@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');

/* Same "warm minimalist" theme as the public landing page (almond
   background, slate accents, glass-card panels) - intentionally one
   theme only for now, no dark mode, to match it exactly. */
:root {
  --bg: #fdfcfb;
  --card: rgba(255, 255, 255, 0.8);
  --card-solid: #ffffff;
  --border: rgba(226, 232, 240, 0.8);
  --text: #2d3748;
  --muted: #64748b;
  --accent: #4a5568;
  --accent-dark: #2d3748;
  --green: #059669;
  --red: #e11d48;
  --amber: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent-dark); }
a:hover { opacity: 0.8; }

/* Webhook URLs, secret tokens, and similar long unbroken strings shown in
   <code> (e.g. trading.html/admin_v11.html strategy cards) have no spaces
   to wrap at, so they overflowed their .card's edge instead of wrapping -
   force a mid-token break instead. */
code { word-break: break-all; overflow-wrap: break-word; }

/* ---------------------------------------------------------------------
   App shell: a persistent left sidebar (the pattern actual enterprise
   dashboards use - Stripe, Linear, Vercel, Salesforce Lightning, GitHub
   Settings) rather than a horizontal bar with hover/click dropdowns.
   Primary nav is always visible and scannable at a glance, grouped into
   labeled sections, with a clear active-page indicator - no menus to
   open before you can see where you are or where you can go.
   --------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 254px;
  flex-shrink: 0;
  background: var(--card-solid);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand { display: flex; flex-direction: column; text-decoration: none; padding: 1.35rem 1.35rem 1.15rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.brand-main { font-weight: 700; letter-spacing: -0.02em; color: var(--accent-dark); font-size: 1.15rem; }
.brand-tag { font-weight: 300; font-style: italic; color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 1.1rem 0.75rem; display: flex; flex-direction: column; gap: 1.5rem; }
.sidebar-section { display: flex; flex-direction: column; gap: 0.1rem; }
.sidebar-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a0aec0;
  padding: 0 0.65rem;
  margin: 0 0 0.45rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.52rem 0.65rem;
  border-radius: 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
  position: relative;
}
.sidebar-link svg { width: 17px; height: 17px; flex-shrink: 0; color: #a0aec0; transition: color 0.12s ease; }
.sidebar-link:hover { background: rgba(74, 85, 104, 0.07); opacity: 1; }
.sidebar-link.active { background: rgba(45, 55, 72, 0.07); color: var(--accent-dark); font-weight: 600; }
.sidebar-link.active svg { color: var(--accent-dark); }
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -0.75rem;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-dark);
}

.sidebar-footer { flex-shrink: 0; border-top: 1px solid var(--border); padding: 0.85rem; display: flex; flex-direction: column; gap: 0.55rem; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s ease;
}
.link-button:hover { color: var(--accent-dark); }

/* Kite connection status - a small pill chip (dot + label), not plain
   colored text, so it reads as a status indicator rather than a stray
   piece of text. */
.kite-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.kite-pill-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.kite-pill.connected { background: rgba(5, 150, 105, 0.1); color: var(--green); }
.kite-pill.connected .kite-pill-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15); }
.kite-pill.disconnected { background: rgba(225, 29, 72, 0.08); color: var(--red); }
.kite-pill.disconnected .kite-pill-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.12); }

/* Account menu, pinned to the sidebar footer (Slack/Notion/Linear
   pattern) - a native <details> so it needs no JS, styled as a proper
   panel that opens upward (it's at the bottom of the screen) rather
   than a floating caret dropdown. */
.nav-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-dark);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-account { position: relative; }
.sidebar-account summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.5rem;
  transition: background 0.12s ease;
}
.sidebar-account summary::-webkit-details-marker { display: none; }
.sidebar-account summary:hover { background: rgba(74, 85, 104, 0.07); }
.sidebar-account-name { flex: 1; font-size: 0.86rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-account-caret { width: 14px !important; height: 14px !important; color: #a0aec0 !important; transition: transform 0.15s ease; }
.sidebar-account[open] .sidebar-account-caret { transform: rotate(180deg); }

.sidebar-account-panel {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--accent-dark);
  border-radius: 0.65rem;
  box-shadow: 0 -12px 32px rgba(45, 55, 72, 0.16);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  z-index: 60;
  animation: sidebar-panel-in 0.15s ease;
}
@keyframes sidebar-panel-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.sidebar-account-panel a, .sidebar-account-panel .link-button {
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 0.45rem;
  white-space: nowrap;
  text-align: left;
  font-size: 0.86rem;
  color: var(--text);
  text-decoration: none;
}
.sidebar-account-panel a:hover, .sidebar-account-panel .link-button:hover { background: rgba(74, 85, 104, 0.08); color: var(--accent-dark); }
.sidebar-account-panel .inline-form { display: block; }
.sidebar-account-panel .inline-form .link-button { width: 100%; }
.sidebar-account-divider { height: 1px; background: var(--border); margin: 0.35rem 0.2rem; }

/* Unauthenticated sidebar (login/register) - same shell, simple links */
.sidebar-nav > a.sidebar-link { padding: 0.55rem 0.65rem; }

.app-main { flex: 1; min-width: 0; }

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 90;
}
.mobile-brand { font-weight: 700; letter-spacing: -0.02em; color: var(--accent-dark); font-size: 1.05rem; }

