/* =========================================================================
   YieldPilot — styles adapted from TemplateMo 609 "Crypto Vault"
   (https://templatemo.com/tm-609-crypto-vault) graphite & copper theme.
   ========================================================================= */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root, [data-theme="dark"] {
  --bg-primary: #1c1c1e; --bg-secondary: #232325; --bg-card: #2c2c2e; --bg-card-hover: #343436;
  --accent: #b87333; --accent-light: #c9845a;
  --accent-gradient: linear-gradient(135deg, #b87333 0%, #d4945a 50%, #c9845a 100%);
  --accent-gradient-hover: linear-gradient(135deg, #c9845a 0%, #daa57a 50%, #d4945a 100%);
  --accent-soft: rgba(184, 115, 51, 0.15);
  --text-primary: #f5f0e8; --text-secondary: #a8a8a8; --text-muted: #7a7a7a;
  --gain: #7fa37f; --loss: #c97b7b; --warn: #d4a55a;
  --border: #3a3a3c; --shadow: rgba(0, 0, 0, 0.3); --grid: rgba(255, 255, 255, 0.06); --overlay: rgba(0, 0, 0, 0.55);
  --on-accent: #1c1c1e;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg-primary: #f5f5f7; --bg-secondary: #ffffff; --bg-card: #ffffff; --bg-card-hover: #f0f0f2;
  --accent: #b5702f; --accent-light: #d4945a;
  --accent-gradient: linear-gradient(135deg, #d4945a 0%, #e8b88a 50%, #f0c89a 100%);
  --accent-gradient-hover: linear-gradient(135deg, #e8b88a 0%, #f0c89a 50%, #f5d4a8 100%);
  --accent-soft: rgba(212, 148, 90, 0.16);
  --text-primary: #1c1c1e; --text-secondary: #5e5e5e; --text-muted: #8a8a8a;
  --gain: #4f8f4f; --loss: #b85c5c; --warn: #b07a22;
  --border: #e0e0e2; --shadow: rgba(0, 0, 0, 0.08); --grid: rgba(0, 0, 0, 0.06); --overlay: rgba(0, 0, 0, 0.45);
  --on-accent: #1c1c1e;
  color-scheme: light;
}

body {
  font-family: 'Instrument Sans', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px; line-height: 1.6; background: var(--bg-primary); color: var(--text-primary);
  min-height: 100vh; transition: background-color .3s, color .3s;
}
.num { font-variant-numeric: tabular-nums; }
a { color: var(--accent-light); }

/* ---------- Layout ---------- */
.dashboard { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-secondary); padding: 28px 22px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; overflow-y: auto; z-index: 1000;
  transition: transform .3s;
}
.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.logo-icon {
  width: 42px; height: 42px; background: var(--accent-gradient); border-radius: 10px; display: grid; place-items: center;
  color: var(--on-accent); box-shadow: 0 4px 12px rgba(184, 115, 51, .25);
}
.logo-text { font-size: 21px; font-weight: 700; }
.logo-sub { font-size: 11px; color: var(--text-muted); letter-spacing: .5px; margin-top: -4px; }
.nav-section { margin-bottom: 26px; }
.nav-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }
.nav-item {
  display: flex; align-items: center; gap: 13px; padding: 12px 14px; border-radius: 10px; color: var(--text-secondary);
  text-decoration: none; margin-bottom: 5px; transition: all .2s; font-size: 15px; cursor: pointer;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--accent-gradient); color: var(--on-accent); font-weight: 600; box-shadow: 0 4px 12px rgba(184, 115, 51, .3); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-badge { margin-left: auto; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-light); font-weight: 600; }
.nav-item.active .nav-badge { background: rgba(28, 28, 30, .18); color: var(--on-accent); }
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--border); }
.theme-toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; color: var(--text-secondary); font-size: 15px; }
.switch { position: relative; width: 48px; height: 26px; background: var(--border); border-radius: 13px; cursor: pointer; border: 0; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: var(--text-primary); border-radius: 50%; transition: transform .3s; }
.switch.on { background: var(--accent-gradient); }
.switch.on::after { transform: translateX(22px); background: #fff; }
.data-stamp { font-size: 12px; color: var(--text-muted); padding: 8px 14px 0; line-height: 1.5; }

.main-content { padding: 30px 38px; min-width: 0; }
.mobile-menu-toggle {
  display: none; position: fixed; top: 16px; left: 16px; z-index: 1001; width: 44px; height: 44px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; align-items: center; justify-content: center; color: var(--text-primary);
}
.sidebar-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 999; opacity: 0; pointer-events: none; transition: opacity .3s; }
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* ---------- Header ---------- */
.header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.header h1 { font-size: 27px; font-weight: 700; margin-bottom: 2px; letter-spacing: -.2px; }
.header-subtitle { font-size: 14.5px; color: var(--text-secondary); }
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.icon-btn {
  height: 42px; min-width: 42px; padding: 0 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; color: var(--text-secondary);
  font: inherit; font-size: 14px; transition: all .2s;
}
.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.live-dot.on { background: var(--gain); box-shadow: 0 0 0 4px rgba(127, 163, 127, .2); }
.live-dot.busy { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Cards & grids ---------- */
.card { background: var(--bg-card); border-radius: 14px; padding: 24px; border: 1px solid var(--border); transition: border-color .3s; min-width: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 18px; font-weight: 600; }
.card-desc { font-size: 13.5px; color: var(--text-secondary); }
.grid { display: grid; gap: 22px; margin-bottom: 22px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
.stat-card { background: var(--bg-card); border-radius: 14px; padding: 18px; border: 1px solid var(--border); display: flex; gap: 14px; align-items: flex-start; transition: all .3s; min-width: 0; }
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px var(--shadow); }
.stat-card.primary { background: var(--accent-gradient); border: none; }
.stat-card.primary * { color: var(--on-accent) !important; }
.stat-card.primary .stat-icon { background: rgba(28, 28, 30, .16); }
.stat-icon { width: 44px; height: 44px; background: var(--accent-soft); border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; color: var(--accent-light); }
.stat-icon svg { width: 22px; height: 22px; }
.stat-content { min-width: 0; }
.stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-value { font-size: 23px; font-weight: 700; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-change { font-size: 12.5px; color: var(--text-muted); }
.pos { color: var(--gain); } .neg { color: var(--loss); } .warn { color: var(--warn); }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 210px; }
.chart-box.lg { height: 340px; }

/* ---------- Buttons & forms ---------- */
.btn {
  padding: 11px 22px; border-radius: 10px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; transition: all .2s;
  border: 1px solid var(--border); background: transparent; color: var(--text-primary); display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { background: var(--bg-card-hover); }
.btn.primary { background: var(--accent-gradient); border: none; color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-gradient-hover); transform: translateY(-1px); }
.btn.sm { padding: 7px 14px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text-secondary); }
.form-input, .form-select {
  width: 100%; padding: 11px 14px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 15px; color: var(--text-primary); transition: border-color .2s;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; color: var(--text-secondary); font: inherit; font-size: 13.5px; padding: 7px 13px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--accent-gradient); color: var(--on-accent); font-weight: 600; }
