:root {
  --bg: #f7f5f0; --panel: #ffffff; --ink: #1d2320; --muted: #6b716c; --line: #e3dfd5; --brand: #1f3a2e; --brand-ink: #e9dfc8;
  --accent: #c8a24a; --ok: #2f7a4f; --warn: #a6541b; --danger: #a8322d; --focus: #2f6fdb; --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121614; --panel: #1b201d; --ink: #e8ebe8; --muted: #9aa39d; --line: #2b322e; --brand: #0f1d17; --brand-ink: #e9dfc8; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; } h2 { font-size: 1.15rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); } .small { font-size: .85em; } .warn { color: var(--warn); } .pad { padding: 1rem; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.narrow { max-width: 420px; width: 100%; }
.brand { font-weight: 700; letter-spacing: .02em; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: .5rem .9rem; font: inherit; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--muted); } .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); } .btn.small { padding: .25rem .6rem; min-height: 32px; font-size: .9em; } .btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .6; cursor: default; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-height: 40px; max-width: 100%; }
textarea { width: 100%; }
.field { display: flex; flex-direction: column; gap: .25rem; } .field > span { font-size: .85em; color: var(--muted); } .req { color: var(--danger); }
.check { display: inline-flex; gap: .4rem; align-items: center; } .checks { display: flex; flex-wrap: wrap; gap: .75rem; }
.list { list-style: none; padding: 0; margin: 0; } .list > li { padding: .6rem 0; border-bottom: 1px solid var(--line); } .list > li:last-child { border-bottom: 0; }
.list a { display: flex; flex-direction: column; text-decoration: none; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 99px; background: var(--line); font-size: .8em; white-space: nowrap; }
.pill.ok, .pill.v-active, .pill.v-declared, .pill.v-paid { background: color-mix(in srgb, var(--ok) 20%, transparent); }
.pill.v-inactive, .pill.v-withdrawn, .pill.v-void { opacity: .7; }

