/* Trading Titans Admin — Modern Flat UI */

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9ef;
  --border-strong: #d1d9e6;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --gold: #d97706;
  --gold-soft: #fffbeb;
  --diamond: #7c3aed;
  --diamond-soft: #f5f3ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 252px;
  --header-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
a:hover { color: var(--accent-hover); }

code {
  font-size: 0.8em;
  padding: 0.15em 0.4em;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--text-secondary);
}

/* ── Shell ─────────────────────────────────────────────────── */

.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  padding: 0 1rem;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.mobile-header .brand-mini {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.menu-toggle:hover { background: var(--surface-2); }

.menu-toggle svg { width: 20px; height: 20px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(15, 23, 42, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.25rem 0.5rem 1.25rem;
  margin-bottom: 0.5rem;
}

.sidebar-logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-logo-text span {
  display: block;
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-link.active svg { opacity: 1; }

.user-card {
  margin-top: auto;
  padding: 0.85rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.user-card-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.user-card-role {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
  margin-top: 2px;
}

.user-card .btn-ghost {
  margin-top: 0.65rem;
  width: 100%;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem;
  padding-bottom: calc(1.75rem + var(--safe-bottom));
}

/* ── Page header ───────────────────────────────────────────── */

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.page-header p {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.page-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.page-header .back-link:hover { color: var(--accent); }

/* ── KPI grid ──────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.kpi .label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.kpi .value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 0.35rem;
  color: var(--text);
}

.kpi.gold .value { color: var(--gold); }
.kpi.diamond .value { color: var(--diamond); }

.kpi-accent .value { color: var(--accent); }

/* ── Cards & panels ────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 1.25rem;
}

.card-body-flush {
  padding: 0;
}

.card-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Legacy: card without header */
.card > h3:first-child {
  margin: 0;
  padding: 1rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.card > h3:first-child + *:not(.table-wrap) {
  padding: 1.25rem;
}

.card > .table-wrap {
  margin: 0;
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.filter-bar input[type="search"] {
  flex: 1;
  min-width: 160px;
}

/* ── Tables ────────────────────────────────────────────────── */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--surface-2);
}

th, td {
  padding: 0.75rem 1.25rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: #fafbfc; }

.table-meta {
  padding: 0.75rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  font-size: 0.875rem;
}

.table-wrap table.detail-table {
  min-width: 0;
}

.detail-table th {
  width: 36%;
  font-size: 0.8125rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
  font-weight: 500;
  background: transparent;
}

.detail-table td {
  word-break: break-word;
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  min-height: 36px;
  font-weight: 500;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  min-height: 32px;
  padding: 0 0.65rem;
  font-size: 0.8125rem;
}

/* ── Forms ─────────────────────────────────────────────────── */

input, select, textarea {
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0 0.85rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  max-width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder { color: var(--muted); }

label.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

label.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
}

label.checkbox-inline input { min-height: auto; width: auto; }

form.inline,
.form-stack {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-stack .field { flex: 1; min-width: 140px; }

.select-inline {
  min-width: 140px;
}

/* ── Badges & alerts ───────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-gold { background: var(--gold-soft); color: var(--gold); }
.badge-diamond { background: var(--diamond-soft); color: var(--diamond); }
.badge-warn { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--text-secondary); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-info {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #bfdbfe;
}

.empty-state {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Charts ────────────────────────────────────────────────── */

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-card .card-body { padding-top: 0.5rem; }

.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.chart-toolbar select {
  min-width: 120px;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
  margin-top: 0.5rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
  max-width: 120px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* ── Login ─────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.login-brand .sidebar-logo-mark {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.login-card .subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.login-form .field { margin-top: 1.1rem; }

.login-form .btn-primary {
  width: 100%;
  margin-top: 1.5rem;
  min-height: 44px;
}

.login-hint {
  margin-top: 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* ── Action blocks ─────────────────────────────────────────── */

.action-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.action-panel .divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.hint-text {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.35rem;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--muted); }

/* ── Page tabs (subscriptions) ─────────────────────────────── */

.page-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.page-tab {
  flex: 1;
  min-width: fit-content;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.page-tab:hover { background: var(--surface-2); color: var(--text); }

.page-tab.active {
  background: var(--accent);
  color: #fff;
}

.page-tab .tab-count {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.2);
}

.page-tab:not(.active) .tab-count {
  background: var(--surface-2);
  color: var(--muted);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.countdown-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: 0.02em;
}

.countdown-timer.soon { color: var(--gold); }
.countdown-timer.critical { color: var(--danger); }
.countdown-timer.ok { color: var(--success); }
.countdown-timer.overdue { color: var(--danger); }

tr.row-overdue td { background: #fef2f2 !important; }
tr.row-soon td { background: #fffbeb !important; }

.kick-note {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  padding: 0.75rem 1.25rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
}

/* ── Mobile ────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .layout {
    flex-direction: column;
    padding-top: var(--header-height);
  }

  .sidebar-overlay { display: block; }

  body.nav-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), 88vw);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
    padding-top: calc(var(--header-height) + 0.5rem);
  }

  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open { overflow: hidden; }

  .sidebar-logo { display: none; }

  .main {
    padding: 1.25rem 1rem;
    padding-bottom: calc(1.25rem + var(--safe-bottom));
  }

  .chart-row { grid-template-columns: 1fr; }

  .filter-bar,
  form.inline {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar > *,
  form.inline > *:not(label) {
    width: 100%;
  }

  label.checkbox-inline { width: 100%; }

  .kpi-grid { grid-template-columns: 1fr 1fr; }

  th, td { padding: 0.65rem 1rem; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .main { padding: 1.5rem; }
}
