:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --line: #ececf4;
  --text: #1b1d3a;
  --muted: #8d90ad;
  --accent: #6c5dd3;
  --accent-soft: #efedfc;
  --accent-text: #ffffff;
  --green: #2fb984;
  --green-soft: #e3f7ef;
  --red: #ef5b6b;
  --red-soft: #fdeaec;
  --orange: #ff9f43;
  --orange-soft: #fff2e4;
  --blue: #3e8bff;
  --blue-soft: #e7f0ff;
  --pink: #e957b9;
  --pink-soft: #fce8f6;
  --shadow: 0 10px 30px rgba(39, 43, 90, 0.06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131f;
    --surface: #1b1d2e;
    --surface-2: #22253a;
    --line: #2b2e46;
    --text: #eceefe;
    --muted: #8d91b3;
    --accent: #8a7cf0;
    --accent-soft: #2b2850;
    --green-soft: #173a31;
    --red-soft: #432129;
    --orange-soft: #43301c;
    --blue-soft: #1c2d4b;
    --pink-soft: #3d1f37;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12131f;
  --surface: #1b1d2e;
  --surface-2: #22253a;
  --line: #2b2e46;
  --text: #eceefe;
  --muted: #8d91b3;
  --accent: #8a7cf0;
  --accent-soft: #2b2850;
  --green-soft: #173a31;
  --red-soft: #432129;
  --orange-soft: #43301c;
  --blue-soft: #1c2d4b;
  --pink-soft: #3d1f37;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--red); margin: 0; font-size: 13px; }
.pad { padding: 0 4px 12px; margin: 0; }

/* Buttons */
.btn {
  border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 500;
  background: var(--surface-2); transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 18px rgba(108, 93, 211, .28); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 500; padding: 0; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; font-size: 16px;
}
.icon-btn:hover { background: var(--red-soft); color: var(--red); }
.icon-btn.restore:hover { background: var(--green-soft); color: var(--green); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border-radius: 24px; padding: 32px;
  box-shadow: var(--shadow); display: grid; gap: 16px;
}
.login-card .muted { margin: -8px 0 0; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 11px 14px; color: var(--text);
}
.field input:focus, .search input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* Shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line); padding: 28px 18px;
  display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px; }
.brand-lg { font-size: 20px; padding: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--pink)); font-size: 16px;
}
.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; border: 0; background: transparent; color: var(--muted);
  padding: 11px 14px; border-radius: 12px; text-align: left; font-weight: 500;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; }
.side-card {
  margin-top: auto; background: var(--surface-2); border-radius: 16px; padding: 16px; display: grid; gap: 8px; font-size: 13px;
}
.side-row { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }

.main { padding: 28px 32px 40px; display: grid; gap: 24px; align-content: start; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar p { margin: 2px 0 0; }
.topbar-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 12px; padding: 0 14px;
  box-shadow: var(--shadow); color: var(--muted);
}
.search input { border: 0; background: transparent; padding: 10px 0; width: 220px; outline: none; color: var(--text); }

/* Cards */
.view { display: grid; gap: 24px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head.wrap { flex-wrap: wrap; }
.split { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 24px; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.stat { display: flex; align-items: center; gap: 16px; }
.stat-icon {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 22px; flex: none;
}
.stat-value { font-size: 24px; font-weight: 600; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 13px; }
.tone-accent { background: var(--accent-soft); color: var(--accent); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-orange { background: var(--orange-soft); color: var(--orange); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-pink { background: var(--pink-soft); color: var(--pink); }
.tone-red { background: var(--red-soft); color: var(--red); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head .tabs { margin: 0; }
.tab, .segmented button {
  border: 0; background: transparent; color: var(--muted); border-radius: 10px; padding: 7px 12px; font-weight: 500; font-size: 13px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab .count { opacity: .7; margin-left: 4px; }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Market rows */
.list { display: grid; }
.row {
  display: grid; grid-template-columns: 44px minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 1.6fr) auto auto;
  align-items: center; gap: 14px; padding: 12px 4px; border-top: 1px solid var(--line);
}
.list .row:first-child { border-top: 0; }
.row.compact { grid-template-columns: 44px minmax(0, 2fr) minmax(0, 1fr) auto; }
.avatar {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-weight: 600; font-size: 11px;
  letter-spacing: .02em;
}
.name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border-radius: 8px; padding: 3px 9px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.plain { background: var(--surface-2); color: var(--muted); }
.read { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: 13px; }
.read a, .read span.title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.read .muted { white-space: nowrap; flex: none; }
.read-lines { display: grid; gap: 2px; min-width: 0; }
.read-line { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.read-line > span { white-space: nowrap; flex: none; }
.read-line.sub, .read-line.sub a { font-size: 12px; color: var(--muted); }
.read-line.sub a:hover { color: var(--accent); }
.empty { color: var(--muted); padding: 28px 4px; text-align: center; }

/* Switch */
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .15s; pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: transform .15s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; }
.event { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.timeline .event:first-child { border-top: 0; }
.event-icon { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 17px; }
.event-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.event-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.event-meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; flex-wrap: wrap; }
.event-body {
  margin-top: 8px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; font-size: 13px;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto;
}
.timeline:not(.timeline-full) .event-body { display: none; }
.timeline:not(.timeline-full) .event.open .event-body { display: block; }
.timeline:not(.timeline-full) .event { cursor: pointer; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(18, 19, 40, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card {
  width: min(480px, 100%); background: var(--surface); border-radius: 22px; padding: 26px; display: grid; gap: 14px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .25);
}
.modal-card p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 12px 20px; border-radius: 14px; box-shadow: var(--shadow); z-index: 30; max-width: calc(100% - 32px);
}

@media (max-width: 1200px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px 16px;
  }
  .nav { display: flex; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .nav-item { padding: 8px 12px; white-space: nowrap; }
  .side-card { margin: 0 0 0 auto; padding: 8px 12px; display: flex; gap: 12px; }
  .side-card .side-row.muted { display: none; }
  .main { padding: 20px 16px 32px; }
  .search input { width: 100%; }
  .topbar-actions, .search { flex: 1 1 100%; }
  .row { grid-template-columns: 44px minmax(0, 1fr) auto auto; }
  .row .cell-pills, .row .cell-read { display: none; }
  .row.compact { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .row.compact .cell-pills { display: none; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
}
