/* ═══════════════════════════════════════════════
   TOKENS
═══════════════════════════════════════════════ */
:root {
  --navy:    #0F172A;
  --ink:     #1E293B;
  --mid:     #64748B;
  --border:  #E2E8F0;
  --bg:      #F1F5F9;
  --white:   #FFFFFF;
  --indigo:  #6366F1;
  --indigo2: #4F46E5;
  --emerald: #10B981;
  --red:     #EF4444;
  --radius:  10px;
  --shadow:  0 1px 3px rgba(15,23,42,.08), 0 4px 16px rgba(15,23,42,.05);
}

/* ═══════════════════════════════════════════════
   RESET + BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* ═══════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 80px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; color: var(--indigo); }
.logo-text {
  font-weight: 700;
  font-size: 18px;
  color: var(--navy);
  letter-spacing: -0.5px;
}
.topbar-tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--mid);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ═══════════════════════════════════════════════
   DASHBOARD LAYOUT
═══════════════════════════════════════════════ */
.dashboard {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 24px 48px;
  align-items: start; /* required so the right panel can go sticky within its row */
}

/* ═══════════════════════════════════════════════
   PANEL
═══════════════════════════════════════════════ */
.panel { display: flex; flex-direction: column; gap: 20px; }

/* Left panel: scrolls normally with the page. */
.panel-form {
  /* no special treatment — flows and scrolls with the page */
}

/* Right panel: sticks to the viewport while scrolling, and only
   releases once its own bottom edge (end of its row) is reached. */
.panel-list {
  position: sticky;
  top: 76px; /* topbar height (60px) + breathing room */
  align-self: start;
}

/* ═══════════════════════════════════════════════
   CARD
═══════════════════════════════════════════════ */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-full { display: flex; flex-direction: column; max-height: calc(100vh - 116px); }
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mid);
  margin-bottom: 20px;
}

/* ═══════════════════════════════════════════════
   FORM FIELDS
═══════════════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field:last-of-type { margin-bottom: 20px; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}

input[type="text"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 9px 13px;
  font-size: 14px;
  color: var(--navy);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
textarea {
  font-family: inherit;
  min-height: 64px;
  resize: vertical;
  line-height: 1.5;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
input::placeholder, textarea::placeholder { color: #CBD5E1; }

/* ═══════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 18px;
  transition: background .15s, transform .1s, opacity .15s;
}

.btn-add {
  width: 100%;
  background: var(--indigo);
  color: var(--white);
  padding: 11px;
}
.btn-add:hover { background: var(--indigo2); }
.btn-add:active { transform: scale(.98); }

.btn-create {
  width: 100%;
  background: var(--emerald);
  color: var(--white);
  padding: 14px;
  font-size: 15px;
  border-radius: 10px;
}
.btn-create:hover:not(:disabled) { background: #059669; }
.btn-create:active:not(:disabled) { transform: scale(.99); }
.btn-create:disabled { opacity: .45; cursor: not-allowed; }

.btn-clear {
  background: none;
  color: var(--mid);
  border: 1.5px solid var(--border);
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 7px;
}
.btn-clear:hover { border-color: var(--red); color: var(--red); background: #FEF2F2; }

.btn-back {
  background: none;
  color: var(--indigo);
  border: 1.5px solid var(--border);
  text-decoration: none;
}
.btn-back:hover { background: #EEF2FF; }

.btn-print {
  background: var(--indigo);
  color: var(--white);
}
.btn-print:hover { background: var(--indigo2); }

/* ═══════════════════════════════════════════════
   LIST HEADER
═══════════════════════════════════════════════ */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--indigo);
  color: var(--white);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════
   TABLE
═══════════════════════════════════════════════ */
.table-wrap { flex: 1; overflow-x: auto; overflow-y: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#itemsTable { table-layout: fixed; }
#itemsTable td, #itemsTable th { overflow-wrap: break-word; word-break: normal; }

thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mid);
  padding: 10px 12px;
  border-bottom: 1.5px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  animation: rowSlide .2s ease;
}
tbody tr:hover { background: #F8FAFF; }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 12px;
  color: var(--navy);
  vertical-align: middle;
}

