:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e5e7eb;
  --line-2: #eef0f3;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #e6f4f2;
  --side: #0f1b24;
  --side-text: #c9d3da;
  --side-muted: #7f8f9b;
  --good: #047857; --good-bg: #e7f6ef;
  --info: #1d4ed8; --info-bg: #e8effd;
  --warn: #b45309; --warn-bg: #fdf3e2;
  --bad: #b91c1c;  --bad-bg: #fdecec;
  --neutral: #4b5563; --neutral-bg: #f0f1f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 45px rgba(16, 24, 40, .18);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); border-color: #d1d5db; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger.confirm { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 6px 9px; }
.btn.block { width: 100%; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #134e4a 0, var(--side) 55%); }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 14px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-lg); }
.login-card p { margin: 0; }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex: 0 0 232px; background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; color: #fff; padding: 2px 6px; }
.brand b { color: #5eead4; font-weight: 700; }
.brand-lg { color: var(--text); font-size: 20px; }
.brand-lg b { color: var(--accent); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.search-wrap { position: relative; }
.search-wrap input { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.1); color: #fff; }
.search-wrap input::placeholder { color: var(--side-muted); }
.search-results { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; background: #fff;
  border-radius: 8px; box-shadow: var(--shadow-lg); overflow: hidden; max-height: 340px; overflow-y: auto; }
.search-results a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; color: var(--text); }
.search-results a:hover, .search-results a.active { background: var(--accent-soft); text-decoration: none; }
.search-results .empty { padding: 10px; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted);
  padding: 12px 8px 4px; }
nav a { color: var(--side-text); padding: 7px 8px; border-radius: 7px; display: flex; gap: 10px; align-items: center; }
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
nav a.active { background: rgba(94, 234, 212, .12); color: #fff; }
nav a.active i { color: #5eead4; opacity: 1; }
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.sidebar-foot .btn { color: var(--side-text); }
.sidebar-foot .btn:hover { background: rgba(255,255,255,.08); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 24px; border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 10; }
#menu-toggle { display: none; }
.crumbs { color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs span:last-child { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 24px; max-width: 1440px; width: 100%; }

/* ---------- page structure ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; color: var(--muted); max-width: 760px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.card-body { padding: 14px 16px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main-side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 10px; }
.empty-state { padding: 22px 16px; text-align: center; color: var(--muted); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  color: var(--text); display: block; }
.kpi:hover { border-color: #c7ccd3; text-decoration: none; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--neutral-bg); color: var(--neutral); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--neutral-bg); color: var(--text-2); font-size: 12px; }

/* tables */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; max-width: 190px; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 12px; background: var(--panel-2);
  border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #fafbfc; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; }
.overdue { color: var(--bad); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }

/* field display */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 20px; }
.field .k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field .v { white-space: pre-wrap; word-break: break-word; }
.field.wide { grid-column: 1 / -1; }
.prose-block { padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; white-space: pre-wrap; }
.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 12px 14px; border-radius: 0 8px 8px 0; }

/* list rows */
.rows > * { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; padding: 11px 16px; border-bottom: 1px solid var(--line-2); color: var(--text); }
.rows > *:last-child { border-bottom: 0; }
.rows > a:hover { background: #fafbfc; text-decoration: none; }
.rows .main { min-width: 0; flex: 1; }
.rows .title { font-weight: 550; }
.rows .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* thesis & campaign cards */
.tile { display: flex; flex-direction: column; gap: 10px; padding: 16px; color: var(--text); }
.tile:hover { border-color: #c7ccd3; text-decoration: none; }
.tile .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.tile .desc { color: var(--text-2); }
.tile .foot { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--line-2); }
.tile .foot b { color: var(--text); }

/* bars */
.bar-row { display: grid; grid-template-columns: 140px 1fr 30px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bar-track { display: block; height: 8px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.score { display: inline-flex; align-items: center; gap: 8px; }
.score .bar-track { display: inline-block; width: 60px; }
.score b { min-width: 24px; }
.dots { display: inline-flex; gap: 3px; }
.dots span { width: 9px; height: 9px; border-radius: 2px; background: var(--line); }
.dots span.on { background: var(--accent); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; font: inherit; padding: 9px 14px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 550; }
.tabs .count { font-size: 11px; background: var(--neutral-bg); padding: 1px 6px; border-radius: 999px; margin-left: 4px; }

/* kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 250px; background: #eef0f3; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 200px); }
.col-head { padding: 10px 12px; display: flex; justify-content: space-between; font-weight: 600; font-size: 13px; }
.col-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; }
.col.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: var(--shadow); }
.kcard:active { cursor: grabbing; }
.kcard .t { font-weight: 600; }
.kcard .m { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kcard .n { font-size: 12px; margin-top: 8px; color: var(--text-2); }
.kcard.dragging { opacity: .4; }

/* waves */
.wave { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.wave dl { margin: 0; display: grid; gap: 8px; }
.wave dt { font-size: 12px; color: var(--muted); }
.wave dd { margin: 0; }

/* timeline */
.timeline > div { position: relative; padding: 0 0 16px 20px; }
.timeline > div::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline > div::after { content: ""; position: absolute; left: 7.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline > div:last-child::after { display: none; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { background: #fff; width: min(720px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.req { color: var(--bad); }

/* toasts */
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); align-items: center; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; animation: slide .16s; }
.toast.error { background: var(--bad); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 40; left: 0; transform: translateX(-100%); transition: transform .18s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  #menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  main { padding: 16px; }
  .cols-2, .cols-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .bar-row { grid-template-columns: 110px 1fr 26px; }
}
