:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1c2430;
  --muted: #6b7480;
  --accent: #c87868;        /* NSC rose — sampled from the clinic's lotus logo */
  --accent-hover: #b1604f;
  --accent-weak: #f8ece7;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;

  --st-new: #6366f1;
  --st-tier1: #0ea5e9;
  --st-tier2: #8b5cf6;
  --st-waitclient: #f59e0b;
  --st-waitint: #eab308;
  --st-closed: #16a34a;

  --pr-high: #dc2626;
  --pr-medium: #d97706;
  --pr-low: #64748b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --panel: #171b22; --panel-2: #1d222b; --border: #2a313c;
    --text: #e6e9ee; --muted: #9aa4b2; --accent: #4f8cff; --accent-weak: #1a2740;
    --shadow: none; --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { height: 34px; width: auto; display: block; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.sub { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.me { color: var(--muted); font-size: 12px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; cursor: pointer; font-size: 13px; }
.seg button.active { background: var(--accent); color: #fff; }

.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: #dc2626; border-color: #f0c4c4; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- filters ---- */
.filters {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.filters input[type="search"] {
  flex: 1; min-width: 220px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 13px;
}
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
  padding: 5px 11px; border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 500;
}
.chip.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }

/* ---- board ---- */
main { flex: 1; padding: 16px 20px; overflow: auto; }
.board { display: flex; gap: 14px; align-items: flex-start; min-height: 100%; }
.col {
  flex: 0 0 288px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px);
}
.col-head {
  display: flex; align-items: center; gap: 8px; padding: 11px 13px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  border-top: 3px solid var(--col); border-radius: var(--radius) var(--radius) 0 0; background: var(--panel-2);
}
.col-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--col); }
.col-head .name { font-weight: 600; font-size: 13px; }
.col-head .n { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 600; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
.collapse-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 5px; margin-left: 4px; border-radius: 5px; }
.collapse-btn:hover { background: var(--border); color: var(--text); }

/* Collapsed column — narrow rail with count + vertical label; still a drop target. */
.col.collapsed { flex: 0 0 46px; cursor: pointer; align-self: stretch; max-height: calc(100vh - 190px); }
.col.collapsed:hover { border-color: var(--accent); }
.col-collapsed-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0; border-top: 3px solid var(--col); border-radius: var(--radius) var(--radius) 0 0; height: 100%; }
.col.collapsed .chev { color: var(--muted); font-size: 13px; }
.col.collapsed .n { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.col.collapsed .vlabel { writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; margin-top: 2px; }
.col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 12px; cursor: grab; box-shadow: var(--shadow); border-left: 3px solid var(--pr);
}
.card:hover { border-color: var(--accent); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: .4; }
.col.drop-target { box-shadow: inset 0 0 0 2px var(--accent); }
.col.drop-target .col-body { background: var(--accent-weak); border-radius: 0 0 var(--radius) var(--radius); }
.card .tnum { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.card .title { font-weight: 600; margin: 3px 0 7px; font-size: 13.5px; }
.card .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card .client { color: var(--muted); font-size: 12px; margin-top: 7px; display: flex; align-items: center; gap: 5px; }
.owner-avatar {
  margin-left: auto; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.picked { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); font-size: 13px; }
.picked .picked-name { font-weight: 600; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge.pr-high { color: var(--pr-high); background: #fde8e8; }
.badge.pr-medium { color: var(--pr-medium); background: #fdf0dd; }
.badge.pr-low { color: var(--pr-low); background: #eef1f5; }
.badge.brand { color: var(--muted); background: var(--panel-2); border-color: var(--border); }
@media (prefers-color-scheme: dark){ :root:not([data-theme="light"]) .badge.pr-high{background:#3a1a1a} :root:not([data-theme="light"]) .badge.pr-medium{background:#3a2c14} :root:not([data-theme="light"]) .badge.pr-low{background:#232833} }

.empty-col { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 8px; }

/* ---- table ---- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; background: var(--panel-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
.status-pill { font-size: 11px; padding: 2px 9px; border-radius: 999px; color: #fff; font-weight: 600; background: var(--col); }

/* ---- drawer ---- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10,15,22,.4); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 100vw);
  background: var(--panel); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  z-index: 50; display: flex; flex-direction: column; animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer header { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer header .tnum { font-size: 12px; color: var(--muted); font-weight: 600; }
.drawer header h2 { margin: 3px 0 0; font-size: 17px; }
.drawer header .x { margin-left: auto; }
.drawer .body { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.field select, .field input, .field textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font-size: 13px; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 64px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.card-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 13px; background: var(--panel-2); }
.card-box h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.contact-line { display: flex; align-items: center; gap: 8px; }
.contact-line .nm { font-weight: 600; }
.contact-line a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.desc { white-space: pre-wrap; font-size: 13px; }

.note { border-top: 1px solid var(--border); padding: 9px 0; font-size: 13px; white-space: pre-wrap; }
.note:first-child { border-top: 0; }
.note .when { color: var(--muted); font-size: 11px; margin-top: 3px; }
.notes-list { max-height: 260px; overflow-y: auto; }

.search-results { border: 1px solid var(--border); border-radius: 8px; margin-top: 6px; overflow: hidden; }
.search-results div { padding: 8px 10px; cursor: pointer; border-top: 1px solid var(--border); font-size: 13px; }
.search-results div:first-child { border-top: 0; }
.search-results div:hover { background: var(--accent-weak); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.actions-row { display: flex; gap: 8px; justify-content: flex-end; }
.stamps { display: flex; gap: 8px; color: var(--muted); font-size: 12px; padding: 2px 2px 8px; }

/* ---- toast + misc ---- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1c2430; color: #fff; padding: 11px 18px; border-radius: 9px;
  z-index: 100; box-shadow: var(--shadow-lg); font-size: 13px; max-width: 90vw;
}
.toast.error { background: #b91c1c; }
.loading, .error-state { padding: 60px 20px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