.td-num { color: var(--mid); font-size: 12px; width: 32px; }
.td-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.td-action { width: 36px; text-align: right; }

.td-item { vertical-align: top; }
.td-item-scroll {
  max-height: 54px;
  overflow-y: auto;
  padding-right: 6px;
}
.td-item-scroll::-webkit-scrollbar { width: 5px; }
.td-item-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.td-item-scroll::-webkit-scrollbar-track { background: transparent; }

.del-btn {
  background: none;
  border: none;
  color: #CBD5E1;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  transition: color .15s, background .15s;
}
.del-btn:hover { color: var(--red); background: #FEF2F2; }

@keyframes rowSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  color: var(--mid);
  font-size: 14px;
}
.empty-icon { font-size: 36px; }
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════
   TOTAL ROW
═══════════════════════════════════════════════ */
.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px;
  margin-top: 8px;
  background: #F8FAFC;
  border-radius: 8px;
  margin-bottom: 20px;
}
.total-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mid);
}
.total-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--emerald);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════
   ERROR MESSAGE
═══════════════════════════════════════════════ */
.error-msg {
  margin-top: 10px;
  font-size: 13px;
  color: var(--red);
  font-weight: 500;
}

/* ═══════════════════════════════════════════════
   PRINT PAGE – SCREEN VIEW
═══════════════════════════════════════════════ */
.print-page {
  background: var(--bg);
}

.print-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 820px;
  margin: 28px auto 0;
  padding: 0 24px;
  gap: 12px;
}

/* ═══════════════════════════════════════════════
   INVOICE DOCUMENT
═══════════════════════════════════════════════ */
.invoice-doc {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 820px;
  margin: 24px auto 48px;
  padding: 48px 52px;
}

.invoice-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.invoice-brand { display: flex; align-items: center; gap: 10px; }
.invoice-brand .logo-icon { font-size: 26px; }
.invoice-brand .logo-text { font-size: 22px; }

.invoice-meta { text-align: right; }
.invoice-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--indigo);
  text-transform: uppercase;
}
.invoice-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -1px;
}
.invoice-date { font-size: 13px; color: var(--mid); margin-top: 2px; }

.divider {
  border: none;
  border-top: 1.5px solid var(--border);
  margin: 28px 0;
}

/* Parties */
.invoice-parties {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
}
.party-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mid);
  margin-bottom: 6px;
}
.party-name { font-size: 18px; font-weight: 700; color: var(--navy); }
.status-badge {
  display: inline-block;
  background: #ECFDF5;
  color: var(--emerald);
  border: 1px solid #A7F3D0;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
}

/* Invoice table */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 0;
}
.invoice-table thead th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mid);
  padding: 10px 14px;
  border-bottom: 2px solid var(--navy);
  text-align: left;
}
.invoice-table th.right,
.invoice-table td.right { text-align: right; }

.invoice-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--navy);
}

.invoice-table tfoot td {
  padding: 10px 14px;
  text-align: right;
}
.subtotal-row td { color: var(--mid); font-size: 13px; padding-top: 16px; }
.total-final-row td {
  font-size: 16px;
  font-weight: 800;
  color: var(--navy);
  border-top: 1.5px solid var(--navy);
  padding-top: 10px;
}

/* Invoice footer */
.invoice-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--mid);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer-note { font-size: 11px; }