.nav-burger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card-solid);
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.nav-burger:hover { background: rgba(74, 85, 104, 0.06); }
.nav-burger span { display: block; width: 16px; height: 2px; margin: 0 auto; background: var(--accent-dark); border-radius: 2px; }

.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  .sidebar.sidebar-open { transform: translateX(0); box-shadow: 12px 0 32px rgba(45, 55, 72, 0.18); }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 32, 44, 0.35);
    z-index: 95;
  }
  .sidebar-backdrop.show { display: block; }
}

main { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }

h1 { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; color: #1a202c; }
h2 { font-size: 1.2rem; font-weight: 700; margin-top: 2.25rem; color: #1a202c; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }

.card {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-width: 560px;
  box-shadow: 0 1px 3px rgba(45, 55, 72, 0.06);
}

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
input, textarea, select {
  background: #fbfaf9;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #a0aec0;
  box-shadow: 0 0 0 3px rgba(160, 174, 192, 0.25);
}

button {
  background: var(--accent-dark);
  color: white;
  border: none;
  border-radius: 0.5rem;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  align-self: flex-start;
  transition: opacity 0.2s ease;
}
button:hover { opacity: 0.85; }
button:disabled { opacity: 0.35; cursor: not-allowed; }

/* Small secondary/outline button variants - for row-level actions
   (Review, Remove) that shouldn't compete visually with a page's primary
   solid button, but still need to read as a real button rather than a
   plain link ("a lot of links, not professional" feedback). */
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 0.4rem;
  align-self: auto;
  white-space: nowrap;
}
a.btn-sm {
  text-decoration: none;
  transition: opacity 0.2s ease;
}
a.btn-sm:hover { opacity: 0.85; }
/* .btn-outline/.btn-danger-outline (below) always pair with .btn-sm in
   this app (no bare solid small anchor button exists) and must win over
   the a.btn-sm rule above - a compound "a.btn-sm" selector otherwise
   outranks a plain ".btn-outline" class selector in specificity
   regardless of source order, which silently rendered every small anchor
   button solid instead of outlined. Both variants set background/color
   explicitly here so they apply the same way to <a> and <button>. */
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: rgba(74, 85, 104, 0.07); opacity: 1; }
.btn-danger-outline {
  background: transparent;
  border: 1px solid rgba(225, 29, 72, 0.35);
  color: var(--red);
}
.btn-danger-outline:hover { background: rgba(225, 29, 72, 0.08); opacity: 1; }

/* Button loading state (disabled + spinner) applied by app.js on every
   form submit site-wide, plus an indeterminate progress bar injected
   next to it - so a slow action (e.g. a FIITrade scan) gives immediate,
   visible feedback and can't be double-clicked while in flight. No real
   percentage is shown since the backend doesn't report granular
   progress - an indeterminate bar is the honest way to say "working,
   no ETA" rather than fabricating a number. */
.btn-spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  margin-right: 0.45em;
  vertical-align: -0.15em;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.is-submitting { opacity: 0.6 !important; cursor: not-allowed !important; }
.progress-indeterminate {
  height: 3px;
  width: 100%;
  max-width: 240px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress-indeterminate-bar {
  height: 100%;
  width: 40%;
  background: var(--accent-dark);
  border-radius: 2px;
  animation: progress-indeterminate-slide 1.1s ease-in-out infinite;
}
@keyframes progress-indeterminate-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

.hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--red); }

/* Client-side password strength meter (register.html) - purely visual
   feedback as the user types. The real enforcement (length, character
   classes, common-password blocklist) happens server-side in
   security.py's validate_password_strength() and can't be bypassed by
   this bar reading "Strong". */
.password-strength-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 0.35rem; }
.password-strength-fill { height: 100%; width: 0; border-radius: 3px; transition: width 0.15s ease, background-color 0.15s ease; }
.password-strength-fill.weak { background: var(--red); }
.password-strength-fill.fair { background: var(--amber); }
.password-strength-fill.strong { background: var(--green); }
.password-strength-label { font-size: 0.85rem; margin-top: 0.25rem; display: block; }
.password-strength-label.weak { color: var(--red); }
.password-strength-label.fair { color: var(--amber); }
.password-strength-label.strong { color: var(--green); }

