:root {
  --navy: #0f2747;
  --blue: #1d4ed8;
  --sky: #eaf2ff;
  --line: #d8e0ea;
  --muted: #64748b;
  --text: #172033;
  --bg: #f5f7fb;
  --white: #fff;
  --surface: #fff;
  --surface-soft: #f8fafc;
  --input-bg: #fff;
  --green: #15803d;
  --red: #b91c1c;
  --amber: #b45309;
  --shadow: 0 12px 35px rgba(15,39,71,.09);
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 Arial, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg,var(--sky),var(--bg) 55%,var(--sky)); }
.login-card { width: min(440px,100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 30px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; color: white; display: grid; place-items: center; font-weight: 800; background: linear-gradient(145deg,var(--navy),var(--blue)); }
.brand-logo { width: 100%; height: 100%; padding: 4px; object-fit: contain; border-radius: inherit; background: white; }
.brand h1 { font-size: 19px; line-height: 1.2; margin: 0; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.login-card h2 { margin: 30px 0 5px; font-size: 25px; }
.login-card > p { color: var(--muted); margin: 0 0 22px; }
label { display: block; font-size: 12px; color: #475569; font-weight: 700; margin-bottom: 6px; }
input, select, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 9px; padding: 10px 11px; background: var(--input-bg); color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
textarea { min-height: 92px; resize: vertical; }
.field { margin-bottom: 15px; }
.grid-2,.grid-3,.grid-4,.grid-5 { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.grid-5 { grid-template-columns: repeat(5,minmax(0,1fr)); }
.btn { border: 0; border-radius: 9px; padding: 10px 15px; font-weight: 700; background: #e2e8f0; color: var(--navy); }
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: white; }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.topbar { position: sticky; top: 0; z-index: 20; height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mobile-menu-button { display: none; font-size: 18px; padding: 6px 10px; }
.topbar .brand-mark { width: 36px; height: 36px; border-radius: 10px; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-copy { text-align: right; }
.user-copy strong { display: block; }
.user-copy span { color: var(--muted); font-size: 11px; }
.layout { display: grid; grid-template-columns: 235px minmax(0,1fr); min-height: calc(100vh - 68px); }
.sidebar { background: var(--navy); padding: 18px 12px; }
.nav-section { color: #7890ad; font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; padding: 15px 13px 5px; }
.nav-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; border: 0; border-radius: 9px; padding: 11px 13px; margin: 3px 0; text-align: left; color: #cbd5e1; background: transparent; }
.nav-btn:hover,.nav-btn.active { color: white; background: rgba(255,255,255,.12); }
.badge { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; background: #f59e0b; color: #1f2937; font-size: 11px; font-weight: 800; }
main { padding: 26px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 3px 12px rgba(15,39,71,.035); }
.card + .card { margin-top: 16px; }
.card h3 { margin: 0 0 15px; font-size: 16px; }
.metric { min-height: 108px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 12px; font-size: 23px; }
.metric.in strong { color: var(--green); }
.metric.out strong { color: var(--red); }
.metric.pending strong { color: var(--amber); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th,td { padding: 10px 11px; border-bottom: 1px solid #e8edf3; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-soft); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
.amount { text-align: right; white-space: nowrap; font-weight: 700; }
.status { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.status-approved,.status-active { background: #dcfce7; color: #166534; }
.status-pending,.status-open,.status-settlement_pending { background: #fef3c7; color: #92400e; }
.status-settled { background: #dcfce7; color: #166534; }
.status-rejected,.status-inactive,.status-corrected { background: #fee2e2; color: #991b1b; }
.actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.notice { padding: 12px 14px; border-radius: 10px; margin: 12px 0; background: var(--sky); color: #1e3a8a; }
.notice.warn { background: #fff7ed; color: #9a3412; }
.notice.success { background: #ecfdf5; color: #166534; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.section-grid { display: grid; grid-template-columns: 360px minmax(0,1fr); gap: 16px; align-items: start; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.check label { margin: 0; }
.permission-group { margin-top: 16px; }
.permission-group h4 { margin: 0; padding: 9px 12px; background: #eef3f9; border-radius: 8px 8px 0 0; }
.permission-row { display: grid; grid-template-columns: minmax(220px,1fr) 210px; gap: 14px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-top: 0; }
.permission-row:last-child { border-radius: 0 0 8px 8px; }
.permission-row small { display: block; color: var(--muted); }
.role-note { display: inline-block; font-size: 11px; padding: 3px 7px; border-radius: 6px; background: #e2e8f0; color: #475569; margin-left: 6px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: 380px; padding: 13px 16px; border-radius: 10px; color: white; background: #1e293b; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }
.loading { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(248,250,252,.72); backdrop-filter: blur(2px); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #bfdbfe; border-top-color: var(--blue); animation: spin .8s linear infinite; }
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(15,39,71,.55); }
.modal-card { position: relative; width: min(760px,100%); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 15px; padding: 24px; box-shadow: var(--shadow); }
.modal-close { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eef2f7; font-size: 22px; }
.public-approval-wrap { min-height: 100vh; padding: 28px 16px; background: linear-gradient(135deg,var(--sky),var(--bg) 55%,var(--sky)); }
.public-approval-shell { width: min(920px,100%); margin: 0 auto; }
.public-brand { margin-bottom: 20px; padding: 0 4px; }
.public-approval-page { padding: 0; }
.approval-detail-card,.approval-pin-card { margin-top: 16px; }
.detail-list { padding: 8px 0; }
.public-receipt { display: grid; gap: 12px; justify-items: start; }
.public-receipt img { display: block; width: min(100%,760px); max-height: 720px; object-fit: contain; border: 1px solid var(--line); border-radius: 12px; background: #f8fafc; }
.public-receipt iframe { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.copy-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.amount-in { color: var(--green); }
.amount-out { color: var(--red); }
.row-overdue { background: #fff7ed; }
.allocation-row { padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.readonly-link { background: var(--surface-soft); cursor: copy; }
.receipt-actions { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
.receipt-picker small { display: block; margin-top: 6px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.settings-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(280px,.75fr); gap: 16px; align-items: start; }
.branding-preview { min-height: 150px; display: grid; place-items: center; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface-soft); }
.branding-preview img { display: block; max-width: 100%; max-height: 140px; object-fit: contain; }
.theme-color-row { display: flex; align-items: center; gap: 12px; }
.theme-color-row input[type="color"] { width: 72px; height: 44px; padding: 3px; }
.theme-color-row span { font-family: monospace; font-weight: 700; text-transform: uppercase; }
.nav-backdrop { display: none; }

html[data-theme="dark"] {
  --text: #e5edf8;
  --muted: #9fb0c6;
  --bg: #0b1220;
  --surface: #111c2e;
  --surface-soft: #17243a;
  --input-bg: #0e192a;
  --line: #2a3a52;
  --sky: #13233c;
  --shadow: 0 14px 38px rgba(0,0,0,.32);
}
html[data-theme="dark"] label { color: #bdcadb; }
html[data-theme="dark"] .btn { color: var(--text); background: #24344b; }
html[data-theme="dark"] .btn-primary { color: white; background: var(--blue); }
html[data-theme="dark"] .btn-success { color: white; background: var(--green); }
html[data-theme="dark"] .btn-danger { color: white; background: var(--red); }
html[data-theme="dark"] th,html[data-theme="dark"] td { border-color: var(--line); }
html[data-theme="dark"] .permission-group h4,html[data-theme="dark"] .permission-row,html[data-theme="dark"] .allocation-row { background: var(--surface-soft); }
html[data-theme="dark"] .loading { background: rgba(11,18,32,.76); }
html[data-theme="dark"] .modal-close { background: #24344b; color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width:1050px) { .grid-5 { grid-template-columns: repeat(3,1fr); } }
@media (max-width:900px) {
  .layout { grid-template-columns: 1fr; }
  .mobile-menu-button { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: 68px; bottom: 0; z-index: 40; width: min(310px,86vw); overflow-y: auto; padding: 14px 12px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 10px 0 30px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: translateX(0); }
  .nav-backdrop { position: fixed; inset: 68px 0 0; z-index: 35; border: 0; background: rgba(2,8,23,.56); }
  body.nav-open .nav-backdrop { display: block; }
  .grid-4,.grid-5 { grid-template-columns: repeat(2,1fr); }
  .section-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width:620px) {
  .topbar { padding: 0 14px; }
  .topbar .brand p,.user-copy { display: none; }
  .topbar .brand h1 { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-user { gap: 6px; }
  .topbar-user .theme-toggle { padding: 6px 8px; font-size: 0; }
  .topbar-user .theme-toggle::after { content: '◐'; font-size: 16px; }
  .login-card { padding: 22px; }
  .login-theme-toggle { font-size: 0; padding: 7px 9px; }
  .login-theme-toggle::after { content: '◐'; font-size: 16px; }
  main { padding: 16px; }
  .grid-2,.grid-3,.grid-4,.grid-5 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .permission-row { grid-template-columns: 1fr; }
  .copy-row { grid-template-columns: 1fr; }
  .receipt-actions { grid-template-columns: 1fr; }
  .public-receipt iframe { height: 420px; }
  .public-brand { align-items: flex-start; }
  .public-brand .theme-toggle { margin-left: auto; font-size: 0; padding: 7px 9px; }
  .public-brand .theme-toggle::after { content: '◐'; font-size: 16px; }
}