/* ═══════════════════════════════════════════════
   PRINT MEDIA QUERY
═══════════════════════════════════════════════ */
@media print {
  .no-print { display: none !important; }

  body { background: white; }

  .invoice-doc {
    border: none;
    box-shadow: none;
    max-width: 100%;
    margin: 0;
    padding: 24px 32px;
    border-radius: 0;
  }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .dashboard {
    grid-template-columns: 1fr;
    margin: 16px auto;
    padding: 0 16px 40px;
  }
  .invoice-doc { padding: 28px 20px; margin: 16px; }
  .print-toolbar { margin: 16px; }
  .invoice-parties { flex-direction: column; gap: 20px; }
}
 @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@500;700&display=swap');

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --ink: #0f1117;
    --ink-light: #5a5f6e;
    --rule: #e2e5ec;
    --accent: #1a56db;
    --accent-pale: #eef2ff;
    --surface: #ffffff;
    --bg: #f5f7fb;
    --green: #0e7a3e;
  }

  body {
    background: var(--bg);
    font-family: 'Inter', sans-serif;
    color: var(--ink);
    min-height: 100vh;
    padding: 40px 16px;
  }

  .page {
    max-width: 780px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 32px rgba(0,0,0,0.08);
  }

  /* ── HEADER ── */
  .header {
    background: var(--ink);
    color: #fff;
    padding: 36px 48px 32px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
  }

  .brand-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.2;
  }
  .brand-name span { color: #60a5fa; }

  .brand-meta {
    margin-top: 10px;
    font-size: 12.5px;
    color: #94a3b8;
    line-height: 1.8;
  }
  .brand-meta a { color: #93c5fd; text-decoration: none; }

  .doc-label {
    text-align: right;
  }
  .doc-label .word {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #60a5fa;
  }
  .doc-label .date {
    margin-top: 6px;
    font-size: 12.5px;
    color: #94a3b8;
  }

  /* ── BILL TO ── */
  .meta-row {
    padding: 28px 48px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--rule);
    gap: 24px;
  }

  .bill-block .label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--ink-light);
    margin-bottom: 6px;
  }
  .bill-block .client-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
  }

  .info-pills {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: right;
  }
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-light);
  }
  .pill .pill-key {
    font-weight: 600;
    color: var(--ink);
  }

  /* ── TABLE ── */
  .table-wrap {
    padding: 0 48px 8px;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 28px;
  }

  thead tr {
    background: var(--accent-pale);
  }
  thead th {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--accent);
    padding: 12px 14px;
    text-align: left;
  }
  .invoice-table td:last-child{
    text-align:right;
    text-align: right;
  }

  tbody tr {
    border-bottom: 1px solid var(--rule);
  }
  tbody tr:last-child { border-bottom: none; }

  tbody td {
    padding: 16px 14px;
    font-size: 13.5px;
    color: var(--ink);
    vertical-align: top;
  }
  .invoice-table th:last-child{
    text-align:right;
    text-align: right;
  }

  .item-name { font-weight: 500; }
  .item-desc { font-size: 11.5px; color: var(--ink-light); margin-top: 2px; }

  /* ── TOTALS ── */
  .totals-wrap {
    padding: 0 48px 36px;
    display: flex;
    justify-content: flex-end;
  }
  .totals-box {
    width: 280px;
    background: var(--accent-pale);
    border-radius: 8px;
    padding: 18px 20px;
    margin-top: 16px;
  }
  .totals-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 5px 0;
    color: var(--ink-light);
  }
  .totals-row.grand {
    border-top: 1.5px solid var(--accent);
    margin-top: 8px;
    padding-top: 12px;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
  }
  .totals-row.grand .amt { color: var(--accent); }

  /* ── CONDITIONS ── */
  .conditions {
    padding: 20px 48px;
    border-top: 1px solid var(--rule);
    display: flex;
    gap: 12px;
    align-items: flex-start;
  }
  .cond-icon {
    width: 32px; height: 32px;
    background: #d1fae5;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
  }
  .cond-text .cond-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.6px;
  }
  .cond-text .cond-desc {
    font-size: 12.5px;
    color: var(--ink-light);
    margin-top: 2px;
  }

  /* ── PAYMENT ── */
  .payment-section {
    padding: 24px 48px 36px;
    border-top: 1px solid var(--rule);
  }
  .section-title {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--ink-light);
    margin-bottom: 14px;
  }
  .banks {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
  }
  .bank-card {
    flex: 1;
    min-width: 200px;
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 14px 16px;
  }
  .bank-name {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent);
    margin-bottom: 4px;
  }
  .bank-account {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.5px;
  }
  .bank-currency {
    font-size: 11px;
    color: var(--ink-light);
    margin-top: 2px;
  }

  /* ── FOOTER ── */
  .footer {
    background: var(--ink);
    padding: 16px 38px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }
  .footer-text { font-size: 11px; color: #64748b; }
  .footer-location { font-size: 11px; color: #64748b;}

  /* Print */
  @media print {
    body { background: white; padding: 0; }
    .page { box-shadow: none; border-radius: 0; }
  }

  @media (max-width: 600px) {
    .header, .meta-row, .table-wrap, .totals-wrap,
    .conditions, .payment-section, .footer {
      padding-left: 20px;
      padding-right: 20px;
    }
    .header { flex-direction: column; }
    .doc-label { text-align: left; }
    .info-pills { text-align: left; }
    .banks { flex-direction: column; }
    .footer { flex-direction: column; }
  }
  /* ===== Align Invoice Section with Payment Details ===== */

/* Same horizontal padding used in Payment Details */
.divider,
.invoice-parties,
.invoice-table,
.invoice-footer {
    padding-left: 48px;
    padding-right: 48px;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid var(--rule);
    margin: 0;
}

/* Invoice parties */
.invoice-parties {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-top: 24px;
    padding-bottom: 20px;
}

/* Match typography */
.party-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--ink-light);
    margin-bottom: 6px;
    font-family: 'Inter', sans-serif;
}

