/* TradeJournal v2 — theme matched to the user's TradeZella screenshot
   (design_refs): light main area, dark-indigo sidebar, purple accent,
   teal win-rate rings. */
:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #eef0f6;
  --border: #e3e6ef;
  --text: #23262f;
  --muted: #7a7f93;
  --side-bg: #2b2846;
  --side-bg-2: #35315a;
  --side-text: #c9c6e4;
  --accent: #6c5ce7;
  --accent-dim: #5a4bd4;
  --ring: #35c3ae;
  --pos: #1ea672;
  --neg: #e5484d;
  --warn: #f5a623;
  --input-bg: #fff;
  --err-bg: #fdecec;
  --chip-accent-bg: #ece9fd;
  --chip-pos-bg: #e2f6ec;
  --chip-neg-bg: #fdecec;
  --cal-green: #e9f7f0; --cal-green-b: #bfe5d4;
  --cal-red: #fdeeee;   --cal-red-b: #f3c6c8;
  --auth-brand: #2b2846;
  --toast-bg: #23262f; --toast-text: #fff;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
/* ---- night theme: same token names, swapped values (router/core set
   <html data-theme> from localStorage or prefers-color-scheme). Sidebar
   stays dark-indigo in both — the TradeZella look. ---- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12131a;
  --panel: #1a1d29;
  --panel-2: #232636;
  --border: #2a2e40;
  --text: #e9ebf5;
  --muted: #8f94ab;
  --accent: #7b6ef0;
  --accent-dim: #6a5ce0;
  --pos: #3ecf8e;
  --neg: #ff6b6e;
  --warn: #fbbf24;
  --input-bg: #1e2230;
  --err-bg: #3a1d22;
  --chip-accent-bg: #2d2a55;
  --chip-pos-bg: #16352a;
  --chip-neg-bg: #3a1d22;
  --cal-green: #14301f; --cal-green-b: #1f4d31;
  --cal-red: #341a1e;   --cal-red-b: #4d2228;
  --auth-brand: #e9ebf5;
  --toast-bg: #2a2e40; --toast-text: #e9ebf5;
}
html[data-theme="dark"] .card, html[data-theme="dark"] .stat,
html[data-theme="dark"] .pb-card { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
html[data-theme="dark"] table.grid tr.clickable:hover td { background: var(--panel-2); }
html[data-theme="dark"] .overlay { background: rgba(0, 0, 0, 0.6); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }

#app { display: flex; min-height: 100vh; }

/* ---- sidebar (desktop) / bottom tabs (mobile) ---- */
#sidebar { width: 230px; flex-shrink: 0; background: var(--side-bg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 20px 14px; font-weight: 700; font-size: 17px; display: flex; gap: 8px;
  align-items: center; color: #fff; letter-spacing: 0.3px; }
.brand-mark { color: var(--accent); }
#nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: var(--side-text); text-decoration: none; font-weight: 500; }
#nav a:hover { background: var(--side-bg-2); color: #fff; }
#nav a.active { background: var(--side-bg-2); color: #fff; }
#nav .ic { width: 20px; text-align: center; }
.side-foot { padding: 14px 16px; border-top: 1px solid var(--side-bg-2); }
.side-foot .muted { color: var(--side-text); }
.side-foot .xsmall { color: #6f6b96; }

#main { flex: 1; min-width: 0; padding: 0 26px 40px; }
#topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 0 12px;
  position: sticky; top: 0; background: var(--bg); z-index: 5; }
#topbar h1 { font-size: 20px; margin: 0; }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  #sidebar { left: 0; right: 0; width: auto; height: auto; position: fixed; bottom: 0; top: auto; z-index: 20;
    flex-direction: row; align-items: center; justify-content: space-around; }
  .brand, .side-foot { display: none; }
  #nav { flex-direction: row; justify-content: space-between; padding: 4px 2px; width: 100%; }
  #nav a { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; font-size: 9px; padding: 6px 2px; }
  #nav .ic { font-size: 17px; }
  #main { padding: 0 12px 96px; }
}

/* ---- cards / stats ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(30, 34, 60, 0.04);
  overflow-x: auto; }  /* wide tables scroll inside their card on phones */
.card-title { margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 1px 2px rgba(30, 34, 60, 0.04); }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; margin-top: 4px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.small { font-size: 13px; } .xsmall { font-size: 11px; }
.empty { color: var(--muted); padding: 26px 10px; text-align: center; }
.banner { padding: 10px 14px; border-radius: 9px; margin-bottom: 12px; }
.banner.err { background: var(--err-bg); color: var(--neg); }

/* ---- tables ---- */
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; color: var(--muted); font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.3px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: var(--bg); }
.num { text-align: right; }

/* ---- chips / buttons / forms ---- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  background: var(--panel-2); color: var(--muted); margin: 1px 3px 1px 0; }
.chip.accent { background: var(--chip-accent-bg); color: var(--accent); }
.chip.pos { background: var(--chip-pos-bg); color: var(--pos); }
.chip.neg { background: var(--chip-neg-bg); color: var(--neg); }
.btn { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dim); color: #fff; }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input, textarea { background: var(--input-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ---- modal ---- */
.overlay { position: fixed; inset: 0; background: rgba(23, 22, 41, 0.45); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: min(640px, 100%); max-height: 88vh; overflow: auto;
  box-shadow: 0 12px 40px rgba(20, 20, 40, 0.25); }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.field-hint { font-size: 11px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 18px; border-radius: 10px; z-index: 99;
  border: 1px solid var(--border);
  transition: opacity 0.5s; }
.toast.err { background: var(--neg); }
.toast.out { opacity: 0; }

/* ---- charts ---- */
.chart { width: 100%; height: auto; display: block; }