/* Flash messages: a fixed-position toast (top-right) instead of a banner
   at the top of the scrollable content area - the banner was routinely
   scrolled out of view by the time a redirect landed (e.g. clicking
   "Remove" on a row far down a long table), so the result of an action
   was invisible without manually scrolling back up. Auto-dismisses; a
   manual close button is available too. */
.flash-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
}
.flash {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--card-solid);
  box-shadow: 0 8px 24px rgba(45, 55, 72, 0.14);
  animation: flash-in 0.2s ease;
}
@keyframes flash-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.flash.flash-hide { animation: flash-out 0.2s ease forwards; }
@keyframes flash-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-6px); }
}
.flash-success { border-left: 3px solid var(--green); color: var(--green); }
.flash-error { border-left: 3px solid var(--red); color: var(--red); }
.flash-info { border-left: 3px solid var(--accent); color: var(--accent); }
.flash-message { flex: 1; }
.flash-close {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  align-self: flex-start;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.flash-close:hover { opacity: 1; }

.param {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.9rem 1.1rem;
  max-width: 720px;
  box-shadow: 0 1px 3px rgba(45, 55, 72, 0.05);
}
.param-header { display: flex; justify-content: space-between; align-items: center; }
.param-desc { color: var(--text); font-size: 0.9rem; margin: 0.4rem 0; }
.param-why { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0; }
.param-range { color: var(--accent-dark); font-size: 0.85rem; margin: 0.4rem 0 0.2rem; font-weight: 600; }
.toggle { flex-direction: row; align-items: center; gap: 0.4rem; }
.weight { flex-direction: row; align-items: center; gap: 0.4rem; margin-top: 0.4rem; }
.weight input { width: 80px; }

.data-table { width: 100%; border-collapse: collapse; margin-top: 1rem; background: var(--card); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 0.75rem; overflow: hidden; box-shadow: 0 1px 3px rgba(45, 55, 72, 0.05); }
.data-table th, .data-table td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; background: rgba(247, 250, 252, 0.6); }
.data-table tr:last-child td { border-bottom: none; }

/* Opt-in click-to-sort columns (see app.js's sortable-table wiring) -
   .sortable-col is added by JS only to headers with real text, so the
   Review/Remove action columns (empty <th>) never become "sortable". */
.sortable-table th.sortable-col { cursor: pointer; }
.sortable-table th.sortable-col:hover { color: var(--accent-dark); }
.sortable-table .sort-indicator { display: inline-block; width: 0.9em; opacity: 0.7; }

/* Tri-state PASS/FAIL/N/A rendering (see templating.py's passfail/
   passfail_class filters) - N/A gets a neutral color, deliberately
   distinct from FAIL's red, since "not enough data" isn't "checked and
   it's bad". */
.text-pass { color: var(--green); }
.text-fail { color: var(--red); }
.text-na { color: var(--muted); }

.status-ok { color: var(--green); }
.status-off { color: var(--red); }

/* Per-source report blocks (FIITrade signal page: Yahoo/Screener.in
   fundamentals, Kite/Yahoo technicals) - one block per data source,
   shown side by side, instead of a metric-oriented table - a reviewer
   can see everything one source reports in one place, and which source
   actually gates the pass/fail call via .source-block-tag. */
.source-block-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 0.75rem; }
.source-block {
  flex: 1 1 220px;
  background: rgba(74, 85, 104, 0.04);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.9rem 1.1rem;
}
.source-block p { margin: 0.35rem 0; font-size: 0.9rem; }
.source-block-title { font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-bottom: 0.6rem !important; }
.source-block-tag {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--accent-dark);
  background: rgba(74, 85, 104, 0.1);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  margin-left: 0.35rem;
}

.subscores span { display: inline-block; margin-right: 0.6rem; color: var(--muted); font-size: 0.8rem; }

.inline-form { display: flex; gap: 0.4rem; align-items: center; }

.pnl.positive, .status-ok { color: var(--green); }
.pnl.negative { color: var(--red); }

.badge { font-size: 0.7rem; padding: 0.15rem 0.55rem; border-radius: 999px; vertical-align: middle; font-weight: 600; }
.badge-paper { background: rgba(74, 85, 104, 0.12); color: var(--accent-dark); }
/* Kept as a warning tone, not green - LIVE means real orders/real money,
   and it should still read as "pay attention", not "all good". */
.badge-live { background: rgba(225, 29, 72, 0.12); color: var(--red); }

.info-box {
  background: rgba(74, 85, 104, 0.06);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.info-box-title { font-weight: 600; color: var(--accent-dark); margin: 0 0 0.5rem; font-size: 0.95rem; }
.term-list { margin: 0; }
.term-list dt { font-weight: 600; color: var(--accent-dark); margin-top: 0.6rem; font-size: 0.9rem; }
.term-list dt:first-child { margin-top: 0; }
.term-list dd { margin: 0.2rem 0 0; color: var(--text); font-size: 0.9rem; line-height: 1.5; }