.chk { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text-secondary); cursor: pointer; margin-right: 14px; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=range] { accent-color: var(--accent); width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: default; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--text-primary); }
td { padding: 12px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: var(--bg-card-hover); }
td.r, th.r { text-align: right; }
.pool-cell { display: flex; align-items: center; gap: 10px; }
.p-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex-shrink: 0; }
.p-name { font-weight: 600; line-height: 1.25; }
.p-sub { font-size: 12px; color: var(--text-muted); }
.grade { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-weight: 700; font-size: 13px; }
.grade.A { background: rgba(127, 163, 127, .22); color: var(--gain); }
.grade.B { background: rgba(127, 163, 127, .12); color: var(--gain); }
.grade.C { background: rgba(212, 165, 90, .18); color: var(--warn); }
.grade.D { background: rgba(201, 123, 123, .16); color: var(--loss); }
.grade.E { background: rgba(201, 123, 123, .3); color: var(--loss); }
.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent-gradient); border-radius: 3px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 6px; display: inline-block; }
.pill.pos { background: rgba(127, 163, 127, .18); } .pill.neg { background: rgba(201, 123, 123, .18); } .pill.mut { background: var(--bg-primary); color: var(--text-secondary); }
.pill.acc { background: var(--accent-soft); color: var(--accent-light); }

