:root {
  --td-bg: #07110f;
  --td-panel: #0a1712;
  --td-border: #28443a;
  --td-muted: #9fb3aa;
  --td-text: #e9f3ee;
  --td-accent: #83dfb9;
  --td-accent-strong: #46c58e;
  --td-glow: #123a30;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 6% 0, var(--td-glow) 0, transparent 35%), var(--td-bg);
  color: var(--td-text);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px clamp(18px, 5vw, 72px);
  border-bottom: 1px solid #1c332b;
  background: #081410ed;
  backdrop-filter: blur(14px);
}

.portal-announcements {
  display: grid;
  flex: 0 0 auto;
  gap: 7px;
  width: calc(100% - 2 * clamp(18px, 5vw, 72px));
  max-width: 1600px;
  margin: 10px auto 0;
}
.portal-announcement-card {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 13px;
  border: 1px solid #345b49;
  border-radius: 10px;
  background: linear-gradient(100deg,#10271d,#0b1713);
  box-shadow: 0 6px 24px #0002;
}
.portal-announcement-card[data-severity="success"] { border-color:#317353; background:linear-gradient(100deg,#10291e,#0b1713); }
.portal-announcement-card[data-severity="warning"] { border-color:#80683a; background:linear-gradient(100deg,#292311,#11150f); }
.portal-announcement-card[data-severity="outage"] { border-color:#85454b; background:linear-gradient(100deg,#30181b,#171112); }
.portal-announcement-copy { display:grid; grid-template-columns:auto minmax(0,1fr); align-items:baseline; gap:3px 9px; min-width:0; }
.portal-announcement-type { color:#83dfb9; font-size:9px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; }
.portal-announcement-card[data-severity="warning"] .portal-announcement-type { color:#efcc7a; }
.portal-announcement-card[data-severity="outage"] .portal-announcement-type { color:#ff9ca5; }
.portal-announcement-copy strong { color:#ecf7f1; font-size:12px; }
.portal-announcement-copy p { grid-column:2; margin:0; color:#a9bdb3; font-size:11px; line-height:1.45; white-space:pre-wrap; overflow-wrap:anywhere; }
.portal-announcement-dismiss { display:grid; place-items:center; width:30px; height:30px; padding:0; border:1px solid #355346; border-radius:8px; background:#08140f; color:#b7c9c1; font:inherit; font-size:18px; cursor:pointer; }
.portal-announcement-dismiss:hover { border-color:#83dfb9; color:#ecf7f1; }
.portal-announcement-dismiss:disabled { opacity:.5; cursor:wait; }
body:has(> header) > .portal-announcements[hidden] { display:none !important; }
body:has(> header) > .portal-announcements:not([hidden]) { flex:0 0 auto; }

.app-brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 11px;
  color: #effaf4;
  text-decoration: none;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -.03em;
}

.paper-brand-badge, .live-brand-badge {
  margin-left: 7px;
  padding: 3px 7px;
  border: 1px solid #2d7964;
  border-radius: 99px;
  color: #83dfb9;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

body[data-mode="live"] .live-brand-badge {
  border-color: #9c6039;
  color: #f5a66b;
}

.app-brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #2d7964;
  border-radius: 12px;
  background: #123329;
  color: #72e3b7;
  font-size: 21px;
}

.app-brand-logo {
  display: block;
  width: 64px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
}

.app-mode-switch {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 3px;
  border: 1px solid #28443a;
  border-radius: 10px;
  background: #07110f;
}

.app-mode-switch a {
  padding: 7px 11px;
  border-radius: 7px;
  color: var(--td-muted);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

[data-live-mode][hidden] {
  display: none !important;
}

.app-mode-switch a[aria-current="true"] {
  background: #174331;
  color: #a2e9c5;
  box-shadow: inset 0 0 0 1px #327859;
}

.app-nav {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: clamp(8px, 1.6vw, 20px);
  overflow: visible;
  color: var(--td-muted);
  font-size: 12px;
}

.app-nav-link {
  flex: 0 0 auto;
  padding: 9px 2px;
  border-bottom: 2px solid transparent;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease;
}

.app-nav-link:hover,
.app-nav-link.active {
  border-bottom-color: var(--td-accent-strong);
  color: var(--td-accent);
}

.app-profile { position: relative; flex: 0 0 auto; }

.app-notifications { position: relative; flex: 0 0 auto; }
.app-notification-trigger {
  position: relative;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  border: 1px solid #315244;
  border-radius: 50%;
  background: #123329;
  color: var(--td-accent);
  cursor: pointer;
  list-style: none;
}
.app-notification-trigger::-webkit-details-marker { display: none; }
.app-notification-trigger::marker { content: ""; }
.app-notification-trigger:hover,
.app-notifications[open] .app-notification-trigger { border-color: var(--td-accent-strong); }
.app-notification-trigger svg { display: block; flex: 0 0 18px; width: 18px !important; height: 18px !important; max-width: 18px; max-height: 18px; }
.app-notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border: 1px solid var(--td-bg);
  border-radius: 99px;
  background: #ed626b;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.app-notification-panel {
  position: absolute;
  z-index: 31;
  top: calc(100% + 9px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: min(440px, calc(100vh - 100px));
  overflow: auto;
  border: 1px solid #315244;
  border-radius: 11px;
  background: var(--td-panel);
  box-shadow: 0 12px 32px #0009;
}
.app-notification-panel[hidden] { display: none !important; }
.app-notification-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border-bottom: 1px solid var(--td-border); background: var(--td-panel); color: var(--td-text); font-size: 12px; }
.app-notification-actions, .app-notification-item-actions { display:flex; align-items:center; gap:6px; }
.app-notification-head button, .app-notification-item-actions button, .app-notification-item-actions a { padding: 5px 7px; border: 1px solid var(--td-border); border-radius: 6px; background: transparent; color: var(--td-accent); font: inherit; font-size: 10px; text-decoration:none; cursor: pointer; }
.app-notification-head button.app-notification-icon-action { display:grid; width:29px; height:27px; padding:5px; place-items:center; }
.app-notification-icon-action svg { width:15px; height:15px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.app-notification-icon-action:hover:not(:disabled) { border-color:var(--td-accent-strong); background:#123329; }
.app-notification-icon-action:focus-visible { outline:2px solid var(--td-accent-strong); outline-offset:2px; }
.app-notification-icon-action:disabled { opacity:.55; cursor:wait; }
.app-notification-head button[aria-pressed="true"] { background:#123329; }
.app-notification-list { padding: 4px 12px; }
.app-notification-item { padding: 10px 0; border-bottom: 1px solid var(--td-border); color: var(--td-muted); font-size: 11px; line-height: 1.45; }
.app-notification-item:last-child { border-bottom: 0; }
.app-notification-item.unread { color: var(--td-text); }
.app-notification-item strong { display: block; color: var(--td-text); font-size: 11px; }
.app-notification-item time { display: block; margin-top: 3px; color: var(--td-muted); font-size: 9px; }
.app-notification-item-actions { margin-top:7px; }
.app-notification-empty { margin: 0; padding: 18px 0; color: var(--td-muted); font-size: 11px; }
.app-trade-toast { position: fixed; z-index: 100; top: 82px; right: 20px; width: min(360px, calc(100vw - 32px)); padding: 12px 14px; border: 1px solid #327859; border-radius: 10px; background: var(--td-panel); color: var(--td-text); box-shadow: 0 12px 32px #0009; font-size: 12px; line-height: 1.45; animation: app-toast-in .18s ease-out; }
.app-trade-toast strong { display: block; margin-bottom: 3px; color: var(--td-accent); }
@keyframes app-toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.app-profile-trigger {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  border: 1px solid #315244;
  border-radius: 50%;
  background: #123329;
  color: var(--td-accent);
  cursor: pointer;
  list-style: none;
}

.app-profile-trigger::-webkit-details-marker { display: none; }
.app-profile-trigger:hover,
.app-profile[open] .app-profile-trigger { border-color: var(--td-accent-strong); }
.app-profile-trigger svg { width: 19px; height: 19px; }

.app-profile-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 9px);
  right: 0;
  display: grid;
  min-width: 190px;
  padding: 6px;
  border: 1px solid #315244;
  border-radius: 11px;
  background: #0a1712;
  box-shadow: 0 12px 32px #0009;
}

.app-profile:not([open]) > .app-profile-menu { display: none; }
.app-profile-menu #userLabel { padding: 9px 10px; color: #83dfb9; font-size: 11px; }
.app-profile-menu a,
.app-profile-menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #d2e3da;
  font: inherit;
  font-size: 12px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.app-profile-menu a:hover,
.app-profile-menu button:hover { background: #174331; color: #a2e9c5; }
.app-profile-menu [hidden] { display: none !important; }
.app-profile-menu .app-mode-switch { display: flex; width: calc(100% - 16px); margin: 4px 8px 8px; }
.app-profile-menu .app-mode-switch a { display: block; flex: 1 1 100%; width: auto; padding: 7px 9px; text-align: center; }
.app-profile-menu .app-mode-switch a[aria-current="true"] { display: none; }

/* Keep desktop app pages inside the viewport below their header. */
@media (min-width: 1181px) and (min-height: 700px) {
  body:has(> header) {
    display: flex;
    height: 100dvh;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  body:has(> header) > header { flex: 0 0 auto; }

  body:has(> header) > main {
    flex: 1 1 auto;
    min-height: 0;
    margin: 12px auto !important;
    overflow: auto;
  }
}

@media (max-width: 700px) {
  .app-header { min-height: 64px; flex-wrap: wrap; gap: 8px 12px; padding: 8px 14px; }
  .portal-announcements { width:calc(100% - 28px); margin-top:8px; }
  .portal-announcement-card { align-items:start; padding:9px; }
  .portal-announcement-copy { grid-template-columns:1fr; gap:3px; }
  .portal-announcement-copy p { grid-column:1; }
  .app-brand { gap: 8px; font-size: 13px; }
  .app-brand-mark { width: 34px; height: 34px; }
  .app-mode-switch { margin-left: auto; }
  .app-nav { width: 100%; flex-wrap: wrap; justify-content: flex-start; gap: 4px 14px; padding: 2px 0; font-size: 11px; }
}

/* Let authenticated app pages, including the journal, use the full workspace width. */
@media (min-width: 701px) {
  body:has(> header) > main:not(.fyers-config-main):not(.membership-main):not(.settings-main) {
    width: 100% !important;
    max-width: none !important;
    padding-inline: clamp(18px, 3vw, 56px) !important;
  }
}

/* Keep the Journal at a readable width and use the page scrollbar. */
@media (min-width: 1181px) {
  body.journal-page:has(> header) {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.journal-page:has(> header) > main.journal-main {
    flex: none;
    min-height: auto;
    margin: 36px auto 56px !important;
    overflow: visible;
  }
}

/* Settings stays centered and uses the document scrollbar instead of filling the workspace. */
@media (min-width: 1181px) {
  body.settings-page:has(> header) {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.settings-page:has(> header) > main.settings-main {
    flex: none;
    min-height: auto;
    margin: 36px auto 56px !important;
    overflow: visible;
  }
}

/* Use the available desktop height on lower-resolution or scaled displays. */
@media (min-width: 1181px) and (max-height: 850px) {
  body:has(> header) > header { min-height: 54px !important; padding-block: 6px !important; }
  body:has(> header) > main { margin-block: 8px !important; }
  body:has(> header) > main h1 { margin-block: 4px !important; font-size: clamp(24px, 3vw, 34px) !important; }
  body:has(> header) > main .intro { margin-bottom: 12px !important; }
  body:has(> header) > main .panel,
  body:has(> header) > main .setting-card,
  body:has(> header) > main .card:not(.chart-card) { padding: 14px !important; }
  body:has(> header) > main .settings-grid,
  body:has(> header) > main .strategy-layout,
  body:has(> header) > main .content-grid { gap: 10px !important; }
}

/* Live mode uses a graphite and amber palette so it is unmistakable beside Paper mode. */
body[data-mode="live"] {
  --td-bg: #0b1018;
  --td-panel: #111923;
  --td-border: #3a4656;
  --td-muted: #a2adba;
  --td-text: #edf2f7;
  --td-accent: #ffc078;
  --td-accent-strong: #ef8954;
  --td-glow: #39261d;
  background: radial-gradient(ellipse at 6% 0, var(--td-glow) 0, transparent 36%), var(--td-bg);
  color: var(--td-text);
}

body[data-mode="live"] .app-header {
  border-bottom-color: #303b49;
  background: #0c131bee;
}

body[data-mode="live"] .app-brand-mark,
body[data-mode="live"] .app-profile-trigger {
  border-color: #815536;
  background: #2b211a;
  color: var(--td-accent);
}

body[data-mode="live"] .app-mode-switch {
  border-color: #3a4656;
  background: #0b1018;
}

body[data-mode="live"] .app-mode-switch a[aria-current="true"] {
  background: #38271d;
  color: #ffd5a0;
  box-shadow: inset 0 0 0 1px #98613b;
}

body[data-mode="live"] .app-nav-link:hover,
body[data-mode="live"] .app-nav-link.active {
  border-bottom-color: var(--td-accent-strong);
  color: var(--td-accent);
}

body[data-mode="live"] .app-profile-menu {
  border-color: #3a4656;
  background: #111923;
}

body[data-mode="live"] .app-profile-menu #userLabel { color: var(--td-accent); }
body[data-mode="live"] .app-profile-menu a:hover,
body[data-mode="live"] .app-profile-menu button:hover { background: #38271d; color: #ffd5a0; }

body[data-mode="live"] .card,
body[data-mode="live"] .strategy-sidebar {
  border-color: #344252;
  background: linear-gradient(145deg, #17212c, #101720);
}

body[data-mode="live"] .metric,
body[data-mode="live"] .backtest-metric,
body[data-mode="live"] .calendar,
body[data-mode="live"] .day-group {
  border-color: #344252;
  background-color: #111923;
}

body[data-mode="live"] .controls,
body[data-mode="live"] .strategy-page-tabs {
  border-color: #344252;
  background: #101720;
}

body[data-mode="live"] .fetch,
body[data-mode="live"] .control-button.start,
body[data-mode="live"] .button.primary,
body[data-mode="live"] .paper-form button,
body[data-mode="live"] .paper-exit-form button,
body[data-mode="live"] .order-exit button,
body[data-mode="live"] .journal-form button {
  border-color: #ef8954;
  background: #ef8954;
  color: #1b120d;
}

body[data-mode="live"] .fetch:hover,
body[data-mode="live"] .button.primary:hover { background: #ffa96f; }

body[data-mode="live"] .interval[aria-pressed="true"],
body[data-mode="live"] .order-tab[aria-selected="true"],
body[data-mode="live"] .strategy-page-tabs button[aria-selected="true"],
body[data-mode="live"] .backtest-controls button[aria-pressed="true"],
body[data-mode="live"] .paper-subtabs button[aria-selected="true"],
body[data-mode="live"] .config-tab[aria-selected="true"] {
  border-color: #98613b;
  background: #38271d;
  color: #ffd5a0;
}

body[data-mode="live"] .interval:hover,
body[data-mode="live"] .strategy-link:hover,
body[data-mode="live"] .strategy-link.active {
  border-color: #98613b;
  background: #2b211a;
  color: #ffd5a0;
}

body[data-mode="live"] .status.ready,
body[data-mode="live"] .status.connected,
body[data-mode="live"] .paper-only-badge,
body[data-mode="live"] .badge {
  border-color: #98613b;
  background: #38271d;
  color: #ffd5a0;
}

body[data-mode="live"] .spot-summary,
body[data-mode="live"] .strike-list,
body[data-mode="live"] .app-mode-switch,
body[data-mode="live"] .backtest-metric {
  border-color: #344252;
}

body[data-mode="live"] .spot-summary .atm strong,
body[data-mode="live"] .strike-pick.active,
body[data-mode="live"] .config-tab[aria-selected="true"] { color: var(--td-accent); }

body[data-mode="live"] .strike-pick.active,
body[data-mode="live"] .strike-pick:hover { border-color: var(--td-accent-strong); background: #38271d; }

body[data-mode="live"] input:focus,
body[data-mode="live"] select:focus { border-color: var(--td-accent-strong); box-shadow: 0 0 0 3px #ef895426; }

body[data-mode="live"] .table th,
body[data-mode="live"] .table td,
body[data-mode="live"] .step,
body[data-mode="live"] .sidebar-note,
body[data-mode="live"] .paper-subtabs,
body[data-mode="live"] .spot-summary,
body[data-mode="live"] .strike-row { border-color: #2b3745; }

/* Fyers setup uses a centered column but keeps normal viewport scrolling. */
@media (min-width: 1181px) {
  body:has(> header):has(> main.fyers-config-main) {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:has(> header) > main.fyers-config-main {
    flex: none;
    min-height: auto;
    margin: 36px auto 56px !important;
    overflow: visible;
  }
}