.party-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
}

.status-badge {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
}

/* Invoice table */
.invoice-table {
    width: calc(100% - 96px);
    margin: 0 48px 24px;
    border-collapse: collapse;
}

/* Header */
.invoice-table thead th {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .8px;
    text-transform: uppercase;
    padding: 12px 14px;
}

/* Body */
.invoice-table tbody td,
.invoice-table tfoot td {
    font-family: 'Inter', sans-serif;
    font-size: 13.5px;
    padding: 16px 14px;
    vertical-align: top;
}

/* Totals */
.invoice-table tfoot td {
    padding-top: 14px;
    padding-bottom: 14px;
}

/* Footer */
.invoice-footer {
    padding-top: 20px;
    padding-bottom: 28px;
    font-family: 'Inter', sans-serif;
}

.invoice-footer p {
    font-size: 12px;
    line-height: 1.7;
}

.footer-note {
    color: var(--ink-light);
}

/* Mobile */
@media (max-width:600px) {

    .divider,
    .invoice-parties,
    .invoice-footer {
        padding-left: 20px;
        padding-right: 20px;
    }

    .invoice-table {
        width: calc(100% - 40px);
        margin: 0 20px 24px;
    }

    .invoice-parties {
        flex-direction: column;
        gap: 16px;
    }
}
/* ===== Print Toolbar ===== */
.print-toolbar{
    max-width: 780px;      /* Same width as .page */
    margin: 0 auto 20px;   /* Center it */
    padding: 0 48px;       /* Same horizontal padding as Payment Details */
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.print-toolbar .btn{
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--rule);
    transition: .2s ease;
}

.btn-back{
    background: #fff;
    color: var(--ink);
}

