:root {
  color-scheme: light;
  --ink: #141411;
  --muted: #68665e;
  --paper: #f1eee7;
  --white: #fbfaf7;
  --gold: #ba913e;
  --gold-dark: #96712f;
  --line: #d8d3c9;
  --danger: #9b3d2d;
  --radius: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.5; }
h1, h2 { margin: 0 0 12px; line-height: 1.15; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
code { padding: 1px 5px; border-radius: 4px; background: #e8e4db; font-size: 13px; word-break: break-all; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand img { display: block; width: 84px; height: auto; }
.topbar-title { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.portal { width: min(1100px, 100%); margin: 0 auto; padding: 20px 16px 60px; }
.card { margin-bottom: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.card.narrow { width: min(460px, 100%); margin: 28px auto; }

label { display: grid; gap: 5px; margin-bottom: 12px; color: #33322e; font-size: 13px; font-weight: 600; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 11px; border: 1px solid #c8c2b6; border-radius: 6px; color: var(--ink); background: #fff; font: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
select { width: auto; min-width: 160px; }
.form-grid select { width: 100%; }

.btn { min-height: 44px; padding: 0 18px; border: 1px solid #c8c2b6; border-radius: var(--radius); color: var(--ink); background: transparent; font: inherit; font-weight: 700; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.btn:hover:not(:disabled) { transform: translateY(-2px); background: #eae5d9; box-shadow: 0 6px 14px rgba(20, 20, 17, .12); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { cursor: wait; opacity: .6; }
.btn-primary { border-color: var(--ink); color: var(--white); background: var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--gold-dark); border-color: var(--gold-dark); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: #d9b7ae; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.form-error { margin: 0 0 12px; padding: 9px 12px; border-left: 3px solid var(--danger); border-radius: 6px; color: #6d2a1f; background: #f5e7e2; font-size: 13px; }
.hint, .form-hint { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.qr { display: block; margin: 8px auto 12px; background: #fff; }

.app-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; }
.app-bar-left, .app-bar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.badge { padding: 3px 10px; border-radius: 999px; color: var(--gold-dark); background: #efe6d2; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.security-status { color: var(--muted); font-size: 13px; }

.notice { margin: 0 0 16px; padding: 10px 14px; border: 1px solid #dfd5bd; border-left: 3px solid var(--gold-dark); border-radius: 8px; background: #eee9df; }
.notice[data-kind='error'] { border-color: #e4c6bb; border-left-color: var(--danger); background: #f5e7e2; }
.notice[data-kind='warn'] { border-left-color: #b07a1a; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab { min-height: 42px; padding: 0 18px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); background: var(--white); font: inherit; font-weight: 700; cursor: pointer; }
.tab[aria-selected='true'] { color: var(--white); border-color: var(--ink); background: var(--ink); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
.form-grid h2, .span-2 { grid-column: 1 / -1; }
.miles-preview { grid-column: 1 / -1; margin: -4px 0 12px; font-weight: 700; color: var(--gold-dark); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.row-actions { white-space: nowrap; }
td.row-actions .btn { margin-right: 4px; }
.empty { color: var(--muted); }

.diagnostics { margin-top: 24px; color: var(--muted); font-size: 13px; }
.diagnostics pre { margin: 8px 0 0; padding: 10px; overflow-x: auto; border-radius: 8px; background: #e8e4db; white-space: pre-wrap; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .tab { flex: 1; padding: 0 8px; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}

.password-field { margin-bottom: 12px; }
.password-field label { margin-bottom: 5px; }
.password-input { position: relative; }
.password-input input { padding-right: 52px; }
.password-toggle { position: absolute; top: 1px; right: 1px; bottom: 1px; width: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; }
.password-toggle:hover { color: var(--ink); background: #eee9df; }
.password-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.password-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.password-toggle .eye-slash { display: none; }
.password-toggle[aria-pressed="true"] .eye-slash { display: block; }

.login-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.forgot-password-link { color: var(--gold-dark); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.forgot-password-link:hover { color: var(--ink); }
.forgot-password-link:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

.portal:has([data-view="app"]:not([hidden])) { width: min(1600px,100%); }
.legacy-workspace { display:none!important; }
#workspace-modern { margin-top:20px; }
