:root {
    color-scheme: light;
    --ink: #18202a;
    --muted: #66717f;
    --line: #dce1e7;
    --surface: #ffffff;
    --subtle: #f5f7f9;
    --accent: #145da0;
    --accent-dark: #0d477c;
    --gold: #f0b323;
    --success: #176b45;
    --danger: #a23333;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--subtle); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.topbar { min-height: 58px; padding: 0 24px; display: flex; align-items: center; gap: 26px; background: #17212b; color: #fff; border-bottom: 3px solid var(--gold); }
.brand { color: #fff; font-size: 18px; font-weight: 750; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-self: stretch; gap: 4px; }
.nav a { color: #d8e0e8; padding: 0 14px; display: flex; align-items: center; border-bottom: 3px solid transparent; }
.nav a:hover, .nav a.active { color: #fff; text-decoration: none; background: #22303d; border-bottom-color: var(--gold); }
.account { margin-left: auto; display: flex; align-items: center; gap: 14px; color: #d8e0e8; }
.account form { margin: 0; }
.link-button { border: 0; padding: 0; color: #fff; background: transparent; cursor: pointer; text-decoration: underline; }

.shell { max-width: 1500px; margin: 0 auto; padding: 28px 24px 48px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #17212b; border-top: 6px solid var(--gold); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
h1 { margin: 0; font-size: 25px; line-height: 1.2; letter-spacing: 0; }
.page-heading p, .login-heading p { margin: 6px 0 0; color: var(--muted); }
.total-block { min-width: 190px; text-align: right; }
.total-block span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.total-block strong { display: block; margin-top: 3px; font-size: 26px; }

.login-panel { width: min(430px, 100%); padding: 30px; background: var(--surface); border: 1px solid #31404d; border-radius: 6px; box-shadow: 0 16px 45px rgba(0,0,0,.24); }
.login-heading { display: flex; align-items: center; gap: 15px; margin-bottom: 28px; }
.login-heading h1 { font-size: 22px; }
.mark { width: 52px; height: 52px; display: grid; place-items: center; background: var(--gold); color: #17212b; font-weight: 900; border-radius: 5px; }

.stack { display: grid; gap: 17px; }
label > span, legend { display: block; margin-bottom: 6px; color: #424c57; font-size: 13px; font-weight: 650; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="month"], input[type="file"], select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; color: var(--ink); background: #fff; border: 1px solid #bfc7d0; border-radius: 4px; }
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(20,93,160,.2); border-color: var(--accent); }
small { display: block; margin-top: 6px; color: var(--muted); }
.check-row { display: inline-flex; align-items: center; gap: 7px; }
.check-row > span { margin: 0; font-weight: 500; }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.button { min-height: 38px; padding: 8px 14px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 4px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.button:hover { text-decoration: none; }
.button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { color: var(--ink); background: #fff; border-color: #bfc7d0; }
.button.secondary:hover { background: #edf1f4; }
.button.full { width: 100%; }

.filters { display: flex; align-items: end; flex-wrap: wrap; gap: 14px; padding: 16px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.filter-field { width: 190px; position: relative; }
.filter-field.compact { width: 150px; }
.filter-field > label { display: block; margin-bottom: 6px; color: #424c57; font-size: 13px; font-weight: 650; }
.filter-input { position: relative; }
.filter-input input { padding-right: 36px; }
.filter-input.has-menu input { padding-right: 66px; }
.filter-icon { width: 30px; height: 30px; position: absolute; top: 5px; display: grid; place-items: center; padding: 0; color: #687481; background: transparent; border: 0; border-radius: 3px; cursor: pointer; font-size: 18px; line-height: 1; }
.filter-icon:hover, .filter-icon:focus { color: var(--ink); background: #e8edf1; outline: none; }
.filter-icon.clear { right: 3px; }
.filter-field.compact .filter-input input { padding-right: 66px; }
.filter-field.compact .filter-icon.clear { right: 32px; }
.filter-input.has-menu .filter-icon.clear { right: 33px; }
.filter-icon.toggle { right: 3px; font-size: 16px; }
.filter-options { width: 100%; position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; padding: 4px; background: #fff; border: 1px solid #aeb8c2; border-radius: 4px; box-shadow: 0 8px 24px rgba(24,32,42,.16); }
.filter-options button { width: 100%; min-height: 34px; padding: 7px 9px; color: var(--ink); background: transparent; border: 0; border-radius: 3px; text-align: left; cursor: pointer; }
.filter-options button:hover, .filter-options button:focus { background: #eaf2f8; outline: none; }
.filters fieldset { min-width: 300px; padding: 0; border: 0; }
.owner-options { min-height: 40px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
.filter-actions { display: flex; gap: 8px; }
.toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar span { margin-right: 3px; color: var(--muted); font-size: 13px; }

.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 12px; background: #edf1f4; border-bottom: 1px solid #cfd6dd; color: #46515d; font-size: 12px; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #e6eaee; vertical-align: top; }
tbody tr:hover { background: #f9fbfc; }
tbody tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.negative { color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; white-space: nowrap; }
.owner-dot { width: 7px; height: 7px; display: inline-block; margin-right: 7px; background: var(--accent); border-radius: 50%; }
.empty { padding: 42px; color: var(--muted); text-align: center; }
.actions { text-align: right; }

.pager { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 18px 0; }
.pager .disabled { color: #9aa3ad; }
.status { padding: 3px 7px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.status.active { color: var(--success); background: #e8f5ee; }
.status.inactive { color: #6c7580; background: #eceff2; }

.upload-panel, .form-panel { max-width: 820px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.upload-panel { display: grid; gap: 16px; }
.invoice-history { margin-top: 30px; }
.section-heading { margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 19px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); }
.drop-zone { min-height: 190px; position: relative; display: grid; place-items: center; align-content: center; gap: 5px; padding: 28px; color: var(--muted); background: #f8fafb; border: 2px dashed #aeb9c5; border-radius: 6px; text-align: center; cursor: pointer; }
.drop-zone:hover, .drop-zone.dragging { color: var(--accent); background: #eef6fc; border-color: var(--accent); }
.drop-zone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.drop-zone strong { color: var(--ink); font-size: 17px; }
.drop-zone span, .drop-zone small { margin: 0; }
.selected-files { margin: 0; padding: 0; display: grid; gap: 7px; list-style: none; }
.selected-files:empty { display: none; }
.selected-files li { padding: 8px 10px; overflow-wrap: anywhere; background: var(--subtle); border: 1px solid var(--line); border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.batch-results { margin-bottom: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.batch-summary { padding: 15px 16px; border-bottom: 1px solid var(--line); }
.batch-summary h2 { margin: 0; font-size: 17px; }
.batch-summary p { margin: 4px 0 0; color: var(--muted); }
.result-list { margin: 0; padding: 0; list-style: none; }
.result-row { padding: 12px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.result-row:last-child { border-bottom: 0; }
.result-row strong, .result-row > div > span { display: block; }
.result-row > div > span { margin-top: 3px; color: var(--muted); }
.result-row ul { margin: 7px 0 0 18px; padding: 0; color: var(--danger); }
.result-status { padding: 3px 7px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.result-row.success .result-status { color: var(--success); background: #e8f5ee; }
.result-row.error .result-status { color: var(--danger); background: #fff1f1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-panel > .form-grid + .button { margin-top: 20px; }
.form-panel > .form-grid + .button { margin-top: 20px; }
.toggles { display: flex; gap: 24px; padding: 20px 0; }

.alert { padding: 13px 15px; margin-bottom: 18px; border: 1px solid; border-radius: 5px; }
.alert.success { color: var(--success); background: #edf8f2; border-color: #9bc9b2; }
.alert.error { color: #7b2020; background: #fff1f1; border-color: #e1aaaa; }
.alert ul { margin: 8px 0 0 20px; padding: 0; }
.field-error { margin: 0; color: var(--danger); }

@media (max-width: 1024px) {
    .shell { padding: 24px 18px 44px; }
    .filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
    .filter-field, .filter-field.compact { width: auto; min-width: 0; }
    .filters fieldset, .filter-actions { grid-column: 1 / -1; }
    .filter-actions { justify-content: flex-end; }
    .upload-panel, .form-panel { max-width: none; }
}

@media (max-width: 760px) {
    .topbar { min-height: 0; padding: 8px max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }
    .brand { min-width: 0; min-height: 44px; display: flex; align-items: center; overflow: hidden; text-overflow: ellipsis; }
    .nav { width: 100%; min-width: 0; height: 46px; grid-column: 1 / -1; grid-row: 2; overflow-x: auto; }
    .nav a { min-width: 84px; min-height: 44px; flex: 1; justify-content: center; padding: 0 12px; }
    .account { min-height: 44px; grid-column: 2; grid-row: 1; margin: 0; gap: 0; }
    .account > span { display: none; }
    .link-button { min-height: 44px; padding: 0 2px; }
    .shell { padding: 22px 14px 40px; }
    .auth-shell { padding: 16px; }
    .login-panel { padding: 22px 18px; }
    .page-heading { align-items: stretch; flex-direction: column; gap: 14px; }
    .page-heading > .button { width: 100%; }
    .total-block { text-align: left; }
    .total-block strong { overflow-wrap: anywhere; font-size: 24px; }
    .filters { grid-template-columns: 1fr; align-items: stretch; padding: 14px; }
    .filter-field, .filter-field.compact, .filters fieldset { width: 100%; min-width: 0; }
    .filters fieldset, .filter-actions { grid-column: auto; }
    input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="month"], input[type="file"], select { min-height: 44px; }
    .filter-icon { width: 36px; height: 36px; top: 4px; }
    .filter-input input { padding-right: 42px; }
    .filter-input.has-menu input { padding-right: 78px; }
    .filter-input.has-menu .filter-icon.clear { right: 39px; }
    .filter-options { max-height: 240px; overflow-y: auto; }
    .filter-actions { width: 100%; }
    .filter-actions .button { flex: 1; }
    .toolbar { justify-content: flex-start; flex-wrap: wrap; }
    .toolbar span { width: 100%; }
    .toolbar .button { min-width: 0; flex: 1; }
    .button { min-height: 44px; }
    .upload-panel, .form-panel { width: 100%; padding: 16px; }
    .upload-panel > .button, .form-panel > .button { width: 100%; }
    .drop-zone { min-height: 150px; padding: 20px 14px; }
    .result-row { align-items: stretch; flex-direction: column; gap: 10px; }
    .result-row strong, .result-row li { overflow-wrap: anywhere; }
    .result-status { align-self: flex-start; }
    .form-grid { grid-template-columns: 1fr; }
    .toggles { align-items: flex-start; flex-direction: column; gap: 14px; padding: 18px 0; }
    .pager { justify-content: space-between; gap: 8px; }
    .pager a, .pager .disabled { min-height: 44px; display: inline-flex; align-items: center; }
}

@media (max-width: 600px) {
    .table-wrap { overflow: visible; background: transparent; border: 0; border-radius: 0; }
    .table-wrap table, .table-wrap tbody { display: block; }
    .table-wrap thead { width: 1px; height: 1px; position: absolute; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .table-wrap tbody { display: grid; gap: 10px; }
    .table-wrap tbody tr { display: block; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
    .table-wrap tbody tr:hover { background: var(--surface); }
    .table-wrap td { min-width: 0; display: grid; grid-template-columns: minmax(108px, 38%) minmax(0, 1fr); gap: 12px; padding: 9px 11px; overflow-wrap: anywhere; border-bottom: 1px solid #e6eaee; text-align: left; }
    .table-wrap td::before { content: attr(data-label); color: #596572; font-size: 11px; font-weight: 750; text-transform: uppercase; }
    .table-wrap td:last-child { border-bottom: 0; }
    .table-wrap td.numeric { white-space: normal; }
    .table-wrap td.mono { white-space: normal; word-break: break-all; }
    .table-wrap td.empty { display: block; padding: 32px 16px; text-align: center; }
    .table-wrap td.empty::before { content: none; }
}

@media (max-width: 380px) {
    .nav a { min-width: 76px; padding: 0 8px; }
    .filter-actions { flex-direction: column; }
    .toolbar .button { width: 100%; flex: auto; }
}