/* layout */
#app.layout-sidebar { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.nav { background: var(--brand); color: var(--brand-ink); padding: 1rem .75rem; display: flex; flex-direction: column; gap: .75rem; }
.nav .brand { text-decoration: none; font-size: 1.05rem; padding: 0 .5rem; }
.nav ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.nav li a { display: flex; gap: .6rem; align-items: center; padding: .5rem; border-radius: 8px; text-decoration: none; }
.nav li a:hover, .nav li a[aria-current] { background: rgb(255 255 255 / .1); }
.nav .icon { width: 1.2em; text-align: center; opacity: .85; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: .25rem; padding: 0 .5rem; }
.nav-foot .muted { color: color-mix(in srgb, var(--brand-ink) 70%, transparent); }
.status { font-size: .8em; } .status.off { color: #f0b37e; }
#app.layout-header { display: block; } .nav.header { flex-direction: row; align-items: center; flex-wrap: wrap; padding: .5rem 1rem; }
.nav.header ul { flex-direction: row; flex-wrap: wrap; } .nav.header .nav-foot { margin: 0 0 0 auto; flex-direction: row; gap: 1rem; }
main { padding: 1.25rem; min-width: 0; outline: none; }
.draft-banner { grid-column: 1 / -1; background: var(--accent); color: #1d2320; padding: .4rem 1rem; font-size: .9em; }

/* screens: header full width, main + side columns */
.screen { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "header header" "main side" "tabs side"; gap: 1rem; align-items: start; }
.c-header { grid-area: header; } .c-main { grid-area: main; } .c-side { grid-area: side; } .c-tabs { grid-area: tabs; }
.c:empty { display: none; }
.screen:not(:has(.c-side:not(:empty))) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main" "tabs"; }
.c > .block + .block { margin-top: 1rem; }
.heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.back { text-decoration: none; font-size: .9em; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; } .search { flex: 1 1 220px; } .filters { display: flex; gap: .5rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; } .data th, .data td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data th { font-size: .8em; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.data tr.clickable { cursor: pointer; } .data tr.clickable:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.data.compact td, .data.compact th { padding: .35rem .5rem; } .data td.actions { text-align: right; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 .75rem; } dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: .6rem .8rem; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; min-height: 40px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.lane { background: color-mix(in srgb, var(--line) 50%, transparent); border-radius: var(--radius); padding: .6rem; }
.lane h3 { display: flex; justify-content: space-between; text-transform: capitalize; } .count { color: var(--muted); font-weight: normal; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; margin-top: .4rem; cursor: default; }
.tile[onclick], .tile:hover { border-color: var(--muted); }
.stat { text-align: center; } .stat-n { font-size: 2.2rem; font-weight: 700; }
.agenda .day { margin-bottom: 1rem; } .entry { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .5rem; border-left: 3px solid var(--line); background: var(--panel); margin: .3rem 0; border-radius: 0 8px 8px 0; }
.entry.s-declared { border-left-color: var(--ok); } .entry.s-entered { border-left-color: var(--accent); }
.plan td.cell { min-width: 90px; cursor: pointer; } .plan td.has { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.plan .p-target { font-weight: 600; } .plan .p-possible { opacity: .7; }
.quick { display: flex; flex-direction: column; gap: .4rem; }
.quick-row { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.quick-row summary { padding: .8rem; cursor: pointer; display: flex; gap: .5rem; align-items: center; min-height: 48px; } .quick-row.done { opacity: .75; }
.quick-fields { padding: 0 .8rem .8rem; display: flex; flex-direction: column; gap: .6rem; }
.seg { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; } .seg-label { width: 100%; font-size: .85em; color: var(--muted); }
.seg-btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 99px; padding: .45rem .9rem; font: inherit; min-height: 40px; cursor: pointer; }
.seg-btn.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; margin: .5rem 0; } .msg.out { border-left: 3px solid var(--accent); }
.msg .body { white-space: pre-wrap; font: inherit; margin: .4rem 0 0; }
.history ul { margin: .25rem 0 0; padding-left: 1rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.perm-grid fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: .25rem; } .perm-grid legend { text-transform: capitalize; font-weight: 600; }
details.role { border-top: 1px solid var(--line); padding: .5rem 0; } details.role summary { cursor: pointer; font-weight: 600; }
.block-error { padding: .75rem; border: 1px dashed var(--danger); border-radius: 8px; color: var(--danger); }
dialog.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 1.25rem; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 150%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; transition: transform .2s; max-width: calc(100vw - 32px); z-index: 10; }
#toast.show { transform: translate(-50%, 0); } #toast.error { background: var(--danger); color: #fff; }
.md p { margin: 0 0 .5rem; }

/* phones */
@media (max-width: 760px) {
  #app.layout-sidebar, #app.layout-bottom-tabs { display: block; padding-bottom: 64px; }
  .nav.sidebar, .nav.bottom-tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; flex-direction: row; padding: .25rem; padding-bottom: max(.25rem, env(safe-area-inset-bottom)); }
  .nav.sidebar .brand, .nav.bottom-tabs .brand { display: none; }
  .nav.sidebar .nav-foot, .nav.bottom-tabs .nav-foot { position: fixed; top: 0; right: 0; margin: 0; padding: .2rem .6rem; background: transparent; }
  .nav-foot a, .nav-foot .linkish + .linkish { display: none; }
  .nav-foot { flex-direction: row !important; gap: .5rem; align-items: center; }
  .nav-foot .linkish { background: var(--brand); color: var(--brand-ink); border-radius: 0 0 0 8px; padding: .2rem .6rem; text-decoration: none; font-size: .75rem; }
  .nav-foot .status.on { display: none; }
  .nav-foot .status.off { background: var(--warn); color: #fff; border-radius: 0 0 0 8px; padding: .2rem .6rem; }
  .nav.sidebar ul, .nav.bottom-tabs ul { flex-direction: row; overflow-x: auto; width: 100%; }
  .nav.sidebar li a, .nav.bottom-tabs li a { flex-direction: column; gap: 0; font-size: .7rem; padding: .35rem .5rem; min-width: 64px; }
  .nav .icon { font-size: 1.2rem; }
  main { padding: 16px; }
  .screen, .screen:not(:has(.c-side:not(:empty))) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main" "side" "tabs"; }
  .data thead { display: none; } .data tr { display: block; border-bottom: 1px solid var(--line); padding: .4rem 0; } .data td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem .7rem; }
  .data td::before { content: attr(data-label); color: var(--muted); font-size: .85em; } .plan td::before { content: none; }
}
@media (min-width: 761px) { .nav.bottom-tabs { flex-direction: column; } #app.layout-bottom-tabs { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; } }
main:focus-visible { outline: none; }
.nav li a span { white-space: nowrap; }
.quick-fields .btn.primary, .quick-fields .btn { justify-content: center; }
.data tbody th { text-transform: none; font-size: 1em; color: var(--ink); letter-spacing: 0; }
.data tbody th a { text-decoration: none; font-weight: 600; }
.linkish { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; text-decoration: underline; opacity: .85; }
