:root {
  --ink: #17221f;
  --muted: #68746f;
  --line: #dfe7e3;
  --paper: #ffffff;
  --canvas: #f3f6f4;
  --green: #156b52;
  --green-dark: #0f513e;
  --mint: #dff2ea;
  --gold: #c99535;
  --amber: #fff0c7;
  --red: #9e3939;
  --red-bg: #fde9e7;
  --shadow: 0 12px 35px rgba(18, 54, 43, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #eef5f1 0, var(--canvas) 360px); }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.topbar { min-height: 74px; padding: 12px max(22px, calc((100vw - 1480px)/2)); display: flex; align-items: center; gap: 34px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); min-width: 190px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--green); color: white; font-family: Georgia, serif; font-size: 23px; font-weight: 700; box-shadow: 0 7px 16px rgba(21,107,82,.22); }
.brand-mark.large { width: 62px; height: 62px; font-size: 36px; border-radius: 18px; margin: 0 auto; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 12px; }
.nav { display: flex; align-items: center; gap: 20px; flex: 1; }
.nav a { color: #34433e; font-weight: 650; font-size: 14px; }
.user-menu { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); }

.shell { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 42px 0 64px; }
.footer { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 24px 0 34px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 12px; }
.hero-row { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.hero-row.compact { align-items: center; }
.hero-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form { display: inline-flex; margin: 0; }
.split-options { border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.split-options legend { padding: 0 8px; font-weight: 800; }
.split-options label { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.split-options input { width: auto; margin-top: 4px; }
.split-options span { display: grid; gap: 3px; }
.split-options small { color: var(--muted); }
.hero-row h1, .setup-hero h1 { font-family: Georgia, Cambria, serif; font-size: clamp(32px, 4vw, 48px); line-height: 1.05; margin: 6px 0 10px; letter-spacing: -.02em; }
.hero-row p, .setup-hero p { color: var(--muted); margin: 0; font-size: 16px; }
.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 800; }
.back-link { display: inline-block; margin-bottom: 8px; font-size: 13px; font-weight: 700; }

.button { appearance: none; border: 1px solid #cbd7d1; background: white; color: var(--ink); border-radius: 10px; padding: 10px 15px; font-weight: 750; cursor: pointer; display: inline-flex; justify-content: center; align-items: center; gap: 7px; box-shadow: 0 2px 4px rgba(0,0,0,.02); }
.button:hover { text-decoration: none; border-color: #a9bbb3; }
.button.primary { background: var(--green); border-color: var(--green); color: white; box-shadow: 0 8px 18px rgba(21,107,82,.2); }
.button.primary:hover { background: var(--green-dark); }
.button.ghost { background: transparent; box-shadow: none; }
.button.danger { background: var(--red); border-color: var(--red); color: white; }
.button.danger:hover { background: #7f2929; border-color: #7f2929; }
.icon-button { border: 0; background: var(--red-bg); color: var(--red); width: 31px; height: 31px; border-radius: 8px; font-size: 20px; cursor: pointer; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.metric { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.metric span, .metric small { display: block; color: var(--muted); }
.metric strong { display: block; font-family: Georgia, Cambria, serif; font-size: 31px; margin: 9px 0 5px; }
.metric.accent { background: var(--green); color: white; border-color: var(--green); }
.metric.accent span, .metric.accent small { color: #d7eee5; }
.metric.warning { background: #fffaf0; border-color: #ecd8ab; }
.currency-totals { display: grid; gap: 1px; margin: 9px 0 5px; }
.currency-totals strong { margin: 0; }

.ocr-progress-panel { padding: 18px 22px; }
.ocr-progress-panel[hidden] { display: none; }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; color: var(--green); font-size: 12px; font-weight: 800; }
.live-indicator i { width: 8px; height: 8px; border-radius: 50%; background: #28a878; box-shadow: 0 0 0 5px rgba(40,168,120,.12); animation: live-pulse 1.6s infinite; }
.ocr-progress-list { display: grid; gap: 14px; }
.ocr-progress-row { display: grid; gap: 7px; }
.ocr-progress-top, .ocr-progress-detail { display: flex; justify-content: space-between; gap: 18px; }
.ocr-progress-top a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; color: var(--ink); }
.ocr-progress-top strong { color: var(--green); }
.ocr-progress-detail { color: var(--muted); font-size: 12px; }
.ocr-progress-track { height: 9px; border-radius: 99px; background: #e8eeeb; overflow: hidden; }
.ocr-progress-track span { display: block; height: 100%; min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, var(--green), #49a582); transition: width .35s ease; }
.ocr-progress-row.is-failed .ocr-progress-track span { background: var(--red); }
.ocr-progress-row.is-done .ocr-progress-track span { background: #28a878; }
@keyframes live-pulse { 50% { opacity: .45; transform: scale(.85); } }

.panel { min-width: 0; background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.panel.narrow { max-width: 720px; margin: 60px auto; }
.panel.narrow-wide { max-width: 900px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-head h2, .panel h2 { margin: 0 0 4px; font-size: 19px; }
.panel-head p { color: var(--muted); margin: 0; font-size: 13px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.invoices-panel, .suppliers-panel { margin: 0; }

.filters { display: grid; grid-template-columns: minmax(260px,1fr) 190px auto auto; gap: 10px; margin-bottom: 16px; }
.materials-filters { grid-template-columns: minmax(240px, 1.4fr) repeat(3, minmax(150px, .8fr)) minmax(135px,.6fr) minmax(135px,.6fr) auto auto; align-items: end; }
.report-filters { display: grid; grid-template-columns: minmax(160px, .7fr) minmax(160px, .7fr) minmax(160px, .7fr) auto auto; align-items: end; gap: 12px; }
input, select, textarea { width: 100%; border: 1px solid #cbd7d1; border-radius: 9px; padding: 10px 11px; color: var(--ink); background: white; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(21,107,82,.12); }
textarea { resize: vertical; min-height: 90px; }
label { display: grid; gap: 7px; color: #3d4a46; font-size: 13px; font-weight: 700; }
.form-stack { display: grid; gap: 17px; }
.form-stack h2:not(:first-child) { margin-top: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.field-row.four { grid-template-columns: repeat(4, 1fr); }
.check { display: flex; align-items: center; grid-template-columns: auto 1fr; }
.check input { width: auto; }

.table-wrap { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); text-transform: uppercase; letter-spacing: .055em; font-size: 11px; text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid #edf1ef; font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.number { text-align: right; white-space: nowrap; }
.invoice-link { font-weight: 800; }
.subline { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; padding: 34px !important; }
.badge { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; background: #edf2f0; color: #52605b; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-review { background: var(--amber); color: #795a15; }
.status-verified, .status-paid { background: var(--mint); color: var(--green-dark); }
.status-archived { background: #eceeef; color: #697177; }

.supplier-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.supplier-list li { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid #edf1ef; }
.supplier-list li:last-child { border-bottom: 0; }
.supplier-list span strong, .supplier-list span small { display: block; }
.supplier-list small { color: var(--muted); margin-top: 3px; }
.supplier-list b { white-space: nowrap; }
.supplier-metrics { grid-template-columns: repeat(3, 1fr); }
.supplier-filters { grid-template-columns: minmax(280px,1fr) auto auto; }
.aliases-cell { max-width: 360px; color: var(--muted); font-size: 12px; }

.summary-strip { display: flex; gap: 12px; align-items: stretch; margin-bottom: 18px; }
.summary-strip > div { min-width: 210px; background: white; border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.summary-strip span { color: var(--muted); font-size: 12px; font-weight: 700; }
.summary-strip strong { display: block; margin-top: 5px; font-size: 22px; color: var(--ink); }
.summary-strip .summary-total { flex: 1; }
.inline-totals { display: flex; gap: 22px; flex-wrap: wrap; }
.inline-totals strong { display: inline-block; }
.materials-table { min-width: 1240px; }
.limit-note { margin: 16px 0 0; color: var(--muted); font-size: 13px; }

.reports-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
.reports-grid .panel { margin: 0; }
.reports-wide { grid-column: 1 / -1; }
.bar-list { display: grid; gap: 16px; }
.bar-row { min-width: 0; }
.bar-label { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 7px; }
.bar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.bar-label strong { white-space: nowrap; font-size: 13px; }
.bar-track { height: 8px; border-radius: 99px; background: #edf2ef; overflow: hidden; }
.bar-track span { display: block; height: 100%; min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, var(--green), #4a9b7f); }
.bar-row small { display: block; color: var(--muted); margin-top: 4px; }
.two-column-bars { grid-template-columns: 1fr 1fr; column-gap: 34px; }

.role-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.role-grid article { background: white; border: 1px solid var(--line); border-radius: 13px; padding: 16px; box-shadow: var(--shadow); }
.role-grid strong, .role-grid span { display: block; }
.role-grid span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.user-create-grid { display: grid; grid-template-columns: 1fr 1.2fr .8fr 1fr auto; gap: 12px; align-items: end; }
.user-list { display: grid; gap: 12px; }
.user-card { display: grid; grid-template-columns: minmax(210px, 1fr) 1fr .8fr 1fr auto auto; align-items: end; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: #fbfdfc; }
.user-card-title { display: flex; align-items: center; gap: 11px; align-self: center; }
.user-card-title strong, .user-card-title small { display: block; }
.user-card-title small { color: var(--muted); margin-top: 3px; }
.avatar { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--mint); color: var(--green); font-weight: 900; }
.active-check { padding-bottom: 10px; white-space: nowrap; }

.invoice-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.invoice-fieldset.read-only { opacity: .84; }
.invoice-fieldset.read-only input, .invoice-fieldset.read-only select, .invoice-fieldset.read-only textarea { background: #f4f6f5; color: #4e5a56; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 24px; border-color: #e7b8b4; background: #fffafa; }
.danger-zone h2 { color: var(--red); }
.danger-zone p { margin: 5px 0 0; color: var(--muted); }
.revision-list { display: grid; }
.revision-list > div { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.revision-list > div:last-child { border-bottom: 0; }
.revision-list strong, .revision-list small { display: block; }
.revision-list small { color: var(--muted); margin-top: 3px; }

.alert { padding: 13px 16px; border-radius: 11px; margin: 0 0 18px; border: 1px solid; }
.alert-success { background: var(--mint); border-color: #abd8c7; color: var(--green-dark); }
.alert-error { background: var(--red-bg); border-color: #efb8b4; color: var(--red); }
.alert-warning { background: var(--amber); border-color: #efd083; color: #705315; }

.setup-hero { display: flex; justify-content: space-between; align-items: center; gap: 28px; margin-bottom: 24px; }
.security-note, .callout { background: #edf5f1; border: 1px solid #cfe3da; border-radius: 12px; padding: 14px 16px; color: #3d584e; font-size: 13px; }
.setup-grid { display: grid; grid-template-columns: 380px minmax(0, 720px); gap: 18px; align-items: start; }
.check-list { padding: 0; margin: 18px 0; list-style: none; display: grid; gap: 10px; }
.check-list li { display: flex; align-items: center; gap: 9px; }
.check-list li span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-weight: 900; }
.check-list .ok span, .status-dot.ok { background: var(--mint); color: var(--green); }
.check-list .bad span, .status-dot.bad { background: var(--red-bg); color: var(--red); }
.facts { margin: 0; }
.facts div { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 800; }

.auth-card { width: min(430px, 100%); margin: 55px auto; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 30px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { margin: 12px 0 3px; font-family: Georgia, serif; font-size: 31px; }
.auth-brand p { color: var(--muted); margin: 0; }

.upload-card { max-width: 850px; }
.dropzone { min-height: 260px; border: 2px dashed #aac4b9; background: #f7fbf9; border-radius: 14px; display: grid; place-items: center; align-content: center; text-align: center; gap: 8px; cursor: pointer; padding: 30px; }
.dropzone:hover { background: #f0f8f4; border-color: var(--green); }
.dropzone input { width: auto; margin-top: 10px; }
.upload-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: var(--mint); color: var(--green); font-size: 28px; }
.dropzone strong { font-size: 18px; }
.dropzone small, .selected-files { color: var(--muted); }

.invoice-layout { display: grid; gap: 18px; }
.invoice-layout.has-pdf { grid-template-columns: minmax(420px, .95fr) minmax(540px, 1.05fr); }
.pdf-panel, .details-panel { margin: 0 0 18px; }
.pdf-panel iframe { width: 100%; height: 680px; border: 1px solid var(--line); border-radius: 10px; background: #e8ecea; }
.item-editor table { min-width: 1140px; }
.item-editor td { padding: 7px 5px; }
.item-editor input { padding: 8px; }
.description-col { min-width: 280px; }
.item-editor tfoot td { background: #f7faf8; font-weight: 800; }
.math-check { margin-top: 14px; padding: 11px 13px; border-radius: 9px; background: #f2f4f3; color: var(--muted); font-size: 13px; }
.math-check.ok { background: var(--mint); color: var(--green-dark); }
.math-check.bad { background: var(--red-bg); color: var(--red); }
.sticky-actions { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; gap: 10px; background: rgba(255,255,255,.94); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 14px; padding: 13px; backdrop-filter: blur(12px); z-index: 10; }

.system-list { display: grid; margin-bottom: 20px; }
.system-list > div { display: grid; grid-template-columns: 15px minmax(180px,1fr) 1fr; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.maintenance-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 16px; }
.maintenance-stats > div { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbf9; }
.maintenance-stats span, .maintenance-stats strong { display: block; }
.maintenance-stats span { color: var(--muted); font-size: 12px; }
.maintenance-stats strong { margin-top: 5px; font-size: 24px; }
.maintenance-actions { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-top: 18px; }
.maintenance-actions form { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; }
.button:disabled { opacity: .5; cursor: not-allowed; }
code { background: #edf2f0; border-radius: 5px; padding: 2px 5px; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .setup-grid, .invoice-layout.has-pdf { grid-template-columns: 1fr; }
  .suppliers-panel { order: -1; }
  .pdf-panel iframe { height: 520px; }
  .field-row.four { grid-template-columns: 1fr 1fr; }
  .materials-filters { grid-template-columns: repeat(2, 1fr); }
  .user-create-grid, .user-card { grid-template-columns: repeat(2, 1fr); }
  .reports-grid { grid-template-columns: 1fr; }
  .reports-wide { grid-column: auto; }
}

@media (max-width: 760px) {
  .topbar { position: static; align-items: flex-start; flex-wrap: wrap; gap: 13px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 0 0 100%; width: 100%; overflow-x: auto; gap: 15px; padding-bottom: 5px; }
  .user-menu span { display: none; }
  .shell { width: min(100% - 22px, 1480px); padding-top: 25px; }
  .hero-row, .setup-hero { align-items: flex-start; flex-direction: column; }
  .hero-row h1, .setup-hero h1 { font-size: 34px; }
  .metric-grid { grid-template-columns: 1fr; }
  .filters, .field-row, .field-row.three, .field-row.four { grid-template-columns: 1fr; }
  .materials-filters, .report-filters, .role-grid, .user-create-grid, .user-card, .two-column-bars { grid-template-columns: 1fr; }
  .maintenance-stats { grid-template-columns: 1fr 1fr; }
  .maintenance-actions, .maintenance-actions form { align-items: stretch; flex-direction: column; }
  .summary-strip, .danger-zone { flex-direction: column; align-items: stretch; }
  .footer { flex-direction: column; }
  .pdf-panel iframe { height: 420px; }
}

@media print {
  :root { background: white; }
  body { background: white; color: #111; }
  .topbar, .footer, .print-button, .sticky-actions, .danger-zone, .back-link, .filters, .report-filters, #add-item, .remove-item { display: none !important; }
  .shell { width: 100%; padding: 0; margin: 0; }
  .hero-row { margin: 0 0 18px; }
  .hero-row h1, .setup-hero h1 { font-size: 28px; }
  .panel, .metric, .summary-strip > div { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .reports-grid, .metric-grid { display: block; }
  .reports-grid .panel, .metric-grid .metric { margin-bottom: 12px; }
  .table-wrap { overflow: visible; }
  table, .materials-table, .item-editor table { min-width: 0; font-size: 10px; }
  th, td { padding: 5px 6px; }
  .pdf-panel { display: none; }
  .invoice-layout.has-pdf { display: block; }
  input, select, textarea { border: 0; padding: 2px; background: transparent; }
  @page { size: A4 landscape; margin: 10mm; }
}
