:root {
  --hdi-bright: #BD0129;
  --hdi-deep: #8E011F;
  --hdi-dark: #51000C;
  --ink: #23262b;
  --mid: #6b7280;
  --line: #e2e4e8;
  --line-strong: #cfd2d8;
  --fill: #f4f5f7;
  --fill2: #fafbfc;
  --bg: #ffffff;
  --activity: #3f8f63;
  --amber: #c98a3a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 12px rgba(0,0,0,.04);
  --serif: 'Merriweather', Georgia, serif;
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--fill2); font-size: 14px; line-height: 1.5; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; }

/* ---------- buttons / chips ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); border-radius: 6px; padding: 7px 14px; font-size: 13px; font-weight: 500; text-decoration: none; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:hover { border-color: var(--mid); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--hdi-bright); border-color: var(--hdi-bright); color: #fff; }
.btn.primary:hover { background: var(--hdi-deep); border-color: var(--hdi-deep); }
.btn.ghost { background: var(--fill); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn.danger { background: var(--hdi-bright); border-color: var(--hdi-bright); color: #fff; }
.btn.danger-quiet { color: var(--hdi-bright); }
.btn.danger-quiet:hover { border-color: var(--hdi-bright); }
.btn.disabled, .btn:disabled { opacity: .45; pointer-events: none; }
.link { background: none; border: none; color: var(--hdi-bright); font-weight: 500; padding: 0; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.small { font-size: 12px; }
.icon-btn { background: none; border: none; color: var(--mid); font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.icon-btn:hover { color: var(--hdi-bright); background: var(--fill); }
.chip { display: inline-block; border: 1px solid var(--line-strong); border-radius: 10px; padding: 1px 8px; font-size: 11px; background: #fff; white-space: nowrap; }
.flex { display: flex; align-items: center; }
.flex.gap { gap: 8px; }
.flex.between, .between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--mid); }
.small { font-size: 12px; }
.center { text-align: center; }
.over { color: var(--hdi-bright); font-weight: 600; }

/* ---------- auth ---------- */
.auth-wrap { max-width: 380px; margin: 8vh auto; padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-brand img { height: 44px; width: auto; }
.brand-name { font-family: var(--serif); font-weight: 900; font-size: 20px; color: var(--hdi-deep); }
.brand-sub { color: var(--mid); font-size: 13px; }
.auth-title { font-family: var(--serif); font-size: 22px; margin-bottom: 14px; color: var(--ink); }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.auth-card input { border: 1px solid var(--line-strong); border-radius: 7px; padding: 10px 12px; outline: none; }
.auth-card input:focus { border-color: var(--hdi-bright); }
.auth-err { color: var(--hdi-bright); font-size: 13px; min-height: 1em; }
.seg-tab { flex: 1; border: 1px solid var(--line-strong); background: var(--fill); padding: 8px; font-size: 13px; font-weight: 500; color: var(--mid); }
.seg-tab:first-child { border-radius: 7px 0 0 7px; }
.seg-tab:last-child { border-radius: 0 7px 7px 0; border-left: none; }
.seg-tab.active { background: var(--hdi-bright); border-color: var(--hdi-bright); color: #fff; }

/* ---------- appbar ---------- */
.appbar { display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-logo { height: 26px; }
.brand b { font-family: var(--serif); color: var(--hdi-deep); font-size: 15px; }
.top-nav { display: flex; gap: 4px; }
.nav-item { padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--mid); text-decoration: none; }
.nav-item:hover { background: var(--fill); color: var(--ink); }
.nav-item.active { color: var(--hdi-bright); background: var(--fill); }
.nav-item.disabled { opacity: .4; cursor: default; }
.appbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.sync-status { font-size: 12px; color: var(--mid); }
.sync-status.offline { color: var(--amber); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- view / page ---------- */
.view { max-width: 1120px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title { font-family: var(--serif); font-size: 24px; color: var(--ink); }
.back-link { color: var(--mid); font-size: 13px; text-decoration: none; font-weight: 500; }
.back-link:hover { color: var(--hdi-bright); }
.empty { color: var(--mid); background: #fff; border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 40px; text-align: center; }

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-title { font-family: var(--serif); font-size: 16px; margin-bottom: 8px; }
.card-meta { font-size: 12.5px; color: var(--mid); line-height: 1.8; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- planner layout ---------- */
.planner-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
.planner-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* DEFINE */
.define, .sheet, .sources { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.block-head { background: var(--hdi-deep); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .1em; padding: 6px 14px; }
.def-grid { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.def-field { display: flex; flex-direction: column; gap: 4px; }
.def-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mid); font-weight: 600; }
.def-input { border: 1px solid var(--line-strong); border-radius: 6px; padding: 8px 10px; outline: none; width: 100%; background: #fff; }
.def-input:focus { border-color: var(--hdi-bright); }
.def-input.narrow { width: auto; }
.def-row { display: flex; gap: 16px; flex-wrap: wrap; }
.def-row .def-field { flex: 0 0 auto; }
textarea.def-input, textarea.detail-area { resize: vertical; }

/* sources */
.sources summary { padding: 10px 14px; font-size: 13px; font-weight: 500; cursor: pointer; }
.sources-body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.src-row { display: flex; gap: 8px; align-items: center; }
.src-input { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 9px; outline: none; }
.src-input:focus { border-color: var(--hdi-bright); }
.src-open { color: var(--hdi-bright); text-decoration: none; padding: 0 4px; }

/* run-sheet */
.sheet-head, .prow { display: grid; grid-template-columns: 28px 1fr 84px 190px 34px; gap: 10px; align-items: center; }
.sheet-head { background: var(--fill); padding: 8px 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--mid); }
.prow-wrap { border-top: 1px solid var(--line); }
.prow { padding: 8px 12px; }
.prow.section { background: #eef2ee; border-top: 1px solid var(--line); }
.prow.section .sec-title { font-family: var(--serif); font-weight: 700; font-size: 14px; }
.prow.dragging { opacity: .4; }
.prow.drag-over, .end-dropzone.drag-over { box-shadow: inset 0 2px 0 var(--hdi-bright); }
.drag { color: var(--line-strong); cursor: grab; font-size: 15px; user-select: none; text-align: center; }
.drag:active { cursor: grabbing; }
.sec-num { color: var(--hdi-bright); font-weight: 700; font-family: var(--serif); }
.col-topic { min-width: 0; }
.col-topic.flex { display: flex; align-items: center; gap: 8px; }
.item-titlerow { display: flex; }
.item-title, .sec-title { width: 100%; border: none; border-bottom: 1px solid transparent; padding: 3px 2px; outline: none; background: none; font-size: 14px; }
.item-title:focus, .sec-title:focus { border-bottom-color: var(--hdi-bright); }
.item-sub { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--mid); margin-top: 2px; }
.clock { font-variant-numeric: tabular-nums; }
.detail-toggle { background: none; border: none; color: var(--mid); font-size: 11.5px; padding: 0; }
.detail-toggle:hover, .detail-toggle.open { color: var(--hdi-bright); }
.slide-badge.muted { opacity: .6; }
.bank-tag { color: var(--amber); }
.dur-input { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 6px; text-align: right; outline: none; font-variant-numeric: tabular-nums; }
.dur-input:focus { border-color: var(--hdi-bright); }
.type-select { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 6px; outline: none; background: #fff; font-size: 12px; }
.col-time { text-align: right; }
.col-end { text-align: center; }
.end-dropzone { height: 14px; }
.sheet-toolbar { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.totals { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--fill); border-top: 1px solid var(--line); font-size: 13px; }
.total-delta.ok { color: var(--activity); }
.total-delta.over { color: var(--hdi-bright); }

/* item detail */
.item-detail { padding: 4px 12px 14px 50px; background: var(--fill2); display: flex; flex-direction: column; gap: 10px; }
.detail-field { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mid); font-weight: 600; }
.detail-input, .detail-area { border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 9px; outline: none; width: 100%; background: #fff; }
.detail-input:focus, .detail-area:focus { border-color: var(--hdi-bright); }
.detail-input.narrow { width: 120px; }
.detail-row { display: flex; gap: 12px; flex-wrap: wrap; }
.detail-sources { display: flex; flex-wrap: wrap; gap: 12px; }
.src-check { display: flex; align-items: center; gap: 5px; font-size: 12px; }
.detail-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* idea sidebar */
.idea-side { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.side-head h4 { font-size: 13px; }
.bank-search { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; outline: none; margin-bottom: 10px; }
.bank-search:focus { border-color: var(--hdi-bright); }
.bank-search.wide { max-width: 320px; margin: 0; }
.bank-list { display: flex; flex-direction: column; gap: 8px; }
.bank-item { border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.bank-item-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 3px; }
.bank-item-head b { font-size: 12.5px; }
.bank-item-meta { margin-bottom: 6px; }

/* bank full view */
.bank-controls { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.bank-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip { border: 1px solid var(--line-strong); background: #fff; border-radius: 12px; padding: 3px 10px; font-size: 12px; color: var(--mid); }
.filter-chip.active { background: var(--hdi-bright); border-color: var(--hdi-bright); color: #fff; }
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.bank-desc { font-size: 13px; color: var(--ink); margin: 8px 0; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: var(--fill); border-radius: 4px; padding: 1px 7px; font-size: 11px; color: var(--mid); }

/* type manager */
.type-manager { display: flex; flex-direction: column; gap: 8px; }
.type-row { display: flex; align-items: center; gap: 8px; }
.type-swatch { width: 16px; height: 16px; border-radius: 4px; flex: none; border: 1px solid var(--line-strong); }
.type-row input[type=color] { width: 32px; height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; background: none; padding: 2px; }

/* modal / toast */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,20,25,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 480px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.modal-head h3 { font-family: var(--serif); font-size: 17px; }
.modal-body { padding: 16px 18px; }
.modal-body .form { display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; z-index: 200; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .planner-layout { grid-template-columns: 1fr; }
  .idea-side { position: static; max-height: none; }
  .sheet-head, .prow { grid-template-columns: 24px 1fr 70px 140px 30px; gap: 6px; }
}