.btn-print{
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn:hover{
    opacity: .9;
}

/* Hide when printing */
@media print{
    .print-toolbar{
        display: none;
    }
}

/* Mobile */
@media (max-width:600px){
    .print-toolbar{
        padding: 0 20px;
        flex-direction: column;
        align-items: stretch;
    }

    .print-toolbar .btn{
        width: 100%;
        text-align: center;
    }
}
.table-wrap{
    padding:0 48px 24px;
}
.invoice-table{
    width:100%;
    margin:0;
    border-collapse:collapse;
}
/* ═══════════════════════════════════════════════
   DASHBOARD — HEADER ACTIONS (Draft / Drafts / Clear)
═══════════════════════════════════════════════ */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-draft {
  background: #EEF2FF;
  color: var(--indigo2);
  border: 1.5px solid #C7D2FE;
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 7px;
}
.btn-draft:hover { background: #E0E7FF; border-color: var(--indigo); }
.btn-draft:active { transform: scale(.98); }

.btn-drafts {
  background: none;
  color: var(--mid);
  border: 1.5px solid var(--border);
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 7px;
  position: relative;
}
.btn-drafts:hover { border-color: var(--indigo); color: var(--indigo); background: #F5F5FF; }

.draft-badge {
  background: var(--emerald);
}

.btn-cancel-edit {
  width: 100%;
  background: none;
  color: var(--mid);
  border: 1.5px solid var(--border);
  padding: 9px;
  margin-top: 8px;
  font-size: 13px;
}
.btn-cancel-edit:hover { border-color: var(--red); color: var(--red); background: #FEF2F2; }

/* Editing state highlight for the Add Item card */
.card.editing {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12), var(--shadow);
}
.editing-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #EEF2FF;
  color: var(--indigo2);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 99px;
  margin-bottom: 14px;
}

/* ═══════════════════════════════════════════════
   DRAG & DROP — ITEM REORDERING
═══════════════════════════════════════════════ */
.th-drag { width: 28px; }
.td-drag {
  width: 28px;
  color: #CBD5E1;
  cursor: grab;
  text-align: center;
  font-size: 14px;
  letter-spacing: -2px;
  user-select: none;
}
.td-drag:active { cursor: grabbing; }

tbody tr[draggable="true"] { transition: background .1s, opacity .15s, transform .1s; }
tbody tr.dragging {
  opacity: .4;
}
tbody tr.drag-over {
  background: #EEF2FF;
  box-shadow: inset 0 2px 0 var(--indigo);
}

/* ═══════════════════════════════════════════════
   ROW ACTION MENU (kebab dropdown: Edit / Duplicate / Delete)
═══════════════════════════════════════════════ */
.td-action { width: 44px; text-align: right; overflow: visible; }

.row-menu { position: relative; display: inline-block; }

.row-menu-btn {
  background: none;
  border: none;
  color: #94A3B8;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 5px;
  transition: color .15s, background .15s;
}
.row-menu-btn:hover,
.row-menu-btn[aria-expanded="true"] { color: var(--indigo); background: #EEF2FF; }

.row-menu-dropdown {
  position: fixed;
  z-index: 1000;
  min-width: 148px;
  background: var(--white, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--navy);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.row-menu-item:hover { background: #F1F5FF; }
.row-menu-item--danger { color: var(--red, #DC2626); }
.row-menu-item--danger:hover { background: #FEF2F2; }

/* ═══════════════════════════════════════════════
   DRAFTS MODAL
═══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-box {
  background: var(--white);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(15,23,42,.25);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
}
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--mid);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }

.drafts-list {
  overflow-y: auto;
  padding: 12px;
}

.draft-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--mid);
  font-size: 14px;
}
.draft-empty .empty-icon { font-size: 30px; display: block; margin-bottom: 10px; }

.draft-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}
.draft-item:last-child { margin-bottom: 0; }

.draft-info { min-width: 0; }
.draft-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.draft-meta {
  font-size: 12px;
  color: var(--mid);
  margin-top: 3px;
}

.draft-actions { display: flex; gap: 6px; flex-shrink: 0; }
.draft-load-btn, .draft-del-btn {
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  cursor: pointer;
}
.draft-load-btn { background: var(--indigo); color: var(--white); }
.draft-load-btn:hover { background: var(--indigo2); }
.draft-del-btn { background: none; color: var(--mid); border: 1.5px solid var(--border); }
.draft-del-btn:hover { color: var(--red); border-color: var(--red); background: #FEF2F2; }

/* ═══════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15,23,42,.3);
  z-index: 1100;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════
   DASHBOARD RESPONSIVE — sticky only makes sense
   on wide layouts; stack + unstick on small screens
═══════════════════════════════════════════════ */
@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; }
  .panel-list { position: static; max-height: none; }
  .card-full { max-height: none; }
}

/* ═══════════════════════════════════════════════
   TABS + HISTORY
═══════════════════════════════════════════════ */
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  border: none; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--mid);
  padding: 8px 18px; border-radius: 8px;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--white); color: var(--indigo2); box-shadow: var(--shadow); }

.history { max-width: 900px; margin: 32px auto; padding: 0 24px 48px; }
.history.hidden, .dashboard.hidden { display: none; }
.history-search {
  font: inherit; padding: 8px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; width: 220px; max-width: 100%;
}
.history-search:focus { outline: none; border-color: var(--indigo); }
.history-list { margin-top: 12px; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  background: var(--white); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 8px;
}
.history-item:hover { border-color: var(--indigo); background: #F5F5FF; }
.history-name { font-weight: 600; color: var(--navy); }
.history-meta { font-size: 12.5px; color: var(--mid); }
.history-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; font-weight: 600; }
.status-pill {
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  background: #D1FAE5; color: #047857;
}
.status-pill.unpaid { background: #FEE2E2; color: #B91C1C; }
.history-detail-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.history-detail-title { font-weight: 700; color: var(--navy); }
.history-frame { width: 100%; height: 80vh; border: 1.5px solid var(--border); border-radius: 10px; background: var(--white); }
@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .history-item { flex-direction: column; align-items: flex-start; }
}

.history-row { display: flex; align-items: stretch; gap: 6px; margin-bottom: 8px; }
.history-row .history-item { margin-bottom: 0; flex: 1; min-width: 0; }
.history-act {
  width: 42px; flex-shrink: 0; cursor: pointer; font-size: 16px;
  background: var(--white); color: var(--mid);
  border: 1.5px solid var(--border); border-radius: 10px;
}
.history-act:hover { color: var(--indigo2); border-color: var(--indigo); background: #F5F5FF; }
.history-act-del:hover { color: var(--red); border-color: var(--red); background: #FEF2F2; }
.history-detail-actions { margin-left: auto; display: flex; gap: 8px; }
.history .header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 640px) { .history-detail-bar { flex-wrap: wrap; } .history-detail-actions { margin-left: 0; } }

/* ═══════════════════════════════════════════════
   MOBILE — keep the items table as a table, just smaller
═══════════════════════════════════════════════ */
@media (max-width: 640px) {
  .card { padding: 14px; }
  .list-header { flex-wrap: wrap; gap: 8px; }
  .header-actions { flex-wrap: wrap; gap: 6px; }

  .panel-list .table-wrap { padding: 0 !important; }
  #itemsTable { font-size: 11px; width: 100%; margin-top: 0 !important; }
  #itemsTable col:nth-child(1) { display: none; }
  #itemsTable col:nth-child(2) { width: 18px !important; }
  #itemsTable col:nth-child(3) { width: auto !important; }
  #itemsTable col:nth-child(4) { width: 28px !important; }
  #itemsTable col:nth-child(5) { width: 62px !important; }
  #itemsTable col:nth-child(6) { width: 68px !important; }
  #itemsTable col:nth-child(7) { width: 22px !important; }

  #itemsTable .th-drag, #itemsTable .td-drag { display: none; }
  #itemsTable thead th { font-size: 8.5px; white-space: nowrap; letter-spacing: 0; padding: 8px 3px; }
  #itemsTable tbody td { padding: 8px 3px; }
  #itemsTable .td-num { font-size: 10px; width: auto; }
  #itemsTable .td-amount { font-size: 10.5px; }
  #itemsTable .td-action { width: auto; padding-left: 0; padding-right: 0; }
  #itemsTable .item-desc { font-size: 10px; }
  #itemsTable .td-item strong { font-size: 12px; }
  #itemsTable .td-item-scroll { padding-right: 2px; max-height: 60px; }
  #itemsTable .row-menu-btn { padding: 2px 4px; }
  .total-row { padding: 12px; }
}

/* History preview: invoice is rendered at full width, then scaled to fit */
.history-frame-wrap {
  width: 100%; overflow: hidden; position: relative;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--white);
}
.history-frame-wrap .history-frame {
  width: 840px; height: 1200px; border: 0; border-radius: 0;
  transform-origin: top left;
}