:root {
  --paper: #F3F4F7;
  --surface: #FFFFFF;
  --ink: #1C2233;
  --muted: #5B6378;
  --line: #D9DDE6;
  --line-soft: #E8EBF1;
  --primary: #2E3A78;
  --primary-ink: #FFFFFF;
  --primary-soft: #E6E8F4;
  --red: #B42318;
  --red-soft: #FDECEA;
  --amber: #A5530A;
  --amber-soft: #FDF1E3;
  --ok: #1F6F4A;
  --focus: #2E3A78;
  --radius-sm: 4px;
  --radius-md: 8px;
  --font: "Public Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Masthead ---------- */
.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 3vw, 32px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background:
    linear-gradient(var(--primary-ink), var(--primary-ink)) 8px 11px / 18px 2.5px no-repeat,
    linear-gradient(var(--primary-ink), var(--primary-ink)) 8px 16px / 18px 2.5px no-repeat,
    linear-gradient(var(--primary-ink), var(--primary-ink)) 8px 21px / 11px 2.5px no-repeat,
    var(--primary);
}
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { margin: 0; font-size: 13px; color: var(--muted); }
.brand-sub a { color: inherit; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px;
  white-space: nowrap; text-decoration: none; color: inherit;
}
.btn:hover { border-color: #B9BFCC; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink) !important; }
.btn.primary:hover { background: #253068; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Sign-in gate ---------- */
main { padding: 20px clamp(16px, 3vw, 32px) 40px; }
.gate { max-width: 460px; margin: 12vh auto 0; }
.gate h2 { font-size: 26px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.015em; }
.gate p { color: var(--muted); margin: 0 0 20px; }
.gate-error { color: var(--red) !important; margin-top: 16px !important; }

/* ---------- Status bar (the proportional strip) ---------- */
.statusbar {
  display: flex; gap: 3px; margin-bottom: 18px;
  border-radius: var(--radius-md); overflow: hidden;
  background: var(--line);
  padding: 3px;
}
.seg {
  --hue: var(--primary);
  flex: var(--grow, 1) 1 0; min-width: 118px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end;
  padding: 10px 14px 11px;
  border: 0; border-radius: 5px; cursor: pointer; text-align: left;
  background: var(--surface);
  position: relative;
  transition: background-color .15s ease;
}
.seg::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: var(--hue); border-radius: 5px 5px 0 0; opacity: .85;
}
.seg .n { font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.seg .l { font-size: 13px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.seg .flag { font-size: 12px; color: var(--red); font-weight: 600; margin-top: 2px; }
.seg:hover { background: #FAFBFD; }
.seg[aria-pressed="true"] { background: var(--hue); color: #fff; }
.seg[aria-pressed="true"] .l, .seg[aria-pressed="true"] .flag { color: rgba(255,255,255,.88); }
.seg.all { --hue: var(--ink); flex: 0 0 auto; min-width: 96px; }
.seg.none { --hue: #8A91A3; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; position: relative; }
.search { flex: 1 1 260px; }
.search input, .scope select, .field input, .field select, .field textarea {
  width: 100%; min-height: 38px; padding: 7px 11px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.search input:focus, .scope select:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.scope { flex: 0 0 auto; }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; user-select: none; }
.toggle input { width: 16px; height: 16px; accent-color: var(--red); }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.columns-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: 280px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(28,34,51,.14); padding: 8px;
}
.columns-pop label { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 4px; font-size: 14px; cursor: pointer; }
.columns-pop label:hover { background: var(--paper); }

/* ---------- Table ---------- */
.table-wrap {
  position: relative; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-md);
  overflow: auto; max-height: calc(100vh - 290px); min-height: 240px;
}
.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.grid th {
  position: sticky; top: 0; z-index: 2; background: #F8F9FB;
  text-align: left; font-weight: 600; font-size: 13px; color: var(--muted);
  padding: 0; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.grid th button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 10px 12px; cursor: pointer;
}
.grid th button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.grid th[aria-sort="ascending"] button::after { content: "▲"; font-size: 9px; }
.grid th[aria-sort="descending"] button::after { content: "▼"; font-size: 9px; }
.grid td {
  padding: 9px 12px; border-bottom: 1px solid var(--line-soft);
  vertical-align: top; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: #F7F8FC; }
.grid tbody tr.active td { background: var(--primary-soft); }
.grid tbody tr:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.grid .name-cell { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.ic { flex: none; width: 18px; height: 18px; border-radius: 3px; display: grid; place-items: center; font-size: 8px; font-weight: 700; color: #fff; background: #8A91A3; letter-spacing: -0.02em; }
.ic.folder { background: #C08A2D; border-radius: 2px 5px 3px 3px; }
.ic.docx, .ic.doc { background: #2B5797; }
.ic.xlsx, .ic.xls, .ic.csv { background: #1E7145; }
.ic.pdf { background: #B42318; }
.ic.msg, .ic.eml { background: #0F6CBD; }
.ic.pptx { background: #C43E1C; }
.grid .path { color: var(--muted); font-size: 12.5px; font-weight: 400; }

.pill {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: color-mix(in srgb, var(--hue, #8A91A3) 14%, white); color: var(--hue, #5B6378);
  white-space: nowrap;
}
.age { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.age .bar { width: 44px; height: 5px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.age .bar i { display: block; height: 100%; width: var(--pct, 0%); background: var(--ok); }
.age.warn .bar i { background: var(--amber); }
.age.late .bar i { background: var(--red); }
.age.late { color: var(--red); font-weight: 600; }
.age.warn { color: var(--amber); font-weight: 600; }
.due-late { color: var(--red); font-weight: 600; }
.due-soon { color: var(--amber); font-weight: 600; }
.muted { color: var(--muted); }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.dropzone {
  position: absolute; inset: 8px; z-index: 5; border: 2px dashed var(--primary); border-radius: var(--radius-md);
  background: rgba(230,232,244,.92); display: grid; place-items: center; font-weight: 600; color: var(--primary);
}
.footnote { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

.loading-row td { color: var(--muted); padding: 28px 14px; }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(28,34,51,.28); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(560px, 100vw); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: -18px 0 40px rgba(28,34,51,.12);
  display: flex; flex-direction: column;
  transform: translateX(102%); visibility: hidden;
  transition: transform .22s ease, visibility 0s linear .22s;
}
.drawer.open { transform: none; visibility: visible; transition: transform .22s ease; }
.drawer.wide { width: min(980px, 100vw); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 22px 10px; }
.drawer-kind { margin: 0; font-size: 13px; color: var(--muted); }
.drawer-head h2 { margin: 2px 0 0; font-size: 19px; line-height: 1.3; word-break: break-word; }
.drawer-tabs { display: flex; gap: 2px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 9px 12px; cursor: pointer; font-weight: 500; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }
.drawer-body { flex: 1; overflow: auto; padding: 18px 22px; }
.drawer-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 22px; border-top: 1px solid var(--line); background: #FAFBFC; }
.drawer-foot .spacer { flex: 1; }

.fields { display: grid; gap: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.field textarea { min-height: 96px; resize: vertical; }
.field.readonly .value { padding: 7px 0; color: var(--ink); word-break: break-word; }
.field.changed input, .field.changed select, .field.changed textarea { border-color: var(--amber); background: #FFFCF6; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.meta { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--muted); display: grid; gap: 3px; }

.children { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-md); }
.children li + li { border-top: 1px solid var(--line-soft); }
.children button { all: unset; box-sizing: border-box; display: flex; gap: 10px; align-items: center; width: 100%; padding: 10px 12px; cursor: pointer; }
.children button:hover { background: #F7F8FC; }
.children button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.children .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.preview-frame { width: 100%; height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.note { font-size: 14px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; box-shadow: 0 8px 24px rgba(28,34,51,.25); max-width: min(560px, 92vw);
}
.toast.error { background: var(--red); }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .statusbar { overflow-x: auto; }
  .seg { min-width: 108px; flex: 0 0 auto; }
  .seg .n { font-size: 24px; }
  .toolbar-actions { margin-left: 0; width: 100%; }
  .table-wrap { max-height: none; }
  .who span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer, .seg { transition: none; }
}
