:root {
  --bg: #0f1115;
  --bg-elev: #181b22;
  --bg-elev2: #20242e;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-dim: #9aa1ad;
  --text-faint: #6b7280;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 50px;
}

/* ---- Light theme ---- */
[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-elev2: #eef1f6;
  --border: #e3e7ee;
  --text: #1b1f27;
  --text-dim: #586172;
  --text-faint: #8b93a3;
}
[data-theme="light"] body { background: var(--bg); }
[data-theme="light"] .topbar,
[data-theme="light"] .tabbar { box-shadow: 0 1px 0 rgba(16,24,40,.04); }
[data-theme="light"] .role-card,
[data-theme="light"] .card,
[data-theme="light"] .role-hero { box-shadow: 0 1px 3px rgba(16,24,40,.06); }
[data-theme="light"] .pill.todo { background: #eaedf2; color: #475569; }
[data-theme="light"] .pill.scheduled { background: #fdeccd; color: #b07314; }
[data-theme="light"] .pill.done { background: #d8f5e1; color: #15803d; }
[data-theme="light"] .tag.accent { background: #e9eaff; color: #4f46e5; }
[data-theme="light"] .md a { color: #4f46e5; }
[data-theme="light"] .md h1, [data-theme="light"] .md h2 { border-bottom-color: var(--border); }
[data-theme="light"] .toast { box-shadow: 0 6px 20px rgba(16,24,40,.18); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { overflow: hidden; }
button { font-family: inherit; cursor: pointer; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Topbar */
.topbar {
  flex: 0 0 auto;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; font-weight: 700; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.sync-status { font-size: 12px; color: var(--text-faint); transition: color .3s; }
.sync-status.ok { color: var(--green); }
.sync-status.syncing { color: var(--amber); }
.sync-status.err { color: var(--red); }
.sync-status.off { color: var(--text-faint); }
.icon-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 23px; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--bg-elev2); }

/* Main */
#main { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 80px); }

/* Cards */
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 10px;
}
.card:active { background: var(--bg-elev2); }
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.card-meta { font-size: 12px; color: var(--text-faint); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card-snippet { font-size: 13px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; max-height: 3em; overflow: hidden; }

.tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-elev2); color: var(--text-dim); border: 1px solid var(--border);
}
.tag.accent { background: rgba(99,102,241,.15); color: #a5b4fc; border-color: transparent; }

/* Status pills */
.pill { font-size: 11px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.pill.todo { background: rgba(107,114,128,.2); color: #cbd5e1; }
.pill.scheduled { background: rgba(245,158,11,.18); color: #fbbf24; }
.pill.done { background: rgba(34,197,94,.18); color: #4ade80; }

/* Section headers */
.section-head { font-size: 13px; font-weight: 700; color: var(--text-dim); margin: 18px 2px 8px; text-transform: uppercase; letter-spacing: .04em; }
.section-head:first-child { margin-top: 4px; }

/* Search */
.search-wrap { position: sticky; top: 0; z-index: 5; padding-bottom: 10px; background: var(--bg); }
.search {
  width: 100%; padding: 11px 14px; font-size: 15px; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.search:focus { border-color: var(--accent); }

/* Empty state */
.empty { text-align: center; color: var(--text-faint); padding: 60px 24px; }
.empty .big { font-size: 44px; margin-bottom: 12px; }
.empty p { font-size: 14px; line-height: 1.6; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 6px 20px rgba(99,102,241,.45);
  z-index: 20;
}
.fab:active { transform: scale(.94); }
.fab.hidden { display: none; }

/* Tabbar */
.tabbar {
  flex: 0 0 auto; display: flex; background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom); height: calc(var(--tabbar-h) + var(--safe-bottom));
}
.tab {
  flex: 1; background: none; border: none; color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  padding: 5px 0; font-size: 10px;
}
.tab .tab-ico { font-size: 18px; filter: grayscale(1) opacity(.55); line-height: 1; }
.tab .tab-img { width: 22px; height: 22px; object-fit: contain; display: block; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .25s ease;
}
.modal.hidden { transform: translateX(100%); pointer-events: none; }
.modal-bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px; background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.modal-bar > span { font-size: 16px; font-weight: 600; flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px calc(var(--safe-bottom) + 40px); }
.text-btn { background: none; border: none; color: var(--text-dim); font-size: 16px; padding: 6px 8px; white-space: nowrap; }
.text-btn.primary { color: var(--accent); font-weight: 600; }
.text-btn.hidden { display: none; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%; padding: 11px 12px; font-size: 15px; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; outline: none;
  font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.field textarea.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; min-height: 320px; }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; line-height: 1.5; }
.row2 { display: flex; gap: 10px; }
.row2 > .field { flex: 1; }

.btn {
  display: block; width: 100%; padding: 13px; border-radius: 12px; border: none;
  font-size: 15px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); margin-top: 8px;
}
.btn:active { opacity: .85; }
.btn.secondary { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: none; color: var(--red); border: 1px solid rgba(239,68,68,.4); }

/* Rendered markdown */
.md { font-size: 15.5px; line-height: 1.72; color: var(--text); word-wrap: break-word; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1.4em 0 .6em; font-weight: 700; }
.md h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.md h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: .25em; }
.md h3 { font-size: 1.12em; }
.md p { margin: .7em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: .6em 0; }
.md li { margin: .3em 0; }
.md a { color: #a5b4fc; }
.md code { background: var(--bg-elev2); padding: .15em .4em; border-radius: 5px; font-size: .88em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.md pre { background: var(--bg-elev); border: 1px solid var(--border); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); margin: .8em 0; padding: .2em 0 .2em 14px; color: var(--text-dim); }
.md table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; margin: .8em 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.md th { background: var(--bg-elev); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md img { max-width: 100%; border-radius: 8px; }

.detail-block { margin-bottom: 18px; }
.detail-block .lbl { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; font-weight: 700; }
.detail-block .val { font-size: 15px; line-height: 1.6; white-space: pre-wrap; }
.detail-block .val.empty-val { color: var(--text-faint); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 30px);
  transform: translateX(-50%); z-index: 100;
  background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
  transition: opacity .2s, transform .2s; max-width: 86%;
}
.toast.hidden { opacity: 0; transform: translate(-50%, 12px); pointer-events: none; }

.banner {
  background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35); color: #fbbf24;
  padding: 12px 14px; border-radius: 12px; font-size: 13px; line-height: 1.55; margin-bottom: 14px;
}
.banner a { color: #fcd34d; }

/* Card row (title + pill on one line) */
.card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-row .card-title { margin: 0; }
.date-chip { color: var(--text-dim); }
.date-chip.muted { color: var(--text-faint); }

/* ---- Home: single-column list of role cards (uniform & minimal) ---- */
.rolelist { display: flex; flex-direction: column; gap: 12px; }
.role-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 18px 18px 22px; position: relative; overflow: hidden;
}
.role-card:active { background: var(--bg-elev2); }
.role-card .rc-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--rc); }
.rc-company { font-size: 13px; font-weight: 700; color: var(--rc); letter-spacing: .02em; }
.rc-title { font-size: 17px; font-weight: 600; line-height: 1.4; margin: 6px 0 16px; }
.rc-progrow { display: flex; align-items: center; gap: 12px; }
.rc-progbar { flex: 1; height: 6px; border-radius: 999px; background: var(--bg-elev2); overflow: hidden; }
.rc-progbar i { display: block; height: 100%; background: var(--rc); border-radius: 999px; }
.rc-proglabel { font-size: 12px; color: var(--text-dim); white-space: nowrap; flex: 0 0 auto; }

/* ---- Role detail ---- */
.back-link { background: none; border: none; color: var(--text-dim); font-size: 15px; padding: 2px 0 10px; }
.role-hero {
  background: var(--bg-elev); border: 1px solid var(--border); border-left: 4px solid var(--rc);
  border-radius: 14px; padding: 14px; margin-bottom: 14px;
}
.rh-title { font-size: 17px; font-weight: 700; line-height: 1.35; }
.rh-meta { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.rh-note { font-size: 12.5px; color: var(--text-dim); line-height: 1.55; margin-top: 8px; }
.rh-actions { display: flex; gap: 10px; margin-top: 12px; }
.rh-link {
  font-size: 13px; color: var(--accent); background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; text-decoration: none; display: inline-block;
}

/* Segmented control */
.segment { display: flex; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 14px; position: sticky; top: 0; z-index: 5; }
.seg { flex: 1; background: none; border: none; color: var(--text-dim); font-size: 14px; font-weight: 600; padding: 9px 0; border-radius: 9px; }
.seg.active { background: var(--accent); color: #fff; }

/* Color swatches */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.sw { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--bg); }
