:root {
  color-scheme: light;
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #6b7280;
  --line: #dbe3ef;
  --primary: #1d4ed8;
}

* {
  box-sizing: border-box;
  font-family: Vazirmatn, Tahoma, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}
.brand p {
  margin: 0.2rem 0 1rem;
  color: #94a3b8;
  font-size: 0.8rem;
}

.app-header {
  text-align: center;
  background: linear-gradient(135deg, #0b2545, #1d4ed8);
  color: #fff;
  padding: 1.6rem 1rem;
  box-shadow: 0 10px 24px rgba(9, 36, 80, 0.24);
}

.app-header p {
  color: #cbd5e1;
  margin: 0.4rem 0 0;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tab {
  border: 1px solid #1e293b;
  background: #111827;
  color: #cbd5e1;
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  text-align: right;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.container {
  width: 100%;
  margin: 0;
  padding: 1rem 1.2rem 2rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

.card h3 {
  margin-top: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 140px minmax(180px, 1fr) 140px minmax(180px, 1fr);
  gap: 0.6rem 0.8rem;
  margin-bottom: 0.8rem;
  align-items: center;
}

input,
select,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem;
}

button {
  cursor: pointer;
  background: #e8f0ff;
  border-color: #c8d7ff;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem;
  text-align: right;
}

th {
  background: #f9fafb;
  color: var(--muted);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0;
}

.alert-box {
  margin-top: 0.8rem;
  color: #991b1b;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
}

.report-center {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 1rem;
  align-items: start;
}

.report-sidebar h3 {
  margin-top: 0;
}

.report-catalog {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.report-cat-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.report-pick {
  display: block;
  width: 100%;
  text-align: right;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.report-pick:hover {
  background: #eef2ff;
  border-color: #93c5fd;
}

.report-pick.active {
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  border-color: #2563eb;
  color: #1e40af;
  font-weight: 600;
}

.report-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.report-params-card h3 {
  margin-top: 0;
}

.report-run-btn {
  margin-top: 0.25rem;
}

.report-preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.report-export-actions {
  display: flex;
  gap: 0.5rem;
}

.report-preview-pane {
  min-height: 280px;
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  background: #f8fafc;
}

.report-preview-pane .report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: #fff;
}

.report-preview-pane .report-table th {
  background: #eff6ff;
  color: #1e3a8a;
  padding: 0.5rem;
  border: 1px solid #bfdbfe;
  text-align: right;
}

.report-preview-pane .report-table td {
  padding: 0.45rem 0.5rem;
  border: 1px solid #e2e8f0;
}

.report-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.report-summary-chip {
  background: #fff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.82rem;
  color: #1e3a8a;
}

.report-empty {
  text-align: center;
  padding: 2rem 1rem;
}

.report-group {
  margin-bottom: 1.25rem;
}

.report-group-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: #1e40af;
  border-right: 3px solid #2563eb;
  padding-right: 0.5rem;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.doc-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.doc-box h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 900px) {
  .report-center {
    grid-template-columns: 1fr;
  }
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 760px) {
  .two-cols {
    grid-template-columns: 1fr;
  }
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.full-row {
  grid-column: 1 / -1;
}

.form-grid label {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.ss-wrap {
  position: relative;
}

.ss-input {
  width: 100%;
}

.ss-list {
  position: absolute;
  z-index: 20;
  right: 0;
  left: 0;
  top: 100%;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.ss-list li {
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.ss-list li:hover {
  background: #eef2ff;
}

.linkbtn {
  background: none;
  border: none;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  padding: 0.2rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(1200px, 96vw);
  max-height: 95vh;
  overflow: auto;
  background: var(--card);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid var(--line);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.subtabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.subtab {
  border: 1px solid var(--line);
  background: #fff;
}

.subtab.active {
  background: #dbeafe;
  border-color: #93c5fd;
}

.subpanel {
  display: none;
}

.subpanel.active {
  display: block;
}

/* ── Invoice sheet (form layout like a real invoice) ── */
.invoice-sheet {
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  padding: 0;
  margin-top: 0.75rem;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.invoice-sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 3px solid #1d4ed8;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}

.invoice-sheet-brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.invoice-sheet-company {
  font-size: 1.35rem;
  color: #1d4ed8;
  font-weight: 800;
}

.invoice-sheet-sub {
  font-size: 0.82rem;
  color: #64748b;
}

.invoice-sheet-type {
  align-self: center;
  justify-self: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: #0f172a;
  padding: 0.45rem 1.25rem;
  border: 2px solid #1d4ed8;
  border-radius: 6px;
  background: #eff6ff;
  white-space: nowrap;
}

.invoice-sheet-sale .invoice-sheet-type {
  color: #1e40af;
  border-color: #2563eb;
  background: #dbeafe;
}

.invoice-sheet-purchase .invoice-sheet-type {
  color: #92400e;
  border-color: #d97706;
  background: #fef3c7;
}

.invoice-sheet-purchase .invoice-sheet-head {
  border-bottom-color: #d97706;
}

.invoice-sheet-purchase .invoice-sheet-company {
  color: #b45309;
}

.invoice-sheet-meta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  justify-self: end;
}

.invoice-meta-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
}

.invoice-meta-field > span {
  color: #64748b;
  font-weight: 600;
}

.invoice-meta-field em {
  font-style: normal;
  font-weight: 400;
  color: #94a3b8;
  font-size: 0.75rem;
}

.invoice-meta-field input {
  width: 100%;
  min-width: 140px;
}

.invoice-section {
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.invoice-section-title {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.invoice-party-input {
  font-size: 1rem;
  font-weight: 600;
}

.invoice-line-entry {
  background: #f8fafc;
}

.invoice-line-grid,
.invoice-payment-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.65rem 0.75rem;
  align-items: end;
}

.invoice-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0;
}

.invoice-field > span {
  font-size: 0.78rem;
  color: #64748b;
  font-weight: 600;
}

.invoice-field-wide {
  grid-column: span 2;
}

.invoice-line-grid .invoice-field-wide {
  grid-column: span 3;
}

.invoice-field input,
.invoice-field .ss-input {
  width: 100%;
}

.invoice-discount-hint {
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
}

.invoice-add-line-btn {
  margin-top: 0.65rem;
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  color: #1d4ed8;
  font-weight: 700;
  padding: 0.45rem 1rem;
  border-radius: 6px;
}

.invoice-add-line-btn:hover {
  background: #dbeafe;
}

.invoice-items {
  padding: 0;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.invoice-table thead th {
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  color: #1e3a8a;
  font-weight: 700;
  padding: 0.65rem 0.75rem;
  border-bottom: 2px solid #93c5fd;
  text-align: right;
}

.invoice-sheet-purchase .invoice-table thead th {
  background: linear-gradient(180deg, #fffbeb, #fef3c7);
  color: #92400e;
  border-bottom-color: #fcd34d;
}

.invoice-table tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.invoice-table tbody tr:nth-child(even):not(.invoice-empty-row) {
  background: #f8fafc;
}

.invoice-table .col-num {
  width: 2.5rem;
  text-align: center;
  color: #64748b;
  font-weight: 600;
}

.invoice-table .col-qty {
  width: 5rem;
  text-align: center;
}

.invoice-table .col-money {
  width: 8rem;
  text-align: left;
  direction: ltr;
  font-variant-numeric: tabular-nums;
}

.invoice-table .col-actions {
  width: 7rem;
  text-align: center;
}

.invoice-empty-row td {
  text-align: center;
  color: #94a3b8;
  padding: 1.5rem;
  font-size: 0.88rem;
}

.invoice-bottom {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 280px);
  gap: 0;
  align-items: stretch;
}

.invoice-payment {
  border-bottom: none;
  border-left: 1px solid #e2e8f0;
}

.invoice-payment-grid {
  grid-template-columns: repeat(2, 1fr);
}

.invoice-summary {
  padding: 1rem 1.5rem;
  background: #f1f5f9;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
}

.invoice-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: #475569;
}

.invoice-summary-row.grand {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  padding-top: 0.5rem;
  border-top: 2px solid #cbd5e1;
}

.invoice-summary-row.grand strong {
  font-size: 1.15rem;
  color: #1d4ed8;
}

.invoice-sheet-purchase .invoice-summary-row.grand strong {
  color: #b45309;
}

.invoice-sheet-foot {
  padding: 1rem 1.5rem;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

.invoice-submit-btn {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  border: none;
  padding: 0.7rem 2.5rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  min-width: 220px;
}

.invoice-sheet-purchase .invoice-submit-btn {
  background: linear-gradient(180deg, #d97706, #b45309);
}

.invoice-cheque-title {
  margin-top: 1rem;
}

.invoice-cash-table {
  margin-top: 0.65rem;
}

.invoice-cash-add-grid {
  grid-template-columns: repeat(3, 1fr);
}

.edit-subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.edit-cash-add-panel {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 0.75rem;
}

.managed-select {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  min-width: 0;
}

.managed-select select {
  flex: 1;
  min-width: 0;
}

.managed-select-btn {
  flex: 0 0 auto;
  width: 2.1rem;
  padding: 0.35rem 0;
  line-height: 1;
  font-size: 1rem;
  font-weight: 700;
}

.form-grid .managed-select.full-row-field {
  grid-column: 2 / -1;
}

.form-grid .ss-wrap.full-row-field {
  grid-column: 2 / -1;
}

.invoice-line-grid .managed-select {
  width: 100%;
}

.invoice-submit-btn:hover {
  filter: brightness(1.05);
}

@media (max-width: 900px) {
  .invoice-sheet-head {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .invoice-sheet-meta {
    justify-self: stretch;
  }

  .invoice-line-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .invoice-line-grid .invoice-field-wide {
    grid-column: span 2;
  }

  .invoice-bottom {
    grid-template-columns: 1fr;
  }

  .invoice-payment {
    border-left: none;
    border-bottom: 1px solid #e2e8f0;
  }
}

.status-btn {
  border: 1px solid #f59e0b;
  background: #fef3c7;
  color: #92400e;
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.badge {
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-in {
  background: #dcfce7;
  color: #166534;
}
.badge-out {
  background: #fee2e2;
  color: #991b1b;
}
.badge-sale {
  background: #dbeafe;
  color: #1e40af;
}
.badge-purchase {
  background: #fef3c7;
  color: #92400e;
}
.badge-shipped {
  background: #dcfce7;
  color: #166534;
  cursor: pointer;
}
.badge-pending-ship {
  background: #f3f4f6;
  color: #4b5563;
  cursor: pointer;
}

.export-toolbar {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  flex-wrap: wrap;
}

.export-btn {
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.export-btn-print {
  background: #e2e8f0;
  color: #334155;
}

.export-btn-pdf {
  background: #1d4ed8;
  color: #fff;
}

.export-btn-print:hover { background: #cbd5e1; }
.export-btn-pdf:hover { background: #1e40af; }

.card > h3 {
  display: inline-block;
  margin-bottom: 0;
  margin-left: 0.5rem;
}

.print-card-btn {
  margin-right: 0.5rem;
}

@media print {
  .tabs,
  .subtabs,
  .form-grid,
  .modal,
  .print-card-btn,
  .linkbtn,
  button {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .tabs {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .form-grid {
    grid-template-columns: 120px minmax(160px, 1fr);
  }
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0b2545, #1d4ed8);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 2rem;
  width: min(400px, 90vw);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-header h1 {
  margin: 0;
  color: var(--primary);
}

.login-header p {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-form label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.auth-form input {
  padding: 0.7rem;
  font-size: 1rem;
}

.auth-form button[type="submit"] {
  margin-top: 0.8rem;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.75rem;
  font-size: 1rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* User Info in Sidebar */
.user-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid #334155;
  margin-bottom: 0.8rem;
}

#user-display-name {
  font-weight: 600;
  color: #f1f5f9;
}

.user-role-badge {
  background: #1e40af;
  color: #dbeafe;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
}

.logout-btn {
  margin-right: auto;
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.logout-btn:hover {
  background: #334155;
  color: #f1f5f9;
}

.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid label {
    margin-top: 0.2rem;
  }
}
