/* ═══════════════════════════════════════════════════════════════════════════
   Cosmo Trader — Main stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #21262d;
  --border:      #30363d;
  --text:        #c9d1d9;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --green:       #3fb950;
  --green-dim:   #1a3d22;
  --red:         #f85149;
  --red-dim:     #3d1a1a;
  --yellow:      #d29922;
  --yellow-dim:  #3d2e00;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0, 0, 0, .4);
  --nav-height:  56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── Login page ──────────────────────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1c2a3e 0%, var(--bg) 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon { font-size: 32px; color: var(--accent); }
.login-logo h1 { font-size: 22px; font-weight: 600; margin-top: 8px; }
.login-logo .tagline { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Shared form inputs ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .2s;
}
.form-group input:focus   { border-color: var(--accent); }
.form-group input:disabled { opacity: .5; cursor: not-allowed; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 4px solid;
}
.alert-error { background: var(--red-dim);    border-color: var(--red);    color: var(--red); }
.alert-info  { background: var(--yellow-dim); border-color: var(--yellow); color: var(--yellow); }

/* ── Login button ────────────────────────────────────────────────────────── */
.btn-login {
  width: 100%;
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity .2s;
}
.btn-login:hover { opacity: .85; }

/* ── Top nav ─────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--nav-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
}
.topnav-brand .logo-icon { color: var(--accent); font-size: 18px; }

.topnav-right { display: flex; align-items: center; gap: 14px; }

.clock {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-open    { background: var(--green-dim);  color: var(--green);  border: 1px solid var(--green); }
.badge-closed  { background: var(--red-dim);    color: var(--red);    border: 1px solid var(--red); }
.badge-waiting { background: var(--yellow-dim); color: var(--yellow); border: 1px solid var(--yellow); }
.badge-holiday { background: var(--red-dim);    color: var(--red);    border: 1px solid var(--red); opacity: 0.75; }
.badge-warn    { background: var(--yellow-dim); color: var(--yellow); border: 1px solid var(--yellow); font-size: 11px; }

/* ── Market closed banner ────────────────────────────────────────────────── */
.market-closed-banner {
  background: var(--yellow-dim);
  border-bottom: 1px solid var(--yellow);
  color: var(--yellow);
  text-align: center;
  padding: 10px 24px;
  font-size: 13px;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 24px 40px; }
.section   { margin-top: 32px; }
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Stats grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color .3s;
}
.stat-card.positive { border-left: 3px solid var(--green); }
.stat-card.negative { border-left: 3px solid var(--red); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-card.positive .stat-value { color: var(--green); }
.stat-card.negative .stat-value { color: var(--red); }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* "Fetching…" placeholder shown before the broker responds */
.stat-pending { font-size: 14px; color: var(--text-muted); font-weight: 400; }

/* ── Live trade banner ───────────────────────────────────────────────────── */
/* 4-column layout for the live banner */
.stats-grid--live {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
/* "Live Trading" badge card */
.stat-card--live-badge {
  border-left: 3px solid var(--accent, #3b82f6);
}
.live-mode-label {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent, #3b82f6);
  letter-spacing: .5px;
}

/* ── Live dot ────────────────────────────────────────────────────────────── */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(63, 185, 80, .4);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(63, 185, 80, .4); }
  70%  { box-shadow: 0 0 0 8px rgba(63, 185, 80, 0); }
  100% { box-shadow: 0 0 0 0   rgba(63, 185, 80, 0); }
}

/* ── Position cards ──────────────────────────────────────────────────────── */
.position-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
  transition: border-color .3s;
}
.position-card:hover { border-color: var(--accent); }

.position-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.position-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.position-meta  { font-size: 13px; color: var(--text-muted); }

.stock-badge {
  background: var(--accent);
  color: #0d1117;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
}

.right-badge {
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}
.right-badge.call { background: var(--green-dim); color: var(--green); border: 1px solid var(--green); }
.right-badge.put  { background: var(--red-dim);   color: var(--red);   border: 1px solid var(--red); }

