/* ============ Trading Journal – Styles ============ */
:root {
  --bg: #0a101d;
  --bg-2: #0d1424;
  --panel: #0f172a;
  --panel-2: #121b30;
  --panel-3: #16213a;
  --border: #1d2842;
  --border-2: #26334f;
  --text: #e6ebf5;
  --text-2: #aab4c8;
  --muted: #6b7891;
  --accent: #2f6bff;
  --accent-2: #4f84ff;
  --accent-soft: rgba(47, 107, 255, .14);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, .13);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, .13);
  --amber: #f5b301;
  --amber-soft: rgba(245, 179, 1, .14);
  --purple: #a78bfa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sidebar-w: 214px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5fa;
  --bg-2: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --panel-3: #eef2f8;
  --border: #e1e6ef;
  --border-2: #d3dae6;
  --text: #121a2b;
  --text-2: #3d4a63;
  --muted: #7a869c;
  --accent-soft: rgba(47, 107, 255, .1);
  --shadow: 0 10px 30px rgba(20, 30, 60, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
.hidden { display: none !important; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 10px 10px;
  transition: width .2s;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 800; line-height: 1.05; font-size: 17px; }
.brand svg { flex: none; }
.mode-switch {
  display: flex; background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px; margin: 0 6px 18px; gap: 2px;
}
.mode-switch button {
  flex: 1; border: 0; background: transparent; padding: 6px 6px; border-radius: 999px; cursor: pointer;
  color: var(--muted); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; overflow: hidden;
}
.mode-switch button.active { background: var(--panel-3); color: var(--text); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden;
}
.nav a svg { flex: none; width: 18px; height: 18px; color: var(--text-2); }
.nav a:hover { background: var(--panel); }
.nav a.active { background: var(--accent); color: #fff; }
.nav a.active svg { color: #fff; }
.nav-sep { height: 1px; background: var(--border); margin: 12px 6px; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.collapse-btn { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 0; background: none; color: var(--text-2); cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.user-row { display: flex; gap: 6px; align-items: stretch; }
.user-row .user-chip { flex: 1; min-width: 0; }
.user-row .logout { padding: 0 9px; }
#app.collapsed .user-row .logout { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #3b6cff, #6d4dff); display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.user-chip .name { font-weight: 700; font-size: 13.5px; line-height: 1.1; }
.user-chip .role { font-size: 11.5px; color: var(--muted); }
#app.collapsed #sidebar { width: 68px; }
#app.collapsed .brand span, #app.collapsed .nav a span, #app.collapsed .collapse-btn span,
#app.collapsed .user-chip .meta, #app.collapsed .mode-switch .lbl { display: none; }
#app.collapsed .mode-switch { flex-direction: column; border-radius: 12px; }

/* ---------- Main ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
#topbar { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 16px 22px 0; flex: none; }
#topbar .spacer { flex: 1; }
#view { flex: 1; overflow: auto; padding: 18px 22px 28px; }
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 18px; letter-spacing: -.01em; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .page-title { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.btn.mobile-menu { display: none; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border-2);
  background: var(--panel); color: var(--text); padding: 8px 13px; border-radius: 9px;
  cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--panel-3); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-3); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { padding: 7px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border-2); background: var(--panel-2); font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text);
}
.chip:hover { background: var(--panel-3); }
.chip.accent { color: var(--accent-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

.input, select.input, textarea.input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 9px;
  padding: 8px 11px; color: var(--text); outline: none; min-height: 36px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 80px; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a96ad' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
input[type="date"].input, input[type="datetime-local"].input { color-scheme: inherit; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 13px; }
.seg button.active { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.seg.long button.active[data-v="Long"] { background: var(--green-soft); color: var(--green); }
.seg.long button.active[data-v="Short"] { background: var(--red-soft); color: var(--red); }

/* Topbar filter boxes */
.tb-box {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; height: 46px; cursor: pointer; position: relative; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tb-box:hover { border-color: var(--border-2); }
.tb-box.focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tb-box .x { color: var(--muted); cursor: pointer; padding: 2px; display: flex; }
.tb-box .x:hover { color: var(--text); }
.tb-box select { background: transparent; border: 0; outline: none; font-weight: 600; cursor: pointer; padding-right: 4px; }
.tb-box select option { background: var(--panel); }

/* Dropdowns */
.dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50; min-width: 240px;
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; cursor: default;
}
.dropdown .dd-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.dropdown .dd-item:hover { background: var(--panel-3); }
.dropdown .dd-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown .dd-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 4px; font-weight: 700; }
.range-dd { display: grid; grid-template-columns: 150px 1fr; gap: 10px; min-width: 430px; }
.range-dd .presets { display: flex; flex-direction: column; gap: 1px; border-right: 1px solid var(--border); padding-right: 8px; }
.range-dd .custom { display: flex; flex-direction: column; gap: 10px; padding: 6px; }

/* ---------- Panels & Cards ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-pad { padding: 18px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-head .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.panel-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-height: 104px; position: relative; overflow: hidden; }
.kpi .lbl { color: var(--text-2); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.kpi .sub { font-size: 12.5px; color: var(--muted); }
.kpi .gauge { position: absolute; right: 14px; top: 16px; }
.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 700; }
.mono { font-family: var(--mono); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 200px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.empty h4 { color: var(--text); margin: 4px 0; font-size: 15px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; background: var(--panel-3); color: var(--text-2); white-space: nowrap; }
.badge.long, .badge.win { background: var(--green-soft); color: var(--green); }
.badge.short, .badge.loss { background: var(--red-soft); color: var(--red); }
.badge.be { background: var(--amber-soft); color: var(--amber); }
.badge.accent { background: var(--accent-soft); color: var(--accent-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.tag { display: inline-flex; padding: 2px 8px; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--border-2); font-size: 11.5px; color: var(--text-2); }
.progress { height: 8px; border-radius: 99px; background: var(--panel-3); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress.green > div { background: var(--green); }
.progress.red > div { background: var(--red); }
.stars { color: var(--amber); letter-spacing: 1px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--panel); cursor: default; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl tr.clickable { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; border-top: 1px solid var(--border-2); }
.tbl tr:last-child td { border-bottom: 0; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 7, 15, .65); backdrop-filter: blur(2px); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 640px; animation: pop .15s ease-out; }
.modal.wide { max-width: 980px; }
.modal.xwide { max-width: 1200px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-foot .left { margin-right: auto; display: flex; gap: 8px; }
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Login ---------- */
.login-screen { position: fixed; inset: 0; z-index: 500; background: radial-gradient(1200px 600px at 20% -10%, rgba(47,107,255,.18), transparent), var(--bg); display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; max-height: calc(100vh - 32px); overflow: auto; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-err { color: var(--red); min-height: 18px; }
.login-card .brand { font-size: 17px; }
.code-input { font-family: var(--mono); font-size: 22px !important; letter-spacing: .25em; text-align: center; }
.qr-box { background: #fff; border-radius: 12px; padding: 6px; width: 210px; height: 210px; align-self: center; }
.qr-box svg { width: 100%; height: 100%; display: block; }
code.secret { font-family: var(--mono); font-size: 13px; word-break: break-all; user-select: all; background: var(--panel-3); padding: 3px 7px; border-radius: 6px; display: inline-block; margin-top: 4px; }
.backup-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.backup-codes code { font-family: var(--mono); font-size: 15px; text-align: center; padding: 7px; background: var(--panel-3); border: 1px solid var(--border-2); border-radius: 8px; user-select: all; }
.sec-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sec-row:last-child { border-bottom: 0; }
.sec-row .t { flex: 1; min-width: 200px; }
.sec-row .t .l { font-weight: 700; }
.sec-row .t .d { font-size: 12.5px; color: var(--muted); }
.boot-msg { max-width: 620px; margin: 10vh auto; }
.boot-msg code { background: var(--panel-3); padding: 1px 6px; border-radius: 5px; }

#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel-3); border: 1px solid var(--border-2); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; font-size: 13.5px; animation: pop .15s; max-width: 380px; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

/* ---------- Calendar ---------- */
.cal-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 170px; gap: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-dow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 0 6px 4px; }
.cal-cell { min-height: 104px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 9px; background: var(--panel-2); display: flex; flex-direction: column; gap: 3px; cursor: pointer; position: relative; }
.cal-cell:hover { border-color: var(--border-2); }
.cal-cell.out { opacity: .35; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.win { background: linear-gradient(180deg, var(--green-soft), var(--panel-2)); border-color: rgba(34,197,94,.35); }
.cal-cell.loss { background: linear-gradient(180deg, var(--red-soft), var(--panel-2)); border-color: rgba(239,68,68,.35); }
.cal-cell .d { font-weight: 700; font-size: 12.5px; color: var(--text-2); display: flex; justify-content: space-between; }
.cal-cell .p { font-weight: 800; font-size: 16px; margin-top: auto; }
.cal-cell .s { font-size: 11.5px; color: var(--muted); }
.cal-cell .p .cmp { display: none; }
.cal-cell .note-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--purple); }
.cal-week { display: flex; flex-direction: column; gap: 8px; padding-top: 22px; }
.cal-week .w { min-height: 104px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--panel); display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.mini-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mini-cal div { aspect-ratio: 1; border-radius: 4px; background: var(--panel-3); }

/* ---------- Notebook ---------- */
.nb { display: grid; grid-template-columns: 264px 412px minmax(0, 1fr); gap: 18px; height: 100%; min-height: 0; }
.nb-col { display: flex; flex-direction: column; min-height: 0; }
.nb-cats { display: flex; flex-direction: column; gap: 3px; }
.nb-cat { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--text); border: 1px solid transparent; }
.nb-cat svg { width: 17px; height: 17px; color: var(--text-2); flex: none; }
.nb-cat .cnt { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 600; }
.nb-cat:hover { background: var(--panel); }
.nb-cat.active { background: var(--panel); border-color: var(--border-2); }
.nb-sec { font-size: 12px; color: var(--muted); font-weight: 600; margin: 16px 0 6px; padding-top: 14px; border-top: 1px solid var(--border); }
.nb-tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px; }
.nb-list { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.nb-list-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px; border-bottom: 1px solid var(--border); }
.nb-list-head h4 { margin: 0; font-size: 14.5px; margin-right: auto; }
.nb-items { overflow: auto; flex: 1; }
.nb-item { padding: 12px 15px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.nb-item:hover { background: var(--panel-2); }
.nb-item.active { background: var(--panel-3); box-shadow: inset 3px 0 0 var(--accent); }
.nb-item .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 14px; }
.nb-item .t .k { font-weight: 500; font-size: 12px; color: var(--muted); flex: none; }
.nb-item .m { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-2); margin-top: 3px; font-weight: 600; }
.nb-item .x { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nb-item .fav { color: var(--amber); }
.nb-editor { padding: 18px 20px; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.nb-editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.nb-editor-head h2 { margin: 0; font-size: 21px; font-weight: 800; margin-right: auto; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-title-input { background: transparent; border: 0; outline: none; font-size: 21px; font-weight: 800; color: var(--text); flex: 1; min-width: 200px; }
.nb-tpl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.nb-tpl .lbl { font-size: 12.5px; color: var(--muted); }
.nb-tpl .saved { margin-left: auto; font-size: 12px; color: var(--muted); }
.nb-tpl .acts { display: flex; gap: 2px; }
.nb-summary .none { grid-column: 1 / -1; }
.nb-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-bottom: 14px; }
.nb-summary .s { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px; }
.nb-summary .s .l { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.nb-summary .s .v { font-weight: 800; font-size: 15px; }

/* Editor */
.rte { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-2); display: flex; flex-direction: column; min-height: 420px; flex: 1; }
.rte.fullscreen { position: fixed; inset: 16px; z-index: 90; background: var(--panel); box-shadow: var(--shadow); }
.rte-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.rte-toolbar .sep { width: 1px; height: 22px; background: var(--border-2); margin: 0 5px; }
.rte-toolbar .break { flex-basis: 100%; height: 0; }
.rte-toolbar button { border: 0; background: none; color: var(--text-2); padding: 6px 8px; border-radius: 7px; cursor: pointer; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; min-width: 30px; justify-content: center; }
.rte-toolbar button:hover { background: var(--panel-3); color: var(--text); }
.rte-toolbar button.on { background: var(--accent-soft); color: var(--accent-2); }
.rte-toolbar button svg { width: 15px; height: 15px; }
.rte-toolbar select { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 8px; padding: 5px 8px; outline: none; font-size: 13px; min-width: 110px; }
.rte-toolbar .fs { width: 44px; text-align: center; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 8px; padding: 5px 4px; font-size: 13px; }
.rte-toolbar .color-btn { position: relative; }
.rte-toolbar .color-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.rte-toolbar .full { margin-left: auto; }
.rte-content { flex: 1; padding: 18px 22px; outline: none; overflow: auto; font-size: 14.5px; line-height: 1.6; min-height: 300px; }
.rte-content:empty:before { content: attr(data-placeholder); color: var(--muted); }
.rte-content h1 { font-size: 24px; margin: 14px 0 8px; }
.rte-content h2 { font-size: 19px; margin: 12px 0 6px; }
.rte-content h3 { font-size: 16px; margin: 10px 0 6px; }
.rte-content p { margin: 0 0 6px; }
.rte-content blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding: 6px 14px; background: var(--panel-2); border-radius: 0 8px 8px 0; color: var(--text-2); }
.rte-content pre { background: var(--panel-3); padding: 10px 14px; border-radius: 8px; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; }
.rte-content img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.rte-content table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.rte-content td, .rte-content th { border: 1px solid var(--border-2); padding: 6px 9px; min-width: 60px; }
.rte-content th { background: var(--panel-3); }
.rte-content ul.checklist { list-style: none; padding-left: 4px; }
.rte-content ul.checklist li { position: relative; padding-left: 26px; }
.rte-content ul.checklist li:before { content: ""; position: absolute; left: 0; top: 4px; width: 15px; height: 15px; border: 2px solid var(--border-2); border-radius: 4px; cursor: pointer; }
.rte-content ul.checklist li.done { color: var(--muted); text-decoration: line-through; }
.rte-content ul.checklist li.done:before { background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center/11px no-repeat; border-color: var(--green); }
.rte-content a { text-decoration: underline; }
.note-view { font-size: 14px; line-height: 1.6; }
.note-view img { max-width: 100%; border-radius: 8px; }

/* ---------- Trade detail ---------- */
.trade-hero { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.trade-hero .s { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.trade-hero .s .l { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.trade-hero .s .v { font-weight: 800; font-size: 16px; margin-top: 2px; }
.shots { display: flex; gap: 10px; flex-wrap: wrap; }
.shots .shot { width: 140px; height: 90px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); position: relative; cursor: zoom-in; background: var(--panel-3); }
.shots .shot img { width: 100%; height: 100%; object-fit: cover; }
.shots .shot .rm { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); border: 0; color: #fff; border-radius: 6px; cursor: pointer; padding: 2px 6px; }
.dropzone { border: 1.5px dashed var(--border-2); border-radius: 10px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 300; display: grid; place-items: center; cursor: zoom-out; padding: 30px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Filters bar ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 140px; }
.filters .search { min-width: 220px; }

/* ---------- Catalog cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.card h4 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card .stats .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.card .stats .v { font-weight: 800; }
.card .desc { color: var(--text-2); font-size: 13px; }
.card ul.rules { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.card .foot { display: flex; gap: 6px; margin-top: auto; }
.rule-row { display: flex; gap: 6px; margin-bottom: 6px; }

/* ---------- Backtesting ---------- */
.bt { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; height: 100%; min-height: 0; }
.bt-chart-panel { display: flex; flex-direction: column; min-height: 0; }
.bt-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bt-toolbar .title { font-weight: 800; font-size: 15px; margin-right: 6px; }
.bt-chart { flex: 1; min-height: 360px; position: relative; }
.bt-statusbar { display: flex; gap: 18px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.bt-statusbar b { color: var(--text); }
.bt-side { display: flex; flex-direction: column; gap: 14px; overflow: auto; min-height: 0; }
.bt-order .seg { width: 100%; }
.bt-order .seg button { flex: 1; }
.bt-pos { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; }
.bt-hint { font-size: 12px; color: var(--muted); }
.pick-on { box-shadow: 0 0 0 2px var(--amber) inset; }
.sessions { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--border-2); border-bottom-width: 2px; border-radius: 5px; color: var(--text-2); background: var(--panel-2); }

/* ---------- Responsive ---------- */
@media (max-width: 1400px) {
  .nb { grid-template-columns: 220px 340px minmax(0, 1fr); }
}
@media (max-width: 1150px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nb { grid-template-columns: 1fr; height: auto; }
  .nb-list { max-height: 420px; }
  .bt { grid-template-columns: 1fr; height: auto; }
  .bt-chart { min-height: 460px; }
}
@media (max-width: 820px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 80; transform: translateX(-100%); transition: transform .2s; width: 240px; }
  #app.mobile-open #sidebar { transform: none; box-shadow: var(--shadow); }
  #app.collapsed #sidebar { width: 240px; }
  .btn.mobile-menu { display: inline-flex; }
  #topbar { flex-wrap: wrap; padding: 12px 16px 0; justify-content: flex-start; }
  #view { padding: 14px 16px 24px; }
  .tb-box { height: 40px; font-size: 13px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid > *, .grid > * { min-width: 0; }
  .input { min-width: 0; max-width: 100%; }
  input[type="date"].input, input[type="datetime-local"].input { -webkit-appearance: none; appearance: none; min-height: 40px; }
  .modal-body { overflow-x: hidden; }
  .cal-wrap { grid-template-columns: 1fr; }
  .cal-week { display: none; }
  .cal-cell { min-height: 64px; padding: 5px; }
  .cal-cell .p { font-size: 11.5px; }
  .cal-cell .p .full { display: none; }
  .cal-cell .p .cmp { display: inline; }
  .kpi .val { font-size: 20px; }
  .kpi { padding: 13px 14px; min-height: 90px; }
  .kpi .gauge { transform: scale(.75); transform-origin: top right; right: 8px; top: 10px; }
  .page-title { font-size: 22px; }
  .cal-cell .s { display: none; }
  .range-dd { grid-template-columns: 1fr; min-width: 280px; }
  .dropdown { right: auto; left: 0; }
}

/* ============ iPhone / App-Modus ============ */
html.standalone, html.standalone body { overflow: hidden; }
#tabbar { display: none; }
button, a, .chip, .nb-item, .tcard { -webkit-tap-highlight-color: transparent; }
.tcards { display: flex; flex-direction: column; }
.tcard { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative; }
.tcard:last-child { border-bottom: 0; }
.tcard:active { background: var(--panel-3); }
.tcard::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--border-2); }
.tcard.win::before { background: var(--green); }
.tcard.loss::before { background: var(--red); }
.tcard.be::before { background: var(--amber); }
.tc-main { flex: 1; min-width: 0; }
.tc-sym { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.tc-sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: inherit; }
.tc-val { text-align: right; flex: none; }
.tc-val .tc-sub { justify-content: flex-end; }
.tc-pnl { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.nb-back { display: none; }
@keyframes sheet { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

@media (max-width: 820px) {
  html, body { overscroll-behavior-y: none; }
  #app { height: 100vh; height: 100dvh; }
  #topbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 2px; }
  #topbar::-webkit-scrollbar { display: none; }
  #topbar .spacer, .btn.mobile-menu { display: none; }
  #topbar .tb-box { flex: none; height: 36px; font-size: 12.5px; padding: 0 10px; min-width: 0 !important; border-radius: 999px; }
  #save-status { display: none; }
  #save-status.err { display: inline; position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 90; background: var(--panel-3); border: 1px solid var(--red); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
  #view { padding: 12px 14px calc(92px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
  .page-head { margin-bottom: 12px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions .seg { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .page-head .actions .seg button { flex: none; }

  /* Seitenmenü als Overlay über „Mehr“ */
  #sidebar { padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom)); width: 270px; overflow-y: auto; }
  #app.mobile-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 75; }
  #app.collapsed .brand span, #app.collapsed .nav a span, #app.collapsed .collapse-btn span, #app.collapsed .user-chip .meta, #app.collapsed .mode-switch .lbl { display: initial; }
  .collapse-btn { display: none; }

  /* Tab-Leiste unten */
  #tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; align-items: flex-end;
    background: color-mix(in srgb, var(--bg-2) 88%, transparent); backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5);
    border-top: 1px solid var(--border); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  #tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--muted); padding: 4px 0 2px; }
  #tabbar a svg { width: 23px; height: 23px; }
  #tabbar a.active { color: var(--accent-2); }
  #tabbar a.fab span { width: 50px; height: 50px; margin-top: -22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(47, 107, 255, .45); border: 3px solid var(--bg-2); }
  #tabbar a.fab svg { width: 24px; height: 24px; }

  /* iOS zoomt bei Schrift < 16 px in Eingabefeldern – vermeiden */
  .input, select.input, textarea.input, .rte-content, .rte-toolbar select, .rte-toolbar .fs, .nb-title-input, .filters .input { font-size: 16px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px 12px; padding: 0 14px; }
  .filters::-webkit-scrollbar { display: none; }
  .filters .input { flex: none; min-width: 150px; }
  .filters .search { min-width: 200px; }

  /* Dialoge als Bottom-Sheet */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal, .modal.wide, .modal.xwide { max-width: 100%; border-radius: 18px 18px 0 0; max-height: calc(100dvh - env(safe-area-inset-top) - 10px); display: flex; flex-direction: column; animation: sheet .22s ease-out; border-bottom: 0; }
  .modal-head { padding: 14px 16px; position: relative; }
  .modal-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--border-2); }
  .modal-body { overflow-y: auto; flex: 1; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
  .modal-foot { flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .left { width: 100%; margin: 0 0 4px; }
  .modal-foot > .btn { flex: 1; justify-content: center; padding: 11px; }
  #toast-root { left: 14px; right: 14px; bottom: calc(84px + env(safe-area-inset-bottom)); align-items: center; }
  .toast { max-width: 100%; }
  .trade-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shots .shot { width: calc(50% - 5px); height: 100px; }
  .form-grid .span-2 { grid-column: 1 / -1; }

  /* Notebook: Liste ODER Notiz */
  .nb { display: block; height: auto; }
  .nb.m-list .nb-editor { display: none; }
  .nb.m-editor > .nb-col:first-child, .nb.m-editor > .nb-list { display: none; }
  .nb.m-list > .nb-col:first-child .page-title { margin-bottom: 10px !important; }
  .nb.m-list .nb-cats { flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  .nb.m-list .nb-cats::-webkit-scrollbar { display: none; }
  .nb.m-list .nb-cat { flex: none; border: 1px solid var(--border-2); border-radius: 999px; padding: 7px 12px; background: var(--panel); white-space: nowrap; }
  .nb.m-list .nb-cats + .nb-sec + .nb-cats { margin-top: 8px; }
  .nb.m-list [data-tags-toggle], .nb.m-list .nb-tags:empty { display: none; }
  .nb.m-list .nb-tags { flex-wrap: nowrap; overflow-x: auto; flex: none; padding: 0; }
  .nb.m-list .nb-cat .cnt { margin-left: 4px; }
  .nb.m-list .nb-sec { display: none; }
  .nb.m-list .nb-tags { padding: 8px 0 0; }
  .nb.m-list .nb-list { margin-top: 12px; max-height: none; }
  .nb.m-list .nb-items { overflow: visible; }
  .nb-back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; margin-bottom: 8px; }
  .nb-editor { padding: 14px; }
  .nb-editor-head h2 { font-size: 18px; white-space: normal; flex-basis: 100%; }
  .rte { min-height: 60vh; }
  .rte-toolbar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .rte-toolbar::-webkit-scrollbar { display: none; }
  .rte-toolbar .break { display: none; }
  .rte-toolbar > * { flex: none; }
  .rte-content { padding: 14px; }

  /* Backtesting */
  .bt-chart { min-height: 52vh; }
  .bt-toolbar { gap: 6px; }
  .bt-toolbar .title { flex-basis: 100%; }
  .bt-toolbar [data-jump] { display: none; }

  /* Anmeldung */
  .login-screen { padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.kpis { gap: 10px; }
  .cards, .sessions { grid-template-columns: 1fr; }
}

@media print {
  #sidebar, #topbar, .no-print { display: none !important; }
  #view { overflow: visible; }
  body { background: #fff; color: #000; }
  .panel { border-color: #ccc; break-inside: avoid; }
}
