:root {
  --navy: #12233f;
  --navy-2: #1a3155;
  --blue: #1d4ed8;
  --blue-hover: #183fae;
  --blue-soft: #eaf1ff;
  --canvas: #f3f6fa;
  --surface: #fff;
  --line: #d5dde8;
  --ink: #16213a;
  --muted: #4d5b70;
  --green: #15803d;
  --green-soft: #e8f7ed;
  --amber: #8a4b08;
  --amber-soft: #fff7e6;
  --red: #a32b22;
  --red-soft: #fff0ee;
  --shadow: 0 1px 2px rgba(22, 33, 58, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 17px;
  line-height: 1.55;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .5rem; font-size: clamp(1.55rem, 3vw, 1.9rem); line-height: 1.2; }
h2 { margin-bottom: .8rem; font-size: 1.2rem; line-height: 1.3; }
h3 { margin-bottom: .5rem; font-size: 1rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 100; top: .5rem; left: .5rem; padding: .7rem 1rem; color: #fff; background: var(--blue); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 2px; border-radius: 4px; }

.environment-band { position: sticky; z-index: 80; top: 0; padding: .45rem 1rem; color: #4b2905; background: #ffd978; text-align: center; font-weight: 750; font-size: .88rem; }
.environment-chip { padding: .18rem .45rem; border: 1px solid #f4bd47; border-radius: 6px; color: #4b2905; background: #ffd978; font-size: .8rem; font-weight: 800; }

.login-view { min-height: 100vh; padding: 5vh 1rem 2rem; display: grid; place-content: center; justify-items: center; }
.login-brand, .brand { display: flex; align-items: center; gap: .7rem; }
.login-brand { margin-bottom: 1.4rem; font-size: 1.15rem; }
.login-brand span:last-child { color: var(--muted); }
.brand-symbol { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; color: #fff; background: var(--blue); font-weight: 850; font-size: 1.2rem; }
.login-card { width: min(100vw - 2rem, 430px); padding: clamp(1.4rem, 5vw, 2rem); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.lead { color: var(--muted); max-width: 50ch; }
.login-card label, .form-field > label, .field-label { display: block; margin: .9rem 0 .3rem; font-weight: 700; }
input, textarea, select { width: 100%; min-height: 48px; padding: .65rem .75rem; color: var(--ink); background: #fff; border: 1px solid #aebbc9; border-radius: 9px; }
textarea { min-height: 95px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--red); background: var(--red-soft); }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.trust-note, .helper, .login-help { color: var(--muted); font-size: .88rem; }
.trust-note { margin: 1rem 0 0; }
.login-help { margin-top: 1rem; }

.button, .text-button, .icon-button, .sidebar-link { min-height: 44px; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 9px; font-weight: 750; text-decoration: none; }
.button.primary { color: #fff; background: var(--blue); }
.button.primary:hover { background: var(--blue-hover); }
.button.secondary { color: var(--blue); background: #fff; border-color: #9db3d8; }
.button.danger { color: var(--red); background: #fff; border-color: #e2aaa5; }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button.wide { width: 100%; margin-top: 1.2rem; }
.text-button, .icon-button, .sidebar-link { color: var(--blue); background: transparent; border: 0; font-weight: 700; }
.text-button { padding: 0 .7rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.25rem 1rem; display: flex; flex-direction: column; color: #fff; background: var(--navy); }
.brand > div { display: grid; line-height: 1.2; }
.brand > div span { color: #bbc8db; font-size: .85rem; }
.tenant-name { margin: 1.4rem .45rem .65rem; color: #c7d3e3; font-size: .85rem; overflow-wrap: anywhere; }
#main-nav { display: grid; gap: .25rem; }
.nav-link { display: flex; align-items: center; gap: .7rem; min-height: 46px; padding: .55rem .7rem; border-radius: 9px; color: #dce6f3; text-decoration: none; font-weight: 650; }
.nav-link:hover, .nav-link.active { color: #fff; background: var(--navy-2); }
.nav-icon { width: 1.35rem; text-align: center; }
.sidebar-footer { margin-top: auto; padding: 1rem .45rem 0; border-top: 1px solid #314768; display: grid; gap: .25rem; color: #c7d3e3; font-size: .86rem; }
.sidebar-link { padding: 0; min-height: 36px; color: #fff; text-align: left; }
.mobile-header { display: none; }
main { min-width: 0; padding: clamp(1rem, 3vw, 2.2rem); }
#page { max-width: 1360px; margin: 0 auto; }
.page-header { margin-bottom: 1.25rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.page-header p { margin: 0; color: var(--muted); }
.page-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.panel-pad { padding: clamp(1rem, 2.5vw, 1.5rem); }
.action-banner { margin-bottom: 1.1rem; padding: 1.1rem 1.25rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 1px solid #e5c27b; border-radius: 12px; background: var(--amber-soft); }
.action-banner.ok { border-color: #9bc9aa; background: var(--green-soft); }
.action-banner strong { display: block; font-size: 1.1rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat { padding: 1rem 1.1rem; }
.stat span { display: block; color: var(--muted); font-size: .88rem; }
.stat strong { display: block; font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.dashboard-grid { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(500px, 1.2fr); gap: 1rem; }

.upload-zone { min-height: 190px; padding: 1.4rem; display: grid; place-content: center; justify-items: center; text-align: center; border: 2px dashed #94a6ba; border-radius: 12px; background: #fbfdff; cursor: pointer; }
.upload-zone:hover, .upload-zone.dragging, .upload-zone:has(input:focus-visible) { border-color: var(--blue); background: var(--blue-soft); }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { width: 54px; height: 54px; margin-bottom: .7rem; display: grid; place-items: center; border-radius: 14px; color: var(--blue); background: var(--blue-soft); font-weight: 850; }
.upload-zone small { display: block; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .8rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: .9rem; }
th { color: var(--muted); font-weight: 750; }
tbody tr:last-child td { border-bottom: 0; }
.invoice-link { font-weight: 750; }
.number { font-variant-numeric: tabular-nums; }
.status-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .55rem; border-radius: 999px; font-size: .84rem; font-weight: 750; white-space: nowrap; }
.status-chip.review { color: var(--amber); background: var(--amber-soft); }
.status-chip.transit { color: #1746a2; background: var(--blue-soft); }
.status-chip.accepted { color: var(--green); background: var(--green-soft); }
.status-chip.rejected { color: var(--red); background: var(--red-soft); }
.mobile-list { display: none; }
.empty-state { padding: 2.3rem 1rem; color: var(--muted); text-align: center; }

.message { margin: .8rem 0; padding: .75rem .9rem; border-radius: 9px; }
.message.error { color: var(--red); background: var(--red-soft); border: 1px solid #e5aaa5; }
.message.success { color: var(--green); background: var(--green-soft); border: 1px solid #9bc9aa; }
.message.warning { color: var(--amber); background: var(--amber-soft); border: 1px solid #e5c27b; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-field.wide, .form-actions { grid-column: 1 / -1; }
.form-actions { margin-top: 1.2rem; display: flex; justify-content: flex-end; gap: .7rem; flex-wrap: wrap; }
.section-divider { margin: 1.5rem 0 1rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.check-field { margin-top: 1rem; display: flex; align-items: flex-start; gap: .6rem; }
.check-field input { flex: 0 0 auto; width: 22px; min-height: 22px; }

.review-layout { display: grid; grid-template-columns: minmax(380px, .9fr) minmax(520px, 1.1fr); gap: 1rem; align-items: start; }
.pdf-panel { position: sticky; top: 1rem; overflow: hidden; }
.pdf-frame { width: 100%; height: calc(100vh - 8rem); min-height: 620px; border: 0; background: #e7ebf0; }
.review-form { padding: 1.2rem; }
.warning-list { margin: .5rem 0 1.2rem; padding-left: 1.3rem; color: var(--amber); }
.line-items { display: grid; gap: .7rem; }
.line-item { padding: .8rem; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; }
.line-grid { display: grid; grid-template-columns: 80px minmax(180px, 2fr) repeat(4, minmax(90px, 1fr)) 48px; gap: .5rem; align-items: end; }
.line-grid label { font-size: .78rem; font-weight: 700; color: var(--muted); }
.line-grid input { min-height: 44px; padding: .5rem; }
.remove-line { width: 44px; min-height: 44px; border: 1px solid #e2aaa5; border-radius: 8px; color: var(--red); background: #fff; cursor: pointer; }
.event-list { margin: 0; padding: 0; list-style: none; }
.event-list li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.event-list li:last-child { border-bottom: 0; }
.event-list time { display: block; color: var(--muted); font-size: .82rem; }

.customer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.customer-card { padding: 1.1rem; }
.customer-card .meta { color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.secret-box { margin-top: 1rem; padding: .8rem; border: 1px solid #e5c27b; border-radius: 9px; background: var(--amber-soft); overflow-wrap: anywhere; font-family: ui-monospace, monospace; }
.code-field { min-height: 125px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }

@media (max-width: 1050px) {
  .dashboard-grid, .review-layout { grid-template-columns: 1fr; }
  .pdf-panel { position: static; }
  .pdf-frame { height: 620px; }
  .line-grid { grid-template-columns: 70px 1fr 1fr 1fr; }
  .line-grid .description { grid-column: 2 / -1; }
}

@media (max-width: 880px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(86vw, 300px); transform: translateX(-105%); transition: transform .16s ease; box-shadow: 6px 0 20px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { position: sticky; z-index: 50; top: 0; min-height: 60px; padding: .55rem .8rem; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: .5rem; background: #fff; border-bottom: 1px solid var(--line); }
  .test-mode .mobile-header { top: 52px; }
  .mobile-brand { text-align: center; }
  main { padding: 1rem; }
}

@media (max-width: 700px) {
  :root { font-size: 16px; }
  .page-header, .action-banner { align-items: stretch; flex-direction: column; }
  .stats, .form-grid { grid-template-columns: 1fr; }
  .desktop-table { display: none; }
  .mobile-list { display: grid; gap: .7rem; }
  .invoice-card { display: block; padding: .9rem; color: var(--ink); text-decoration: none; }
  .invoice-card header { margin-bottom: .55rem; display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
  .invoice-card strong { display: block; }
  .invoice-card small { color: var(--muted); }
  .pdf-frame { min-height: 460px; height: 65vh; }
  .line-grid { grid-template-columns: 1fr 1fr; }
  .line-grid .description { grid-column: 1 / -1; }
  .form-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
