:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  --bg: #f5f7fb;
  --surface: #fff;
  --ink: #17233b;
  --muted: #52627a;
  --line: #dce4ef;
  --soft: #eaf1ff;
  --accent: #174ea6;
  --action: #195ccc;
  --green: #188038;
  --red: #c5221f;
  --gold: #fbbc04;
  --shadow: 0 8px 24px #2041760a;
}
body.dark {
  color-scheme: dark;
  --bg: #111826;
  --surface: #1a2435;
  --ink: #ecf3ff;
  --muted: #aebdd2;
  --line: #394960;
  --soft: #263a5b;
  --accent: #b2cdff;
  --green: #7fe4a1;
  --red: #ff9f98;
  --shadow: 0 8px 24px #0003;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-block: 0 12px; }
h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); line-height: 1.15; }
h2 { font-size: 1.16rem; }
h3 { font-size: 1rem; }
p, li { line-height: 1.6; }
ul { padding-inline-start: 1.25rem; }
hr { border: 0; border-block-start: 1px solid var(--line); margin-block: 16px; }
button, input, select { font: inherit; }
button, input, select { border: 1px solid var(--line); border-radius: 10px; }
button { min-height: 42px; padding: 8px 14px; background: var(--surface); color: var(--ink); cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--action); border-color: var(--action); color: white; font-weight: 650; }
button.secondary { background: var(--soft); color: var(--ink); }
:focus-visible { outline: 3px solid #4285f4; outline-offset: 2px; }
.finance-topbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 68px; padding: 10px max(18px, calc((100vw - 1440px) / 2));
  background: var(--surface); border-block-end: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; direction: ltr; }
.brand b { white-space: nowrap; font-size: 1.17rem; letter-spacing: -.025em; }
.brand span { color: var(--accent); }
.finance-actions { display: flex; gap: 6px; justify-content: flex-end; }
.workspace { max-width: 1480px; margin: auto; padding: 22px 20px; }
.finance-shell { display: grid; grid-template-columns: 228px minmax(0,1fr); gap: 26px; align-items: start; }
.finance-view { min-width: 0; }
#nav-menu { display: none; }
#tabs {
  position: sticky; top: 90px; max-height: calc(100dvh - 110px);
  overflow: auto; scrollbar-width: thin; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.nav-group + .nav-group { border-block-start: 1px solid var(--line); margin-block-start: 9px; padding-block-start: 5px; }
.nav-group p { font-size: .75rem; font-weight: 650; color: var(--muted); margin: 7px 8px; }
#tabs button {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 38px;
  text-align: start; padding: 5px 8px; background: transparent; border-color: transparent;
  font-size: .9rem;
}
#tabs button:hover, #tabs button[aria-current] { background: var(--soft); color: var(--accent); }
#tabs button[aria-current] { font-weight: 700; }
#tabs button span { display: grid; place-items: center; width: 23px; height: 23px; flex: none; color: var(--accent); font-size: 1.1rem; }
.page-header {
  display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-block-end: 18px;
  padding: 16px 0; border-block-end: 1px solid var(--line);
}
.page-header h1 { margin: 0; }
.account { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
#role { background: var(--soft); color: var(--accent); padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.panel { padding: clamp(16px, 2.4vw, 24px); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); margin-block-end: 14px; min-width: 0; }
.login { max-width: 435px; margin: clamp(30px, 10vh, 100px) auto 0; border-block-start: 4px solid #4285f4; }
.login p, .notice, small { color: var(--muted); }
.login form { margin-block-start: 20px; }
form, .formgrid { display: grid; gap: 14px; }
form + form { margin-block-start: 20px; padding-block-start: 18px; border-block-start: 1px solid var(--line); }
.formgrid { grid-template-columns: repeat(auto-fit,minmax(min(100%,190px),1fr)); }
form button { justify-self: start; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; font-size: .9rem; }
input, select { min-height: 42px; width: 100%; min-width: 0; padding: 9px 11px; background: var(--surface); color: var(--ink); }
.checkrow { display: flex; flex-wrap: wrap; gap: 12px; }
.checkrow label { display: flex; align-items: center; gap: 6px; }
.checkrow input { min-height: auto; width: auto; accent-color: var(--action); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.permission-matrix td, .permission-matrix thead th:not(:first-child) { text-align: center; }
.permission-matrix input { min-height: auto; width: 19px; height: 19px; margin: 3px; accent-color: var(--action); }
.permission-matrix tbody th { background: var(--surface); color: var(--ink); }
.permission-matrix label span { display: none; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
legend { color: var(--muted); }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit,minmax(min(100%,220px),1fr)); }
.cards .panel { border-block-start: 3px solid #4285f4; }
.cards .panel:nth-child(2) { border-block-start-color: #34a853; }
.cards .panel:nth-child(3) { border-block-start-color: var(--gold); }
.balance { font-size: clamp(1.25rem, 3vw, 2rem); font-weight: 700; unicode-bidi: isolate; overflow-wrap: anywhere; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.table-scroll { overflow-x: auto; margin-block: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 10px; border-block-end: 1px solid var(--line); text-align: start; white-space: nowrap; }
th { background: var(--bg); color: var(--muted); }
#pad { display: block; width: min(100%, 560px); height: 150px; background: white; border: 1px dashed #8495af; border-radius: 10px; touch-action: none; margin-block-end: 12px; }
#status:empty, #delivery:empty { display: none; }
#status, #delivery { white-space: pre-wrap; overflow-wrap: anywhere; }
#status { max-width: 680px; margin: 16px auto; color: var(--accent); }
.policy { max-width: 850px; }
footer { margin-block: 24px 8px; text-align: center; font-size: .85rem; }
a { color: var(--accent); }
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 16px; width: min(520px, 94vw); max-height: 92dvh; padding: 20px; }
dialog::backdrop { background: #091526a0; }
dialog code { overflow-wrap: anywhere; }
#receipt { width: min(900px, 95vw); }
.dialog-head, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-block: 10px; flex-wrap: wrap; }
.dialog-head h2 { margin: 0; }
.voucher-img { display: block; width: 100%; height: auto; }
@media (max-width: 900px) {
  .finance-shell { grid-template-columns: 185px minmax(0,1fr); gap: 14px; }
  .permission-matrix table, .permission-matrix tbody { display: block; }
  .permission-matrix thead, .permission-matrix .permission-na { display: none; }
  .permission-matrix tr {
    display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,125px),1fr));
    gap: 6px; padding: 10px 0; border-block-end: 1px solid var(--line);
  }
  .permission-matrix th, .permission-matrix td { border: 0; padding: 3px; white-space: normal; }
  .permission-matrix th { grid-column: 1 / -1; }
  .permission-matrix label { display: flex; align-items: center; text-align: start; }
  .permission-matrix label span { display: inline; }
}
@media (max-width: 640px) {
  .workspace { padding: 14px 12px; }
  .finance-topbar { padding-inline: 12px; }
  .finance-topbar button { padding-inline: 8px; }
  .brand img { width: 30px; height: 30px; }
  .brand b { font-size: 1rem; }
  .finance-shell { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  #nav-menu { display: block; justify-self: start; }
  #tabs { display: none; position: static; max-height: 55dvh; }
  #tabs.is-open { display: block; }
  .page-header { padding-block: 10px; }
}
@media print {
  .finance-topbar, #tabs, #nav-menu, button { display: none !important; }
  .finance-shell { display: block; }
  .panel { box-shadow: none; break-inside: avoid; }
}
