/* ===== Theme tokens ===== */
:root {                      /* light (default) */
  --bg: #e7ebf1;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #e2e8f1;
  --border: #cdd6e2;
  --text: #16202c;
  --muted: #5a6b7f;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #dceafe;
  --green: #15803d;
  --green-soft: #dcf3e4;
  --red: #dc2626;
  --red-soft: #fbe3e3;
  --amber: #b45309;
  --amber-soft: #fbedd6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.08), 0 2px 8px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 28px rgba(16,24,40,.16);
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --surface-3: #262e38;
  --border: #2a323c;
  --text: #e6eaf0;
  --muted: #93a0b0;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --accent-soft: #16233b;
  --green: #22c55e;
  --green-soft: #14301d;
  --red: #ef4444;
  --red-soft: #331617;
  --amber: #f59e0b;
  --amber-soft: #33280c;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== Top nav ===== */
header.nav {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 58px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
header.nav .brand { font-weight: 800; letter-spacing: .2px; font-size: 15px; white-space: nowrap; }
header.nav .brand span { color: var(--accent); }
header.nav nav { display: flex; gap: 2px; }
header.nav nav a {
  color: var(--muted); padding: 8px 13px; border-radius: 8px; font-weight: 600; white-space: nowrap;
}
header.nav nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
header.nav nav a.active { background: var(--accent); color: #fff; }
header.nav .right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--muted); white-space: nowrap;
}
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); cursor: pointer;
  width: 34px; height: 34px; border-radius: 8px; font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-3); }
.nav-toggle { display: none; }

.container { max-width: 1440px; margin: 0 auto; padding: 20px; }
h1.page { font-size: 20px; margin: 0 0 16px; }

/* ===== Flash / banners ===== */
.flash, .banner { padding: 11px 15px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.flash.ok, .banner.good { background: var(--green-soft); color: var(--green); border: 1px solid var(--green); }
.flash.error { background: var(--red-soft); color: var(--red); border: 1px solid var(--red); }
.banner.warn { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.banner.info { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }

/* ===== Stat tiles ===== */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 13px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.tile .value { font-size: 25px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.tile .value.green { color: var(--green); }
.tile .value.accent { color: var(--accent); }
.tile .value.amber { color: var(--amber); }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card .card-head { padding: 13px 18px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card .card-body { padding: 18px; }

/* ===== Forms ===== */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font: inherit; max-width: 100%;
}
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: var(--surface-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, monospace; line-height: 1.5; }
label { font-weight: 500; }

.btn { background: var(--accent); color: #fff; border: none; padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--accent-2); text-decoration: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.green { background: var(--green); }

/* help tooltip */
.help-i { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-3); color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; margin-left: 5px; position: relative; }
.help-i:hover::after {
  content: attr(data-tip); position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 11px; border-radius: 8px; font-size: 12px; font-weight: 400;
  width: max-content; max-width: 260px; line-height: 1.4; z-index: 50; box-shadow: var(--shadow-lg); white-space: normal; text-align: left;
}
.help { color: var(--muted); font-size: 12px; margin-top: 5px; }

/* ===== Filters ===== */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .f { display: flex; flex-direction: column; gap: 4px; }
.filters label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.searchbar { margin-bottom: 14px; }
.search-box { position: relative; width: 100%; }
.search-box input { width: 100%; font-size: 15px; padding: 13px 16px; border-radius: 10px; }
.search-drop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); overflow: hidden; }
.sd-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; color: var(--text); border-bottom: 1px solid var(--border); }
.sd-item:last-child { border-bottom: none; }
.sd-item:hover { background: var(--surface-2); text-decoration: none; }
.sd-label { font-weight: 600; }
.sd-price { color: var(--muted); font-variant-numeric: tabular-nums; }