/* ---- calendar (journal month grid) ---- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; color: var(--muted); font-size: 11px; font-weight: 700; padding: 4px 0; }
.cal .day { min-height: 74px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 8px; cursor: pointer; position: relative; }
.cal .day.blank { background: transparent; border: none; cursor: default; }
.cal .day:hover:not(.blank) { border-color: var(--accent); }
.cal .day .dnum { font-size: 11px; color: var(--muted); }
.cal .day .dpnl { font-size: 13px; font-weight: 700; margin-top: 3px; }
.cal .day.green { background: var(--cal-green); border-color: var(--cal-green-b); }
.cal .day.red { background: var(--cal-red); border-color: var(--cal-red-b); }
.cal .day .logdot { position: absolute; top: 6px; right: 8px; color: var(--accent); font-size: 11px; }
@media (max-width: 820px) { .cal .day { min-height: 58px; } }
/* KPI gauge cards + compact dashboard calendar (TradeZella parity pass) */
.gauge-row { display: flex; align-items: center; gap: 10px; }
.gauge-row svg.chart { width: 46px; height: 46px; flex: none; }
.cal .day.mini { min-height: 62px; position: relative; }
.cal .day.mini .dpnl { font-size: 12px; }
.cal .day.mini .small { font-size: 10px; }
@media (max-width: 820px) { .cal .day.mini { min-height: 48px; } .gauge-row svg.chart { width: 38px; height: 38px; } }

/* ---- progress bars (goals) ---- */
.prog { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.prog > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.prog.done > i { background: var(--pos); }

/* ---- playbook cards (matched to screenshot) ---- */
.pb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.pb-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 1px 2px rgba(30, 34, 60, 0.05); display: flex; flex-direction: column; }
.pb-thumb { height: 120px; background: linear-gradient(135deg, #2b2846, #4a3f8f); position: relative;
  display: flex; align-items: center; justify-content: center; font-size: 40px; color: #fff; cursor: pointer; }
.pb-body { padding: 14px 16px; }
.pb-name { font-size: 15.5px; font-weight: 700; margin-bottom: 10px; }
.pb-stats { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; align-items: center; margin-top: 8px; }
.pb-stats .k { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.pb-stats .v { font-size: 14px; font-weight: 700; margin-top: 2px; }
.pb-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px;
  padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
ul.rules { margin: 6px 0 0; padding-left: 18px; }
ul.rules li { margin: 3px 0; font-size: 13px; }

/* ---- tabs (My playbooks | Templates style) ---- */
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 8px 2px; cursor: pointer; border-bottom: 2px solid transparent; display: flex; gap: 6px; align-items: center; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- notebook ---- */
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.note-body { white-space: pre-wrap; font-size: 13.5px; color: var(--text); }

/* trade detail drawer */
.drawer-shots { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.drawer-shots img { max-height: 140px; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }

/* ---- card grids (notebook / goals reuse pb-card visuals) ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
/* ---- playbook cards v2 (matched to TradeZella reference) ---- */
.pb-banner { height: 132px; background: linear-gradient(135deg, #232043, #37315f 60%, #2b2846); }
.pb-banner svg { display: block; width: 100%; height: 100%; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pb-foot-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pb-avatar { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(135deg, #4a3f8f, #6c5ce7); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 800; }
.pb-avatar.brand { background: #2b2846; }
.pb-add { width: 34px; height: 34px; border: none; border-radius: 10px; flex: 0 0 auto;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; }
.pb-add:hover { filter: brightness(1.1); }
.searchbox { background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font: inherit; font-size: 13.5px; color: var(--text); min-width: 170px; }
.searchbox:focus { outline: none; border-color: var(--accent); }
.tmpl-head { margin: 2px 0 16px; }
.tmpl-title { font-size: 21px; font-weight: 800; margin-bottom: 2px; }

/* ---- progress goals ---- */
.goal-bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 10px; }
.goal-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.35s ease; }
.goal-fill.done { background: var(--pos); }

/* ---- auth screen + user chip (multi-user pass) ---- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
             justify-content: center; padding: 24px; }
.auth-brand { font-size: 22px; font-weight: 700; color: var(--auth-brand); margin-bottom: 14px; }
.auth-card { width: 100%; max-width: 380px; padding: 22px; }
.auth-form .field { margin-bottom: 12px; }
.btn.block { width: 100%; justify-content: center; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin: 8px 10px;
             background: var(--side-bg-2); border-radius: 10px; }
.user-chip .user-ava { width: 26px; height: 26px; border-radius: 50%; flex: none; color: #fff;
                       display: inline-flex; align-items: center; justify-content: center;
                       font-size: 13px; font-weight: 700;
                       background: linear-gradient(135deg, #4a3f8f, #6c5ce7); }
.user-chip .uname { color: #fff; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chip-admin { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #fff;
              background: var(--accent); border-radius: 999px; padding: 2px 7px; }
.user-chip .chip-out { background: none; border: none; color: #b9b4d8; font-size: 12px; cursor: pointer; }
.user-chip .chip-out:hover { color: #fff; }
.side-foot { margin-top: auto; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row-actions { text-align: right; white-space: nowrap; }
.invite-code { font-size: 15px; font-weight: 700; letter-spacing: .08em; cursor: copy;
               background: var(--panel-2); padding: 3px 8px; border-radius: 6px; }

/* ---- day/night toggle (topbar right on app, floating on auth screen) ---- */
.theme-toggle { width: 34px; height: 34px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel); cursor: pointer;
  font-size: 15px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle.float { position: fixed; top: 14px; right: 16px; z-index: 60; }
.fu-row { display: flex; gap: 10px; align-items: center; }
.fu-row > span { min-width: 0; }
.fu-row > span > input, .fu-row > span > select { width: 100%; min-width: 0; }
.fu-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; min-width: 0; }
