:root {
  --blue: #0f6bff;
  --blue-dark: #0b3f93;
  --teal: #00a8a8;
  --amber: #f5a400;
  --green: #12a66a;
  --ink: #112033;
  --muted: #66788a;
  --line: #d9e5ee;
  --bg: #f4f8fb;
  --card: #fff;
  --danger: #d9234e;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 11px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { min-height: 104px; resize: vertical; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: #52687a; background: #f8fbfd; }
td small { display: block; color: var(--muted); margin-top: 3px; }
code { background: #edf4fb; border-radius: 6px; padding: 2px 6px; }

.app-shell { min-height: 100vh; }
.sidebar { display: none; }
.main { padding: 16px 16px 92px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 900; color: white; }
.brand img { width: 38px; height: 38px; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 28px; line-height: 1.1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.company-switcher select { min-width: 180px; background: white; }
.eyebrow { margin: 0 0 4px; color: var(--blue); font-weight: 900; text-transform: uppercase; font-size: 12px; letter-spacing: .08em; }
.muted { color: var(--muted); margin: 4px 0 0; }
.user-chip { background: white; border: 1px solid var(--line); border-radius: 999px; padding: 8px 11px; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 42px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: white; }
.btn-soft { background: #eaf2ff; color: var(--blue-dark); }
.btn-danger { background: #ffe7ec; color: #9d1432; }

.alert { border-radius: 8px; padding: 12px 14px; margin: 0 0 16px; font-weight: 700; }
.alert.success { background: #e7fff2; border: 1px solid #7dd9a6; color: #12633e; }
.alert.error { background: #fff1f3; border: 1px solid #f3a0ad; color: #94142d; }

.cards-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.cards-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric-card span { color: var(--muted); font-weight: 800; }
.metric-card strong { font-size: 24px; line-height: 1.1; }
.metric-card small { color: var(--muted); }
.metric-card.blue { border-left: 5px solid var(--blue); }
.metric-card.teal { border-left: 5px solid var(--teal); }
.metric-card.amber { border-left: 5px solid var(--amber); }
.metric-card.green { border-left: 5px solid var(--green); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.panel.narrow { max-width: 820px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 20px; }
.filters { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.form-grid label { display: grid; gap: 6px; font-weight: 800; }
.form-grid .full { grid-column: 1 / -1; }
.check-line { display: flex !important; align-items: center; gap: 8px; }
.check-line input { width: auto; min-height: 0; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.amount-plus { color: #0b7b4b; font-weight: 800; }
.amount-minus { color: #b4233e; font-weight: 800; }
.low-stock { background: #fff7e2; }

.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.quick-tile { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 18px; text-decoration: none; font-weight: 900; color: var(--blue-dark); }
.feature-grid { align-items: stretch; }
.feature-tile {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 128px;
}
.feature-tile span { font-size: 16px; color: #102033; }
.feature-tile small { color: var(--muted); font-weight: 700; line-height: 1.35; }
.feature-tile strong {
  width: fit-content;
  background: #ecfff6;
  color: #0b7048;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
}

.detail-hero { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; background: white; border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.detail-hero h2 { margin: 0 0 6px; font-size: 26px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions .btn { min-height: 34px; padding: 7px 10px; font-size: 13px; }
.statement-share-form { align-items: end; }
.statement-share-form .check-line { min-height: 44px; align-content: center; }
.placeholder-box { border: 1px dashed #9fb4c5; border-radius: 8px; padding: 24px; background: #f8fbfd; }
.filters-with-actions { grid-template-columns: 1fr; }
.voucher-create-panel { max-width: 1040px; margin-inline: auto; }
.voucher-form { display: grid; gap: 14px; }
.compact-form { gap: 10px; }
.voucher-section-title {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 30px;
  border-left: 4px solid var(--teal);
  background: #effcff;
  color: #0b5260;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}
.tally-entry-grid label {
  color: #0f253b;
  font-size: 13px;
}
.voucher-items { display: grid; gap: 12px; }
.voucher-item-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}
.voucher-item-row.is-extra { display: none; }
.voucher-item-row.is-extra.is-visible { display: block; }
.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.line-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border: 1px solid #cbe1ef;
  border-radius: 8px;
  background: #f3fbff;
  padding: 9px 12px;
  font-weight: 900;
}
.line-total span { color: var(--muted); font-size: 13px; }
.voucher-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.voucher-total-box {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--green);
  background: #effff7;
  color: #0c5f3f;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 900;
}
.voucher-total-box span { color: #2c6f52; }
.api-key-once { background: #102033; color: white; border-radius: 8px; padding: 16px; margin-bottom: 16px; display: grid; gap: 10px; }
.api-key-once code { white-space: normal; word-break: break-all; background: #223a55; border-radius: 8px; padding: 12px; }
.tally-sheet {
  background: #fff;
  border-color: #b8c7d4;
}
.tally-report-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid #25364a;
  border-bottom: 0;
  padding: 12px 14px;
  background: #f7fafc;
}
.tally-report-head h2 { margin: 0; font-size: 20px; text-transform: uppercase; }
.tally-report-head p { margin: 3px 0; color: #52687a; font-weight: 800; }
.tally-period { color: #52687a; font-weight: 800; white-space: nowrap; }
.tally-report { border: 1px solid #25364a; }
.tally-report th, .tally-report td {
  border: 1px solid #25364a;
  padding: 8px 10px;
  font-size: 13px;
}
.tally-report th {
  background: #edf3f8;
  color: #102033;
  text-transform: none;
  letter-spacing: 0;
}
.tally-report tfoot th {
  background: #f4f8fb;
  font-size: 14px;
}
.tally-report .right { text-align: right; }
.opening-row td {
  background: #fffdf2;
  font-weight: 800;
}
.invoice-sheet {
  background: #fff;
  color: #111;
  border: 1px solid #1d1d1d;
  border-radius: 0;
  max-width: 960px;
  margin: 0 auto 20px;
  padding: 18px;
}
.invoice-title { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #111; padding-bottom: 8px; }
.invoice-title h2 { margin: 0; font-size: 22px; text-transform: uppercase; }
.invoice-title p { margin: 0; color: #444; font-weight: 700; }
.invoice-company { text-align: center; border-bottom: 2px solid #111; padding: 10px 0; }
.invoice-company h1 { margin: 0 0 4px; font-size: 26px; }
.invoice-company p { margin: 2px 0; }
.invoice-grid { display: grid; grid-template-columns: 1.2fr .8fr; border-bottom: 1px solid #111; }
.invoice-grid > div { padding: 10px; border-right: 1px solid #111; }
.invoice-grid > div:last-child { border-right: 0; }
.invoice-grid h3, .invoice-grid p { margin: 4px 0; }
.invoice-meta th, .invoice-meta td { border: 1px solid #111; padding: 7px; font-size: 13px; }
.invoice-lines { margin-top: 12px; border-collapse: collapse; }
.invoice-lines th, .invoice-lines td { border: 1px solid #111; padding: 8px; font-size: 13px; }
.invoice-lines th { background: #f2f4f7; color: #111; text-transform: none; }
.invoice-lines .right, .invoice-meta .right { text-align: right; }
.invoice-lines .grand { font-size: 16px; font-weight: 900; }
.invoice-ledger-breakup { border: 1px solid #111; border-top: 0; padding: 10px; }
.invoice-ledgers { margin-top: 8px; border-collapse: collapse; }
.invoice-ledgers th, .invoice-ledgers td { border: 1px solid #111; padding: 7px; font-size: 12px; }
.invoice-ledgers th { background: #f7f8fa; color: #111; }
.invoice-ledgers .right { text-align: right; }
.invoice-footer-grid { display: grid; grid-template-columns: 1fr 260px; border: 1px solid #111; border-top: 0; }
.invoice-footer-grid > div { padding: 12px; border-right: 1px solid #111; min-height: 110px; }
.invoice-footer-grid > div:last-child { border-right: 0; }
.invoice-sign { display: flex; flex-direction: column; justify-content: space-between; text-align: center; }
.invoice-note { font-size: 12px; color: #555; margin: 10px 0 0; }
.voucher-sheet .invoice-title h2 { color: #0b3f93; }
.no-print { }

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; background: white; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(6, 1fr); z-index: 10; }
.bottom-nav a { display: grid; place-items: center; gap: 2px; text-decoration: none; color: var(--muted); padding: 8px 4px 7px; min-height: 62px; }
.bottom-nav span { display: grid; place-items: center; background: #edf4fb; border-radius: 8px; width: 28px; height: 26px; font-weight: 900; }
.bottom-nav .is-active { color: var(--blue); }
.bottom-nav .is-active span { background: var(--blue); color: white; }

.login-body { background: #eef7fb; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 24px; width: min(420px, 100%); box-shadow: 0 18px 50px rgba(15,61,92,.13); }
.login-logo { width: 64px; height: 64px; }
.login-card h1 { margin: 4px 0 20px; }
.stack { display: grid; gap: 14px; }
.stack label { font-weight: 800; display: grid; gap: 6px; }
.login-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 18px; }
.login-links a { color: var(--blue-dark); font-weight: 800; }

@media (min-width: 720px) {
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
  .filters-with-actions { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quick-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 980px) {
  .app-shell { display: grid; grid-template-columns: 250px 1fr; }
  .sidebar { display: block; background: #102033; color: white; padding: 18px; position: sticky; top: 0; height: 100vh; overflow: auto; }
  .sidebar nav { display: grid; gap: 5px; margin-top: 24px; }
  .nav-link { display: flex; align-items: center; gap: 10px; color: #c8d8e7; text-decoration: none; padding: 10px; border-radius: 8px; font-weight: 800; }
  .nav-link span:first-child { display: grid; place-items: center; width: 28px; height: 28px; background: #1e3954; border-radius: 8px; color: white; font-size: 12px; }
  .nav-link.is-active, .nav-link:hover { background: #1e3954; color: white; }
  .main { padding: 24px 28px 40px; min-width: 0; }
  .bottom-nav { display: none; }
  .cards-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .main { padding: 10px 10px 78px; }
  .topbar { display: grid; }
  .topbar h1 { font-size: 22px; }
  .topbar-actions { justify-content: flex-start; }
  .user-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .cards-grid, .cards-grid.compact { grid-template-columns: 1fr; }
  .metric-card { min-height: 86px; padding: 12px; }
  .metric-card strong { font-size: 22px; }
  .detail-hero { display: grid; }
  .panel { padding: 10px; margin-bottom: 10px; }
  .panel-head { display: grid; }
  .panel-head h2 { font-size: 18px; }
  input, select, textarea { min-height: 40px; padding: 9px 10px; border-radius: 7px; }
  textarea { min-height: 74px; }
  th, td { padding: 10px; }
  .btn { width: auto; }
  .mobile-card-wrap { overflow: visible; border: 0; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table thead { display: none; }
  .responsive-table tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    margin-bottom: 10px;
    overflow: hidden;
  }
  .responsive-table td {
    border-bottom: 1px solid #edf3f8;
    display: grid;
    grid-template-columns: 105px 1fr;
    gap: 10px;
    align-items: center;
    min-height: 42px;
  }
  .responsive-table td:last-child { border-bottom: 0; }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
  }
  .responsive-table .empty { display: table-cell; }
  .voucher-item-row { padding: 10px; }
  .voucher-section-title { width: 100%; justify-content: center; }
  .voucher-actions { align-items: stretch; }
  .voucher-total-box { width: 100%; justify-content: space-between; }
  .voucher-actions .btn, .voucher-form .btn { width: 100%; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .quick-tile { padding: 12px; min-height: 54px; display: flex; align-items: center; }
  .feature-tile { display: grid; min-height: 112px; }
  .bottom-nav a { min-height: 56px; padding: 6px 2px; font-size: 12px; }
  .invoice-sheet { padding: 8px; overflow-x: visible; max-width: 100%; }
  .invoice-title { display: grid; gap: 3px; }
  .invoice-title h2 { font-size: 18px; }
  .invoice-company h1 { font-size: 20px; }
  .tally-report-head { display: grid; }
  .tally-report { min-width: 860px; }
  .invoice-grid, .invoice-footer-grid { grid-template-columns: 1fr; }
  .invoice-grid > div, .invoice-footer-grid > div { border-right: 0; border-bottom: 1px solid #111; }
  .invoice-lines, .invoice-lines tbody, .invoice-lines tr, .invoice-lines td { display: block; width: 100%; }
  .invoice-lines thead { display: none; }
  .invoice-lines tr {
    border: 1px solid #111;
    margin-bottom: 8px;
  }
  .invoice-lines td {
    border: 0;
    border-bottom: 1px solid #d8d8d8;
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 8px;
    text-align: left !important;
  }
  .invoice-lines td::before {
    content: attr(data-label);
    color: #555;
    font-weight: 900;
  }
  .invoice-lines tfoot, .invoice-lines tfoot tr, .invoice-lines tfoot td { display: block; width: 100%; }
  .invoice-lines tfoot td:first-child { display: none; }
  .invoice-lines tfoot td.right {
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }
  .invoice-lines tfoot td.right::before { content: ''; }
  .invoice-ledgers { min-width: 0; }
}

@media print {
  .sidebar, .bottom-nav, .topbar, .topbar-actions, .filters .btn, .btn, .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel, .detail-hero { border: 0; }
  .tally-report-head { border-color: #111; }
  .table-wrap { overflow: visible; border: 0; }
  body { background: white; }
  .invoice-sheet { max-width: none; border: 0; margin: 0; padding: 0; }
}