/* one clean filter toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.toolbar .f { display: flex; flex-direction: column; gap: 4px; }
.toolbar .f label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.toolbar .f select, .toolbar .f input { min-width: 90px; }
.toolbar .f input { width: 96px; }
.toolbar .f.chk { justify-content: flex-end; padding-bottom: 9px; }
.toolbar .cbx { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.filter-actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.card-head.clickable { cursor: pointer; user-select: none; }
.card-head.clickable:hover { background: var(--surface-3); }
#filtChevron { display: inline-block; width: 14px; color: var(--muted); }
.bulkbar { display: inline-flex; align-items: center; gap: 10px; padding: 4px 10px; background: var(--accent-soft); border-radius: 8px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; background: var(--surface); }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb { width: 66px; height: 48px; object-fit: cover; border-radius: 7px; background: var(--surface-3); display: block; }
.thumb.ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.rank { color: var(--muted); font-weight: 800; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.buy { background: var(--green); color: #fff; }
.badge.pass { background: var(--surface-3); color: var(--muted); }
.badge.src { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.drop { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber); }
.badge.wf-new { background: var(--accent-soft); color: var(--accent); }
.badge.wf-watching { background: var(--amber-soft); color: var(--amber); }
.badge.wf-bought { background: var(--green-soft); color: var(--green); }
.badge.wf-passed { background: var(--surface-3); color: var(--muted); }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.ok { background: var(--green); }
.status-dot.expired, .status-dot.error { background: var(--red); }
.status-dot.unset, .status-dot.running { background: var(--amber); }

/* ===== Bars (reports) ===== */
.bar-row { display: grid; grid-template-columns: 140px 1fr 84px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bar { height: 22px; background: var(--accent); border-radius: 5px; min-width: 2px; }
.bar.green { background: var(--green); }
.bar.amber { background: var(--amber); }
.bar-row2 { display: grid; grid-template-columns: 92px 1fr 70px 90px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bar-row2 .barwrap { background: var(--surface-3); border-radius: 5px; }

/* ===== Deal detail ===== */
.grid2 { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; align-items: start; }
.grid2 > * { min-width: 0; }   /* let columns keep their fr ratio regardless of content */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 12px; }
.kv .k { color: var(--muted); }
.val-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(115px,1fr)); gap: 11px; }
.val-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.val-box .t { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.val-box .n { font-size: 20px; font-weight: 800; margin-top: 3px; font-variant-numeric: tabular-nums; }
.hero-profit { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.wf-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.wf-buttons .btn.active { outline: 2px solid var(--accent); }

/* ===== Settings layout ===== */
.settings-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
.settings-nav { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 10px 13px; border-radius: 9px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 9px; }
.settings-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.panel-head { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.panel-sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.form-row { margin-bottom: 15px; max-width: 560px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; max-width: 560px; }
.test-out { font-size: 12px; margin-top: 8px; min-height: 16px; }
.log { background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px; padding: 12px; font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; max-height: 380px; overflow: auto; }
.empty { text-align: center; color: var(--muted); padding: 46px 20px; }
.section-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px,1fr)); gap: 16px; }
details.guide { background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
details.guide summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.guide ol { margin: 10px 0 4px; padding-left: 20px; }
details.guide li { margin-bottom: 7px; line-height: 1.5; }
details.guide code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.pill { display: inline-block; background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; font-family: ui-monospace, monospace; font-size: 12px; margin: 2px; cursor: pointer; }
.pill:hover { border-color: var(--accent); color: var(--accent); }

/* docs */
.docs h2 { font-size: 18px; margin: 26px 0 8px; }
.docs h3 { font-size: 15px; margin: 18px 0 6px; }
.docs p, .docs li { color: var(--text); }
.docs code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; font-family: ui-monospace, monospace; font-size: 13px; }
.docs .step { display: flex; gap: 12px; margin-bottom: 12px; }
.docs .step .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.toc a { display: block; padding: 4px 0; }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 350px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 30px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .form-row { max-width: none; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .settings-nav a { white-space: nowrap; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  header.nav nav { display: none; position: absolute; top: 58px; left: 0; right: 0; background: var(--surface);
    flex-direction: column; padding: 8px; border-bottom: 1px solid var(--border); gap: 2px; box-shadow: var(--shadow-lg); }
  header.nav nav.open { display: flex; }
  header.nav nav a { padding: 12px; }
  .nav-toggle { display: inline-flex; }
  .chip.hide-sm { display: none; }
  th { position: static; }
  /* stacked table cards */
  table.responsive thead { display: none; }
  table.responsive tbody tr { display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; padding: 8px 12px; background: var(--surface); }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: none; padding: 6px 0; white-space: normal; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; text-align: left; }
  table.responsive td[data-label=""]::before { content: ""; }
  .thumb { width: 100%; height: 160px; }
}

/* ===== Extra polish + new components ===== */
header.nav { box-shadow: var(--shadow); }
.tile { position: relative; overflow: hidden; }
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .55; }
.tile:nth-child(1)::before { background: var(--green); }
.tile:nth-child(2)::before { background: var(--green); }
.tile:nth-child(3)::before { background: var(--accent); }
.tile:nth-child(4)::before { background: var(--amber); }
thead th { background: var(--surface-2); }
.card-head { background: var(--surface-2); border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }

/* pagination */
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 16px; flex-wrap: wrap; }
.pager a, .pager span.cur, .pager span.gap { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; }
.pager a:hover { background: var(--surface-2); text-decoration: none; border-color: var(--accent); }
.pager span.cur { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager span.gap { border: none; background: transparent; }
.pager .info { color: var(--muted); font-weight: 400; margin: 0 8px; }

/* row delete */
.row-del { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.row-del:hover { color: var(--red); background: var(--red-soft); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }

/* deal detail sections */
.dsec { margin-bottom: 16px; }
.dsec .dsec-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 6px 0 10px; }
.dsec .dsec-h .tag { font-size: 10px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); letter-spacing: .3px; }
.fieldgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.fieldgrid .fld { background: var(--surface); padding: 9px 12px; }
.fieldgrid .fld .fk { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
.fieldgrid .fld .fv { font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; word-break: break-word; }

/* telegram preview */
.tg-preview { background: #0e1621; border-radius: 12px; padding: 16px; }
.tg-bubble { background: #182533; color: #e9edf0; border-radius: 12px 12px 12px 4px; padding: 10px 13px; max-width: 340px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.tg-bubble b { color: #fff; }
.tg-bubble a { color: #6ab7ff; }

/* tour */
#tourOverlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 2000; display: none; }
#tourOverlay.on { display: block; }
.tour-hole { position: absolute; border-radius: 10px; box-shadow: 0 0 0 4px var(--accent), 0 0 0 9999px rgba(0,0,0,.55); transition: all .25s ease; }
.tour-pop { position: absolute; z-index: 2001; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 16px; width: 300px; box-shadow: var(--shadow-lg); }
.tour-pop h4 { margin: 0 0 6px; font-size: 15px; }
.tour-pop p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.tour-pop .row { display: flex; justify-content: space-between; align-items: center; }
.tour-pop .steps { color: var(--muted); font-size: 12px; }
