:root {
  --navy: #0e2a4d;
  --navy-2: #163a6b;
  --navy-dark: #081a33;
  --green: #2f9e44;
  --green-dark: #23803a;
  --paper: #ffffff;
  --bg: #eef1f7;
  --text: #1c2530;
  --muted: #64748b;
  --border: #e3e8f0;
  --danger: #c0342d;
  --warn: #b5860b;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-md: 0 6px 20px -6px rgba(15, 23, 42, .16);
  --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, .28);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 500px at 100% -10%, rgba(14, 42, 77, .06), transparent),
    radial-gradient(900px 500px at -10% 0%, rgba(47, 158, 68, .05), transparent),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy); }

.container { max-width: 1040px; margin: 0 auto; padding: clamp(16px, 4vw, 28px) clamp(16px, 4vw, 24px) 60px; }

/* ---- Top nav ---- */
.topnav {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}
.topnav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 24px);
  max-width: 1040px;
}
.topnav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; text-decoration: none; flex-shrink: 0; }
.topnav .brand img { height: 34px; width: auto; border-radius: 6px; background: #fff; padding: 3px; box-shadow: var(--shadow-sm); }
.topnav .brand span { font-size: 15px; }
.topnav .brand small { display: block; font-weight: 400; color: #b9c9e2; font-size: 11px; letter-spacing: .01em; }

.topnav nav { display: flex; align-items: center; }
.topnav nav a {
  color: #dce4f2;
  text-decoration: none;
  margin-left: 22px;
  font-size: 14px;
  font-weight: 600;
  transition: color .15s ease;
  white-space: nowrap;
}
.topnav nav a:hover { color: #fff; }
.topnav nav form button {
  background: none; border: none; color: #dce4f2; font-weight: 600; font-size: 14px;
  margin-left: 22px; cursor: pointer; font-family: inherit; padding: 0; transition: color .15s ease;
}
.topnav nav form button:hover { color: #fff; }

.nav-toggle {
  display: none;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  width: 38px; height: 34px;
  padding: 0;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.nav-toggle .bar {
  position: absolute; left: 9px; right: 9px; height: 2px; background: #fff; border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}
.nav-toggle .bar:nth-child(1) { top: 11px; }
.nav-toggle .bar:nth-child(2) { top: 16px; }
.nav-toggle .bar:nth-child(3) { top: 21px; }
.nav-toggle.open .bar:nth-child(1) { top: 16px; transform: rotate(45deg); }
.nav-toggle.open .bar:nth-child(2) { opacity: 0; }
.nav-toggle.open .bar:nth-child(3) { top: 16px; transform: rotate(-45deg); }

/* ---- Cards / sections ---- */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(18px, 3vw, 26px) clamp(18px, 3.5vw, 28px);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
h1, h2, h3 { color: var(--navy); margin-top: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(21px, 3vw, 26px); font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; margin-bottom: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

.alert { border-radius: var(--radius-md); padding: 13px 16px; margin-bottom: 18px; font-size: 13.5px; border: 1px solid transparent; }
.alert.error { background: #fdecea; border-color: #f5c2bd; color: #7a201d; }
.alert.success { background: #e9f7ec; border-color: #b9dfb9; color: var(--green-dark); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--border); }
.btn.secondary:hover { background: #f7f9fc; }
.btn.green { background: linear-gradient(180deg, #37ab4d, var(--green)); }
.btn.small { padding: 7px 13px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { background: linear-gradient(180deg, #d1463e, var(--danger)); }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
label .opt { color: var(--muted); font-weight: 400; }

input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=password], input[type=search], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fbfcfe;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder, textarea::placeholder { color: #9aa5b5; }
input[type=text]:hover, input[type=email]:hover, input[type=tel]:hover, input[type=number]:hover,
input[type=date]:hover, input[type=password]:hover, textarea:hover, select:hover { border-color: #c7d1e0; }
input[type=text]:focus, input[type=email]:focus, input[type=tel]:focus, input[type=number]:focus,
input[type=date]:focus, input[type=password]:focus, input[type=search]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--navy-2);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(14, 42, 77, .10);
}
textarea { resize: vertical; }
.field { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ---- BOM item table (form) ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
table.bom { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 640px; }
table.bom th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 6px 10px; border-bottom: 2px solid var(--border); }
table.bom td { padding: 7px 6px; vertical-align: top; border-bottom: 1px solid var(--border); }
table.bom input, table.bom select { font-size: 13px; padding: 8px 9px; }
.col-qty, .col-price, .col-disc { width: 100px; }
.col-disctype { width: 110px; }
.col-remove { width: 40px; text-align: center; }
.remove-row {
  background: #fdecea; border: 1px solid #f5c2bd; color: var(--danger); font-size: 15px; cursor: pointer;
  line-height: 1; width: 28px; height: 28px; border-radius: 8px; transition: background .15s ease;
}
.remove-row:hover { background: #f9d3cf; }
.catalog-picker { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.catalog-picker select { max-width: 420px; flex: 1; min-width: 220px; }

/* ---- Invoice list ---- */
.table-scroll table.list { min-width: 720px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 8px; border-bottom: 2px solid var(--border); }
table.list td { padding: 12px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.list tbody tr { transition: background .12s ease; }
table.list tbody tr:hover td { background: #f7f9fc; }

.badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .01em; }
.badge.paid { background: #e4f4e4; color: var(--green-dark); }
.badge.partial { background: #fdf2d9; color: var(--warn); }
.badge.unpaid { background: #fbe6e5; color: var(--danger); }
.badge.valid { background: #e4f4e4; color: var(--green-dark); }
.badge.invalid { background: #fbe6e5; color: var(--danger); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

/* ---- Invoice document ---- */
.invoice-toolbar {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 100%);
  position: sticky; top: 0; z-index: 30;
}
.invoice-toolbar .container { display: flex; justify-content: space-between; align-items: center; padding: 12px clamp(16px,4vw,24px); flex-wrap: wrap; gap: 10px; max-width: 1040px; }
.invoice-toolbar .back-link { color: #dce4f2; text-decoration: none; font-weight: 600; font-size: 14px; }
.invoice-toolbar .back-link:hover { color: #fff; }
.invoice-toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.email-status { margin: 20px auto 0; max-width: 900px; }
.email-status .alert { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.invoice-sheet {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 40px);
  max-width: 900px;
  margin: 24px auto;
  box-shadow: var(--shadow-md);
}
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 3px solid var(--navy); padding-bottom: 18px; flex-wrap: wrap; }
.inv-header .org { display: flex; gap: 14px; }
.inv-header .org img { height: 60px; width: auto; }
.inv-header .org h1 { font-size: 20px; margin: 0 0 2px; }
.inv-header .org .tagline { color: var(--green-dark); font-weight: 600; font-size: 12.5px; margin-bottom: 6px; }
.inv-header .org .addr { color: var(--muted); font-size: 12.5px; max-width: 260px; }
.inv-header .meta { text-align: right; }
.inv-header .meta h2 { font-size: 26px; letter-spacing: .06em; margin: 0; color: var(--navy); }
.inv-header .meta .num { font-weight: 700; font-size: 15px; margin-top: 4px; }
.inv-header .meta .dates { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

.barcode-strip { text-align: center; padding: 20px 0 14px; margin-top: 10px; border-top: 1px dashed var(--border); }
.barcode-strip img { height: 60px; max-width: 100%; }
.barcode-strip .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }

.bill-to { display: flex; justify-content: space-between; gap: 30px; padding: 18px 0; flex-wrap: wrap; }
.bill-to .block h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
.bill-to .block .name { font-weight: 700; font-size: 15px; }
.bill-to .block { font-size: 13.5px; min-width: 200px; }

.table-scroll table.items { min-width: 560px; }
table.items { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.items thead th { background: var(--navy); color: #fff; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 8px; text-align: left; }
table.items thead th:first-child { border-radius: 8px 0 0 8px; }
table.items thead th:last-child { border-radius: 0 8px 8px 0; }
table.items thead th.num { text-align: right; }
table.items tbody td { padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: top; }
table.items tbody td.num { text-align: right; white-space: nowrap; }
table.items tbody .item-name { font-weight: 700; }
table.items tbody .item-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
table.items tbody .discount-cell { color: var(--danger); }

.totals { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals table { border-collapse: collapse; min-width: 320px; width: 100%; max-width: 340px; }
.totals td { padding: 7px 10px; font-size: 14px; }
.totals td.label { color: var(--muted); text-align: right; }
.totals td.val { text-align: right; font-weight: 600; width: 140px; }
.totals tr.grand td { border-top: 2px solid var(--navy); font-size: 16px; padding-top: 12px; }
.totals tr.grand td.val { color: var(--navy); }
.totals tr.due td.val { color: var(--danger); }
.totals tr.paid td.val { color: var(--green-dark); }

.words { margin-top: 8px; font-size: 12.5px; font-style: italic; color: var(--muted); }

.terms { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 14px; }
.terms h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.terms ol { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text); }
.terms li { margin-bottom: 4px; }

.inv-footer { margin-top: 26px; text-align: center; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }
.inv-footer .verify-link { font-weight: 700; color: var(--navy); }

/* ---- Auth / login ---- */
.auth-wrap {
  min-height: calc(100vh - 62px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 16px 60px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 34px 30px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-card .auth-icon {
  width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, var(--navy-2), var(--navy));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; margin: 0 auto 16px;
  box-shadow: var(--shadow-sm);
}
.auth-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { text-align: center; margin-bottom: 22px; }
.auth-footer-note { text-align: center; margin-top: 18px; }

/* ---- Verify page ---- */
.verify-hero { text-align: center; padding: 20px 0 4px; }
.verify-hero .auth-icon { margin-bottom: 14px; }
.verify-form { display: flex; gap: 10px; max-width: 480px; margin: 20px auto 4px; }
.verify-form input { flex: 1; }
.verify-result { max-width: 700px; margin: 0 auto; }
.verify-status { display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: var(--radius-lg); margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.verify-status.ok { background: #e9f7ec; border: 1px solid #b9dfb9; }
.verify-status.bad { background: #fdecea; border: 1px solid #f5c2bd; }
.verify-status .icon {
  font-size: 20px; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.verify-status.ok .icon { background: var(--green); }
.verify-status.bad .icon { background: var(--danger); }
.verify-status .title { font-weight: 700; font-size: 16px; }
.verify-status.ok .title { color: var(--green-dark); }
.verify-status.bad .title { color: var(--danger); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }
.detail-grid .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }
.detail-grid .v { font-size: 14.5px; font-weight: 600; }

.scan-toggle { text-align: center; margin-top: 10px; }
#reader { max-width: 360px; margin: 16px auto; border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); }

/* ---- Dropdown (Save / Print) ---- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13.5px; font-weight: 600;
  transition: background .12s ease;
}
.dropdown-menu a:hover { background: #f2f5fb; }
.dropdown-menu .ic { width: 18px; text-align: center; flex-shrink: 0; }

/* ---- Footer credit ---- */
.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px 40px; }

@media print {
  body { background: #fff; }
  .topnav, .invoice-toolbar, .email-status, .no-print { display: none !important; }
  .invoice-sheet { border: none; margin: 0; padding: 0; max-width: 100%; box-shadow: none; }
  .container { padding: 0; max-width: 100%; }
}

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .topnav nav {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--navy-dark);
    flex-direction: column; align-items: stretch;
    padding: 6px 16px 14px;
    max-height: 0; overflow: hidden;
    transition: max-height .22s ease;
  }
  .topnav nav.open { max-height: 260px; }
  .topnav nav a, .topnav nav form { margin: 0; padding: 12px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
  .topnav nav form button { margin: 0; padding: 0; }
  .topnav { position: relative; }
}

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .inv-header { flex-direction: column; gap: 16px; }
  .inv-header .meta { text-align: left; }
  .bill-to { flex-direction: column; }
  .detail-grid { grid-template-columns: 1fr; }
  .totals { justify-content: stretch; }
  .totals table { max-width: 100%; }

  /* Data tables become a stack of cards — a table clipped off-screen with no
     scroll affordance is a dead end on a phone, worse for the BOM form since
     the clipped fields are actually required inputs, not just extra detail. */
  .responsive-table { min-width: 0 !important; }
  .stack-scroll { overflow: visible; margin: 0; padding: 0; }
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody { display: block; width: 100%; }
  .responsive-table tbody tr {
    display: block; position: relative;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 14px 44px 14px 14px; margin-bottom: 12px;
  }
  .responsive-table td { display: block; width: auto !important; padding: 6px 0; border-bottom: none; }
  .responsive-table td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 700; margin-bottom: 4px;
  }
  .responsive-table td.col-remove, .responsive-table td.row-action {
    position: absolute; top: 10px; right: 10px; width: auto !important; padding: 0;
  }
  table.list.responsive-table tbody tr:hover td { background: none; }
}