/* ---------- Agent console ---------- */
.agent-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 22px; margin-bottom: 22px; }
.chat { display: flex; flex-direction: column; height: 520px; }
.chat-log { flex: 1; overflow-y: auto; padding-right: 6px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.msg { max-width: 88%; padding: 11px 15px; border-radius: 14px; font-size: 14.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-gradient); color: var(--on-accent); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bg-primary); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.bot b { color: var(--accent-light); }
.msg .src { display: block; margin-top: 6px; font-size: 11.5px; color: var(--text-muted); }
.chat-input { display: flex; gap: 10px; }
.chat-input textarea { resize: none; height: 48px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: 12.5px; padding: 6px 11px; border-radius: 99px; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); cursor: pointer; font-family: inherit; }
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.trace { list-style: none; position: relative; }
.trace li { position: relative; padding: 0 0 16px 34px; }
.trace li::before { content: ''; position: absolute; left: 11px; top: 24px; bottom: 0; width: 2px; background: var(--border); }
.trace li:last-child::before { display: none; }
.trace .dot { position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg-card); display: grid; place-items: center; font-size: 11px; color: var(--text-muted); }
.trace li.run .dot { border-color: var(--warn); color: var(--warn); animation: pulse 1s infinite; }
.trace li.done .dot { border-color: var(--gain); background: rgba(127, 163, 127, .18); color: var(--gain); }
.trace .t-title { font-weight: 600; font-size: 14.5px; }
.trace .t-tool { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--accent-light); background: var(--accent-soft); padding: 1px 7px; border-radius: 5px; margin-left: 6px; }
.trace .t-out { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.explain { font-size: 15px; line-height: 1.85; white-space: pre-wrap; }
.explain-src { font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.empty { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 10px; }
.donut-wrap { display: grid; grid-template-columns: 190px 1fr; gap: 18px; align-items: center; }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.legend div { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.legend i { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend span.n { margin-left: auto; color: var(--text-primary); font-weight: 600; }

/* ---------- Monitor ---------- */
.log { max-height: 360px; overflow-y: auto; font-size: 13.5px; display: flex; flex-direction: column; gap: 10px; }
.log-item { border-left: 3px solid var(--border); padding: 6px 12px; background: var(--bg-primary); border-radius: 0 8px 8px 0; }
.log-item.alert { border-color: var(--loss); } .log-item.ok { border-color: var(--gain); } .log-item.info { border-color: var(--accent); }
.log-item time { font-size: 11.5px; color: var(--text-muted); display: block; }
.shock-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.shock { text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-primary); color: var(--text-primary); cursor: pointer; font-family: inherit; transition: all .2s; }
.shock:hover { border-color: var(--loss); }
.shock b { display: block; font-size: 14px; } .shock span { font-size: 12.5px; color: var(--text-muted); }

/* ---------- RL ---------- */
.qtable td, .qtable th { text-align: center; padding: 8px 6px; }
.qcell { border-radius: 6px; padding: 4px 6px; font-size: 12.5px; }
.qbest { outline: 2px solid var(--accent); font-weight: 700; }

/* ---------- About ---------- */
.prose { font-size: 15px; line-height: 1.85; color: var(--text-secondary); }
.prose h3 { color: var(--text-primary); font-size: 17px; margin: 18px 0 8px; }
.prose ul { padding-left: 20px; }
.prose b { color: var(--text-primary); }
.flow { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; }
.flow .node { flex: 1 1 140px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 12px; padding: 14px; position: relative; }
.flow .node b { display: block; font-size: 14px; margin-bottom: 4px; color: var(--accent-light); }
.flow .node span { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; display: block; }
.flow .arrow { align-self: center; color: var(--text-muted); font-size: 20px; }

/* ---------- Modal / drawer ---------- */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 26px; width: min(760px, 100%); max-height: 90vh; overflow-y: auto; }
.modal.narrow { width: min(480px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; gap: 10px; }
.close-x { background: none; border: 0; color: var(--text-secondary); font-size: 24px; cursor: pointer; line-height: 1; }
.note { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--bg-card); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 18px; z-index: 3000; box-shadow: 0 10px 30px var(--shadow); font-size: 14px; transform: translateY(120%); opacity: 0; transition: all .3s; max-width: calc(100vw - 44px); }
.toast.show { transform: none; opacity: 1; }
.copyright { text-align: center; padding: 22px 0 6px; color: var(--text-muted); font-size: 13px; border-top: 1px solid var(--border); margin-top: 30px; }
.page { display: none; } .page.active { display: block; animation: fade .35s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.disclaimer { font-size: 12.5px; color: var(--text-muted); background: var(--bg-primary); border: 1px dashed var(--border); border-radius: 10px; padding: 10px 14px; margin-top: 14px; line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, 1fr); } .agent-grid { grid-template-columns: 1fr; } }
@media (max-width: 1024px) {
  .mobile-menu-toggle { display: flex; }
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; width: 270px; transform: translateX(-100%); box-shadow: 4px 0 24px var(--shadow); }
  .sidebar.active { transform: none; }
  .main-content { padding: 76px 22px 24px; }
  .g3, .g2, .g-2-1, .g-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .main-content { padding: 72px 16px 20px; }
  .g4 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card { padding: 18px; }
  .stat-card { padding: 14px; flex-direction: column; gap: 8px; }
  .stat-value { font-size: 19px; }
  .header h1 { font-size: 22px; }
  .donut-wrap { grid-template-columns: 1fr; }
  .chat { height: 480px; }
  .shock-grid { grid-template-columns: 1fr; }
  .msg { max-width: 95%; }
}
