:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --sidebar: #0e1116;
  --surface: #13161c;
  --surface-2: #171b22;
  --surface-3: #1e232b;
  --input: #0f1217;
  --border: #222831;
  --border-strong: #2d343f;
  --text: #e7eaf0;
  --text-2: #b3bbc7;
  --muted: #7d8696;
  --accent: #4a7dff;
  --accent-hover: #6590ff;
  --accent-text: #8fb0ff;
  --accent-soft: rgba(74, 125, 255, .14);
  --green: #3ecf8e;
  --amber: #f5b54a;
  --amber-soft: rgba(245, 181, 74, .14);
  --red: #f26d6d;
  --red-soft: rgba(242, 109, 109, .13);
  --cyan: #4cc9f0;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a303b; border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Sidebar ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; background: var(--sidebar); border-right: 1px solid var(--border); padding: 22px 14px; display: flex; flex-direction: column; gap: 26px; z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #4a7dff, #7c5cff); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .5px; color: #fff; flex: none; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav { display: grid; gap: 4px; }
.nav-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); font-weight: 500; cursor: pointer; text-align: left; transition: background .15s, color .15s; }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- Layout ---------- */
.main { margin-left: 248px; padding: 28px 36px 48px; max-width: 1500px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .15s, border-color .15s, color .15s; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: rgba(242, 109, 109, .22); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Status colours ---------- */
.badge { --c: #9aa4b2; --c-soft: rgba(154, 164, 178, .12); display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--c); background: var(--c-soft); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-new { --c: #9aa4b2; --c-soft: rgba(154, 164, 178, .12); }
.status-inspection-scheduled { --c: #4cc9f0; --c-soft: rgba(76, 201, 240, .12); }
.status-under-valuation { --c: #f5b54a; --c-soft: rgba(245, 181, 74, .13); }
.status-under-review { --c: #a78bfa; --c-soft: rgba(167, 139, 250, .14); }
.status-approved { --c: #3ecf8e; --c-soft: rgba(62, 207, 142, .13); }
.status-sent-to-bank { --c: #6b9bff; --c-soft: rgba(107, 155, 255, .15); }
.status-closed { --c: #6b7280; --c-soft: rgba(107, 114, 128, .16); }
.status-on-hold { --c: #fb7185; --c-soft: rgba(251, 113, 133, .13); }

/* ---------- Dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { --kpi: var(--text-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--kpi); flex: none; }
.kpi strong { display: block; font-size: 30px; font-weight: 650; letter-spacing: -.02em; margin-top: 8px; line-height: 1.1; }
.kpi-hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.k-arranged { --kpi: var(--cyan); }
.k-unarranged { --kpi: var(--amber); }
.k-approved { --kpi: var(--green); }
.k-sent { --kpi: var(--accent); }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.panel-grid .panel { margin-bottom: 0; }
.g-scheduled { --c: var(--cyan); }
.g-process { --c: #a78bfa; }
.g-unarranged { --c: var(--amber); }
.status-chart { padding: 18px 20px; display: grid; gap: 13px; }
.status-row { display: grid; grid-template-columns: 172px 1fr 28px; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); }
.status-name { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--c); transition: width .3s; }
.status-row strong { text-align: right; color: var(--text); font-weight: 600; }

/* ---------- Panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.panel-body { padding: 20px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 11.5px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; white-space: nowrap; font-size: 13px; }
th { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); color: var(--text-2); }
tbody tr:last-child td { border-bottom: 0; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--surface-2); }
td.strong { color: var(--text); font-weight: 600; }
td.time { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
td.empty { text-align: center; color: var(--muted); padding: 40px 16px; white-space: normal; }
.sub { color: var(--muted); margin-left: 6px; }
.not-arranged { color: var(--amber); font-size: 12.5px; }

/* ---------- Forms ---------- */
.form-section { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.form-section h3 { margin: 0 0 14px; font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.req { color: var(--red); }
.span-2 { grid-column: span 2; }
input, select, textarea { width: 100%; background: var(--input); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: #5c6574; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; padding-right: 34px; cursor: pointer; background-repeat: no-repeat; background-position: right 12px center; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237d8696' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
select option { background: var(--surface-2); }
textarea { resize: vertical; min-height: 160px; line-height: 1.6; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; background: var(--surface-2); }
.filters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; align-items: center; }
.search { position: relative; width: 280px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 34px; }
.filters select { width: 190px; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.inline-form .field { width: 240px; }

/* ---------- Workspace ---------- */
.ws-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .1em; color: var(--accent-text); text-transform: uppercase; }
.ws-head h2 { margin: 4px 0 2px; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.ws-head p { margin: 0; color: var(--muted); font-size: 13px; }
.ws-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab-btn { position: relative; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 10px 14px 12px; color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab-btn:hover, .tab-btn.active { color: var(--text); }
.tab-btn.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--border); }
.summary-item { background: var(--surface); padding: 14px 20px; min-height: 72px; }
.summary-item span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.summary-item strong { font-weight: 500; color: var(--text); word-break: break-word; }
.summary-item.wide { grid-column: span 2; }
.section-actions { display: flex; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ---------- Photos ---------- */
#photoPanel { transition: border-color .15s, box-shadow .15s; }
#photoPanel.dragover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; padding: 20px; }
.photo { position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); cursor: zoom-in; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.photo:hover img { transform: scale(1.03); }
.photo-del { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(10, 12, 16, .78); color: #fff; font-size: 17px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity .15s; display: grid; place-items: center; }
.photo:hover .photo-del, .photo-del:focus-visible { opacity: 1; }
@media (hover: none) { .photo-del { opacity: 1; } }
.photo-empty { grid-column: 1 / -1; display: grid; place-items: center; gap: 4px; text-align: center; padding: 44px 16px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); cursor: pointer; }
.photo-empty strong { color: var(--text-2); font-weight: 600; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (hover: hover) and (pointer: fine) { .camera-only { display: none; } }

/* ---------- Workflow ---------- */
.stepper { list-style: none; margin: 0; padding: 30px 24px 24px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; font-size: 12px; color: var(--muted); padding: 0 4px; }
.step::before { content: ""; position: absolute; top: 15px; left: calc(-50% + 20px); right: calc(50% + 20px); height: 2px; background: var(--border-strong); }
.step:first-child::before { display: none; }
.step-dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 13px; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--muted); position: relative; z-index: 1; }
.step.done, .step.current { color: var(--text-2); }
.step.done::before, .step.current::before { background: var(--accent); }
.step.done .step-dot { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.step.current { color: var(--text); font-weight: 600; }
.step.current .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.workflow-controls { display: flex; justify-content: space-between; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
.wf-right { display: flex; gap: 10px; }
.stepper.paused { opacity: .4; }
.hold-notice { margin: 20px 24px 0; padding: 10px 14px; border-radius: var(--radius-sm); background: rgba(251, 113, 133, .1); color: #fb7185; font-size: 13px; font-weight: 500; }

/* ---------- Sync & sign-in ---------- */
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.sync-pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.sync-pill:hover { background: var(--surface-3); }
.sync-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-pill[data-state="ok"] i { background: var(--green); }
.sync-pill[data-state="busy"] i { background: var(--cyan); animation: pulse 1s ease-in-out infinite; }
.sync-pill[data-state="offline"] i { background: var(--amber); }
.sync-pill[data-state="error"] { color: var(--red); }
.sync-pill[data-state="error"] i { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }
.icon-btn { padding: 8px; }
.full { width: 100%; }
.save-hint { margin-right: auto; align-self: center; font-size: 12.5px; color: var(--muted); }
.login-screen { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 30% 20%, rgba(74, 125, 255, .12), transparent 55%), var(--bg); }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; justify-items: center; text-align: center; padding: 32px 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .45); }
.login-card .brand-mark { width: 48px; height: 48px; border-radius: 14px; font-size: 16px; }
.login-card h1 { margin: 2px 0 0; font-size: 20px; font-weight: 650; }
.login-card p { margin: 0; color: var(--muted); font-size: 13px; }
.login-card .login-error { min-height: 18px; color: var(--red); }
.photo.loading { display: grid; place-items: center; cursor: default; }
.photo-wait { font-size: 12px; color: var(--muted); }
.photo-sync { position: absolute; left: 8px; bottom: 8px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(10, 12, 16, .78); color: var(--cyan); font-size: 12px; font-weight: 700; }

/* ---------- Overlays ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 8, .88); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 24px; }
.lightbox-inner { display: grid; gap: 12px; max-width: min(1100px, 100%); }
.lightbox img { max-width: 100%; max-height: 78vh; border-radius: 10px; display: block; margin: auto; }
.lightbox-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--text-2); font-size: 13px; }
.lightbox-bar div { display: flex; gap: 8px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 60; max-width: 380px; padding: 12px 16px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text); box-shadow: 0 12px 32px rgba(0, 0, 0, .45); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.toast.show { opacity: 1; transform: none; }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.success::before { background: var(--green); }
.toast.error::before { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .panel-grid { grid-template-columns: 1fr; }
  .summary-grid, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stepper { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 24px; }
  .step:nth-child(5)::before { display: none; }
}
@media (max-width: 820px) {
  .sidebar { position: sticky; top: 0; width: auto; flex-direction: row; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; }
  .brand span { display: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; grid-template-columns: repeat(3, 1fr); gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--sidebar); border-top: 1px solid var(--border); z-index: 20; }
  .nav-btn { flex-direction: column; justify-content: center; gap: 3px; font-size: 11.5px; padding: 8px 4px; text-align: center; }
  .nav-btn.active { background: transparent; }
  .main { margin-left: 0; padding: 20px 16px 96px; }
  .topbar h1 { font-size: 20px; }
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .topbar-actions #quickNewBtn { margin-left: auto; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .k-total { grid-column: 1 / -1; }
  .form-grid, .summary-grid { grid-template-columns: 1fr; }
  .span-2, .summary-item.wide { grid-column: auto; }
  .ws-head, .panel-head.stack { flex-direction: column; align-items: flex-start; }
  .filters { width: 100%; }
  .search, .filters select { width: 100%; }
  .filters .btn { flex: 1; }
  .stepper { grid-template-columns: 1fr; row-gap: 12px; }
  .step { flex-direction: row; text-align: left; }
  .step::before { display: none; }
  .inline-form .field { width: 100%; }
  .toast { left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: none; }
  #photoPanel .panel-head { flex-direction: column; align-items: flex-start; }
}
