:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5d6677;
  --line: #e3e6ec;
  --accent: #1f4e8c;
  --accent-soft: #e8eef8;
  --accent-ink: #1a4377;
  --row-hover: #f3f6fb;
  --row-sel: #dfe8f7;
  --ok: #1f8a3e;
  --bad: #c9302c;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 17px; color: var(--accent); letter-spacing: .1px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tab { padding: 6px 14px; border-radius: 6px; color: var(--muted); }
.tab.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.data-through { margin: 0 0 0 auto; font-size: 12px; color: var(--muted); }

/* ── Layout (master / detail) ────────────────────────── */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}
.layout.has-detail { grid-template-columns: minmax(0, 1.45fr) minmax(380px, 1fr); }

.master {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Filters ─────────────────────────────────────────── */
.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: span 2; }
.field.check { justify-content: flex-end; gap: 6px; }
.field > label, .field > .label { font-size: 12px; font-weight: 600; color: var(--ink); }
input[type="search"], input[type="date"] {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus-visible, button:focus-visible, .ms-button:focus-visible, tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.daterange { display: flex; align-items: center; gap: 6px; }
.daterange input { min-width: 0; padding: 0 6px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }
.link-btn { align-self: flex-start; border: 0; background: none; color: var(--accent); padding: 0; font: inherit; font-size: 12px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* multiselect */
.ms { position: relative; }
.ms-button {
  width: 100%;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.ms-button .ms-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-button .ms-text.placeholder { color: #8a92a2; }
.ms-button::after { content: "▾"; color: var(--muted); font-size: 11px; }
.ms-pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  width: max(100%, 280px);
  max-height: 340px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 30, 50, .14);
}
.ms-pop input[type="search"] { border: 0; border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.ms-list { overflow: auto; padding: 4px 0; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 5px 10px; cursor: pointer; font-size: 13px; }
.ms-opt:hover { background: var(--row-hover); }
.ms-opt input { accent-color: var(--accent); }
.ms-opt .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.ms-empty { padding: 10px; color: var(--muted); font-size: 13px; }
.ms-foot { display: flex; justify-content: space-between; padding: 6px 10px; border-top: 1px solid var(--line); }

/* ── Toolbar / pager ─────────────────────────────────── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.count { margin: 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.toolbar-actions { display: flex; align-items: center; gap: 12px; }
.pager { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn { height: 30px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--row-hover); }
.btn:disabled { opacity: .45; cursor: default; }
.error { margin: 10px 16px 0; padding: 10px 12px; border-radius: 6px; background: #fdecea; color: #8a1f1b; font-size: 13px; }

/* ── Table ───────────────────────────────────────────── */
.table-wrap { flex: 1; min-height: 0; overflow: auto; }
.grid { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafbfc;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.grid th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; color: var(--accent); }
.grid th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; color: var(--accent); }
.grid td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid tbody tr[aria-selected="true"] { background: var(--row-sel); }
.c-date { width: 86px; } .c-item { width: 78px; } .c-file { width: 82px; }
.c-type { width: 13%; } .c-dept { width: 11%; } .c-owner { width: 11%; }
.c-title { width: 26%; } .c-task { width: 22%; }
.muted { color: var(--muted); }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; white-space: normal; }

.flag { display: inline-block; width: 15px; height: 15px; margin-left: 6px; vertical-align: -3px; }
.flag.pass { fill: var(--ok); } .flag.fail { fill: var(--bad); }

.tag {
  display: inline-block;
  max-width: 100%;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Detail panel ────────────────────────────────────── */
.detail {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px 28px;
}
.close { position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; border-radius: 6px; }
.close:hover { background: var(--row-hover); color: var(--ink); }
.d-head { margin: 26px 0 6px; padding: 8px 12px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; text-align: center; }
.d-link { display: block; text-align: center; margin-bottom: 8px; font-size: 13px; }
a { color: var(--accent); }
.d-sec { padding: 12px 0; border-bottom: 1px solid var(--line); }
.d-sec:last-child { border-bottom: 0; }
.d-sec h2 { margin: 0 0 8px; font-size: 14px; color: var(--accent-ink); display: flex; align-items: center; gap: 8px; }
.d-sec h2 .flag { margin-left: auto; width: 18px; height: 18px; }
.d-text { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.d-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.d-meta b { color: var(--ink); font-weight: 600; }
.loading-line { color: var(--muted); font-size: 13px; }

.votes { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.vote { display: flex; align-items: center; gap: 7px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; }
.vote svg { width: 16px; height: 16px; flex: none; }
.vote.aye svg { fill: var(--ok); } .vote.nay svg { fill: var(--bad); } .vote.other svg { fill: #98a0ad; }
.vote small { display: block; color: var(--muted); }

.task-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.task-card h3 { margin: 0 0 4px; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ob { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.ob.recurring { background: #e6f4ea; color: #1d6b35; }
.ob.ongoing { background: #fff4e0; color: #8a5300; }
.ob.one_time { background: #eef1f6; color: #3e4a5e; }

.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.mini td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.mini td:first-child { white-space: nowrap; }
.mini button.link-btn { font-size: 13px; }
.attach { margin: 0; padding-left: 18px; }
.attach li { margin: 3px 0; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1280px) {
  .filters { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
  .layout.has-detail { grid-template-columns: minmax(0, 1fr) minmax(360px, 42%); }
  .c-task { display: none; }
}
@media (max-width: 900px) {
  .filters { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .field.wide { grid-column: span 2; }
  .c-dept, .c-title { display: none; }
  .layout.has-detail { grid-template-columns: minmax(0, 1fr); }
  .layout.has-detail .detail { position: fixed; inset: 0; z-index: 50; border-radius: 0; }
}
