/* ==========================================================================
   TelegramTrading — Design System
   ========================================================================== */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Brand */
  --brand: #4f6df5;
  --brand-dark: #3d54d6;
  --brand-light: #eef1ff;

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 76px;
  --sidebar-bg: #101528;
  --sidebar-bg-active: #1a2140;
  --sidebar-text: #aab2d5;
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.06);

  /* Topbar */
  --topbar-height: 68px;
  --topbar-bg: #ffffff;

  /* Surfaces */
  --page-bg: #f4f6fb;
  --card-bg: #ffffff;
  --card-border: #e9ecf5;
  --card-shadow: 0 1px 2px rgba(20, 24, 51, 0.04), 0 8px 24px -12px rgba(20, 24, 51, 0.10);

  /* Text */
  --text-primary: #1b1f3b;
  --text-secondary: #6b7290;
  --text-muted: #98a0c3;

  /* Status */
  --up: #16a34a;
  --down: #e11d48;
  --warn: #d97706;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page-bg: #0b0e1a;
    --card-bg: #12162a;
    --card-border: #232a4a;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
    --topbar-bg: #12162a;
    --text-primary: #eef0fb;
    --text-secondary: #a4abcf;
    --text-muted: #6c7397;
    --brand-light: rgba(79, 109, 245, 0.15);
  }
}

:root[data-theme="dark"] {
  --page-bg: #0b0e1a;
  --card-bg: #12162a;
  --card-border: #232a4a;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --topbar-bg: #12162a;
  --text-primary: #eef0fb;
  --text-secondary: #a4abcf;
  --text-muted: #6c7397;
  --brand-light: rgba(79, 109, 245, 0.15);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font-sans);
  background-color: var(--page-bg);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

a {
  color: var(--brand);
}

code, pre {
  font-family: var(--font-mono);
}

.text-muted {
  color: var(--text-muted) !important;
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1030;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.25rem 1.25rem;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.05rem;
  flex-shrink: 0;
  box-shadow: 0 4px 10px -2px rgba(79, 109, 245, 0.6);
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem 0.85rem;
}

.sidebar-section-label {
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #5c6493;
  padding: 0.9rem 0.6rem 0.4rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
  transition: background-color 0.15s ease, color 0.15s ease;
  position: relative;
}

.sidebar-nav .nav-link i {
  font-size: 1.05rem;
  width: 1.3rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
}

.sidebar-nav .nav-link.active::before {
  content: "";
  position: absolute;
  left: -0.85rem;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}

.sidebar-nav .nav-badge {
  margin-left: auto;
}

.sidebar-footer {
  padding: 0.9rem 1rem 1.1rem;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.78rem;
  color: #5c6493;
}

.sidebar-footer .badge {
  width: 100%;
  justify-content: center;
  font-size: 0.72rem;
  white-space: normal;
  line-height: 1.3;
}

/* ---- Main column ---- */

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0;
  color: var(--text-primary);
}

.sidebar-toggle-btn {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: none;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn:hover {
  background: var(--brand-light);
  color: var(--brand);
}

.topbar-spacer {
  flex: 1 1 auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--brand);
  border-color: var(--brand);
}

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  border-radius: 999px;
  padding: 0.3rem 0.9rem 0.3rem 0.3rem;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.app-content {
  padding: 1.75rem;
  flex: 1 1 auto;
}

.app-footer {
  padding: 1rem 1.75rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--card-border);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9, 11, 24, 0.55);
  z-index: 1025;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-shell.sidebar-open .app-sidebar {
    transform: translateX(0);
  }
  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
  }
  .app-main {
    margin-left: 0;
  }
  .sidebar-toggle-btn {
    display: inline-flex;
  }
}

/* ==========================================================================
   Page header
   ========================================================================== */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.2rem;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0;
}

/* ==========================================================================
   Cards, KPIs, tables
   ========================================================================== */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--card-border);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 1rem 1.25rem;
  color: var(--text-primary);
}

.card-body {
  padding: 1.25rem;
}

.kpi-card {
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100%;
}

.kpi-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.kpi-icon.i-blue { background: rgba(79, 109, 245, 0.12); color: var(--brand); }
.kpi-icon.i-green { background: rgba(22, 163, 74, 0.12); color: var(--up); }
.kpi-icon.i-red { background: rgba(225, 29, 72, 0.12); color: var(--down); }
.kpi-icon.i-amber { background: rgba(217, 119, 6, 0.12); color: var(--warn); }
.kpi-icon.i-purple { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }

.kpi-label {
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.kpi-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.table {
  color: var(--text-primary);
  --bs-table-bg: transparent;
}

.table > :not(caption) > * > * {
  padding: 0.7rem 1rem;
  border-bottom-color: var(--card-border);
}

.table thead th {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.table tbody tr {
  transition: background-color 0.12s ease;
}

.table-hover tbody tr:hover {
  background-color: var(--brand-light);
}

.table-clickable tbody tr {
  cursor: pointer;
}

.symbol-cell {
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}

.side-long {
  color: var(--up);
  font-weight: 700;
}

.side-short {
  color: var(--down);
  font-weight: 700;
}

.pnl-pos {
  color: var(--up);
  font-weight: 700;
}

.pnl-neg {
  color: var(--down);
  font-weight: 700;
}

/* ==========================================================================
   Badges, buttons, forms, alerts
   ========================================================================== */

.badge {
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.4em 0.75em;
}

.btn {
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background-color: var(--brand);
  border-color: var(--brand);
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn-outline-primary {
  color: var(--brand);
  border-color: var(--brand);
}

.btn-outline-primary:hover {
  background-color: var(--brand);
  border-color: var(--brand);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.2rem rgba(79, 109, 245, 0.25);
}

.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: var(--card-border);
  background-color: var(--card-bg);
  color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand);
}

.form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.alert {
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}

.list-group-item {
  background-color: transparent;
  border-color: var(--card-border);
  color: var(--text-primary);
}

.dropdown-menu {
  border-radius: var(--radius-md);
  border-color: var(--card-border);
  box-shadow: var(--card-shadow);
}

.pagination .page-link {
  border-radius: var(--radius-sm);
  margin: 0 2px;
  color: var(--text-primary);
  border-color: var(--card-border);
}

.pagination .page-item.active .page-link {
  background-color: var(--brand);
  border-color: var(--brand);
}

hr {
  border-color: var(--card-border);
}

/* ==========================================================================
   Landing page (anonymous Home/Index)
   ========================================================================== */

.landing-hero {
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
}

.landing-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--brand-light);
  color: var(--brand);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  margin-bottom: 1.25rem;
}

.landing-hero h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin-bottom: 1rem;
}

.landing-hero p.lead {
  color: var(--text-secondary);
  max-width: 620px;
  margin: 0 auto 2rem;
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-mono { font-family: var(--font-mono); }
.fw-800 { font-weight: 800; }
.shadow-soft { box-shadow: var(--card-shadow); }
.rounded-lg { border-radius: var(--radius-lg) !important; }

@media (min-width: 768px) {
  html { font-size: 15px; }
}