/* ── TradingView button ───────────────────────────────────────────────────── */
.tv-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;           /* push to the right of the title row */
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #2962ff;
  background: rgba(41, 98, 255, 0.10);
  border: 1px solid rgba(41, 98, 255, 0.30);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tv-btn:hover {
  background: rgba(41, 98, 255, 0.20);
  border-color: rgba(41, 98, 255, 0.60);
  text-decoration: none;
}
.tv-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ── Square-Off button ───────────────────────────────────────────────────── */
.sqoff-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #ef5350;
  background: rgba(239, 83, 80, 0.10);
  border: 1px solid rgba(239, 83, 80, 0.30);
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.sqoff-btn:hover {
  background: rgba(239, 83, 80, 0.22);
  border-color: rgba(239, 83, 80, 0.65);
}
.sqoff-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* ── Confirmation modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}
.modal-body {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}
.modal-detail {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  letter-spacing: 0.01em;
}
.modal-warn {
  margin-top: 12px;
  font-size: 12px;
  color: #ef5350;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}
.modal-btn {
  padding: 8px 20px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.modal-btn-cancel:hover { background: var(--bg); }
.modal-btn-confirm {
  background: #ef5350;
  border: 1px solid #ef5350;
  color: #fff;
}
.modal-btn-confirm:hover  { background: #e53935; }
.modal-btn-confirm:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Toast notifications ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  max-width: 380px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: #1b4332; color: #6ee7b7; border: 1px solid #065f46; }
.toast-error   { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.toast-info    { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.position-body { padding: 18px 20px; }

/* ── Price grid ──────────────────────────────────────────────────────────── */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.price-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 4px;
}
.price-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.price-value.positive { color: var(--green); }
.price-value.negative { color: var(--red); }
.live-ltp { color: var(--accent); }

/* ── Trend chart ─────────────────────────────────────────────────────────── */
.trend-section { margin-top: 4px; }
.trend-label   { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.trend-image-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.trend-img { width: 100%; display: block; }
.trend-placeholder {
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Styled "no chart" box — replaces plain text placeholder */
.trend-placeholder-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,.02);
  min-height: 80px;
}
.trend-placeholder-icon  { font-size: 28px; opacity: .5; }
.trend-placeholder-text  { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-sub  { font-size: 13px; margin-top: 8px; }

/* ── Tag list (watchlist) ────────────────────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer-version {
  font-size: 11px;
  opacity: 0.55;
  letter-spacing: 0.03em;
}

/* ── Live-update flash animations ────────────────────────────────────────── */
@keyframes flash-green {
  from { background: rgba(63, 185, 80, .18); }
  to   { background: transparent; }
}
@keyframes flash-red {
  from { background: rgba(248, 81, 73, .18); }
  to   { background: transparent; }
}
.flash-green { animation: flash-green .6s ease-out; }
.flash-red   { animation: flash-red   .6s ease-out; }

/* ── Avatar dropdown ─────────────────────────────────────────────────────── */
.avatar-menu { position: relative; }

.avatar-trigger {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 50%;
  transition: opacity .2s;
}
.avatar-trigger:hover { opacity: .85; }

.avatar-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  z-index: 300;
  overflow: hidden;
}
.avatar-menu.open .avatar-dropdown { display: block; }

.dropdown-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}
.dropdown-name  { font-size: 14px; font-weight: 600; }
.dropdown-uname { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.dropdown-divider { height: 1px; background: var(--border); }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  transition: background .15s;
}
.dropdown-item:hover         { background: var(--surface2); text-decoration: none; }
.dropdown-item.active        { color: var(--accent); background: var(--surface2); }
.dropdown-item-danger        { color: var(--red); }
.dropdown-item-danger:hover  { background: var(--red-dim); }

/* ── Avatar sizes ────────────────────────────────────────────────────────── */
.avatar,
.avatar-placeholder {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.avatar-sm,  .avatar-placeholder.avatar-sm  { width: 32px; height: 32px; font-size: 13px; }
.avatar-nav, .avatar-placeholder.avatar-nav { width: 30px; height: 30px; font-size: 12px; border: 2px solid var(--border); }

.avatar-placeholder {
  background: var(--surface2);
  border: 2px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .topnav        { padding: 0 14px; }
  .container     { padding: 16px 14px 32px; }
  .position-header { flex-direction: column; align-items: flex-start; }
  .stats-grid    { grid-template-columns: 1fr 1fr; }
}
