/* ============ RESET & VARIABLES ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-sidebar: #141620;
  --bg-input: #232636;
  --border: #2a2d3a;
  --border-light: #363950;
  --text: #e4e6ef;
  --text-dim: #8b8fa7;
  --text-muted: #5c6078;
  --accent: #e8952e;
  --accent-hover: #f0a840;
  --accent-dim: rgba(232, 149, 46, 0.15);
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.12);
  --blue: #60a5fa;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 180ms ease;
}

html { font-size: 14px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============ LAYOUT ============ */
#app { display: flex; min-height: 100vh; }

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

/* ============ SIDEBAR ============ */
.sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.sidebar-logo span { font-size: 1.4rem; }

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

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.sidebar-nav a:hover { background: var(--bg-input); color: var(--text); }
.sidebar-nav a.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.sidebar-nav .nav-icon { font-size: 1.15rem; width: 24px; text-align: center; }

.sidebar-section {
  padding: 8px 12px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 8px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user { font-size: 0.85rem; color: var(--text-dim); font-weight: 500; }

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-body);
  transition: var(--transition);
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  padding: 24px 28px;
  overflow-x: auto;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ============ LOGIN PAGE ============ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: var(--bg);
}

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

.login-box h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-align: center;
  color: var(--accent);
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 28px;
  font-size: 0.9rem;
}

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  transition: var(--transition);
  outline: none;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #000;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid transparent; }
.btn-danger:hover { border-color: var(--red); }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-xs { padding: 4px 8px; font-size: 0.78rem; }

.error-msg {
  background: var(--red-dim);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.success-msg {
  background: var(--green-dim);
  color: var(--green);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.toggle-link {
  text-align: center;
  margin-top: 16px;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.toggle-link a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.card-title { font-size: 1rem; font-weight: 700; }

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar select, .toolbar input {
  padding: 7px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  outline: none;
}

.toolbar select:focus, .toolbar input:focus {
  border-color: var(--accent);
}

/* ============ SPREADSHEET TABLE ============ */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
}

.grid-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  white-space: nowrap;
  width: 100%;
  min-width: max-content;
}

.grid-table th, .grid-table td {
  padding: 5px 10px;
  border: 1px solid var(--border);
  text-align: right;
}

.grid-table th {
  background: #b8651a;
  color: #fff;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 0.76rem;
}

.grid-table .col-bm {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
  background: #1f2230;
  min-width: 130px;
  font-weight: 600;
  color: var(--accent);
}

.grid-table th.col-bm {
  z-index: 4;
  background: #b8651a;
  color: #fff;
}

.grid-table .row-total td {
  background: #3d2a0e;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.82rem;
}

.grid-table .row-total .col-bm { background: #3d2a0e; color: var(--accent); }

.grid-table .row-delta td { background: #1a1f2e; font-weight: 600; }
.grid-table .row-delta-pct td { background: #1a1f2e; font-size: 0.74rem; }

.grid-table .row-header th { font-size: 0.73rem; }

.grid-table .val-pos { color: var(--green); }
.grid-table .val-neg { color: var(--red); }
.grid-table .val-zero { color: var(--text-muted); }

.grid-table tbody tr:hover td { background: rgba(232, 149, 46, 0.06); }
.grid-table tbody tr:hover .col-bm { background: rgba(232, 149, 46, 0.12); }

.grid-table .row-total:hover td,
.grid-table .row-delta:hover td,
.grid-table .row-delta-pct:hover td { background: inherit; }

/* ============ BOOKMAKER MANAGER ============ */
.bm-list { display: flex; flex-direction: column; gap: 6px; }

.bm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.bm-item .bm-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bm-item .bm-name { flex: 1; font-weight: 600; font-size: 0.92rem; }
.bm-item .bm-order { color: var(--text-muted); font-size: 0.8rem; font-family: var(--font-mono); }
.bm-item .bm-inactive { opacity: 0.4; }
.bm-actions { display: flex; gap: 6px; }

/* ============ BALANCE ENTRY ============ */
.balance-grid {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 8px;
  align-items: center;
}

.balance-grid .bm-label {
  font-weight: 600;
  font-size: 0.92rem;
  padding: 6px 0;
}

.balance-grid input {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  text-align: right;
  outline: none;
  width: 100%;
}

.balance-grid input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* ============ DASHBOARD ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.chart-container h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text-dim);
}

.chart-container canvas { width: 100% !important; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.stat-card .stat-change {
  font-size: 0.82rem;
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  min-width: 380px;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal h2 {
  font-size: 1.15rem;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-logo span { display: block; }
  .sidebar-logo { justify-content: center; padding: 16px 0; }
  .sidebar-logo:not(span) { display: none; }
  .sidebar-nav a { justify-content: center; padding: 10px; }
  .sidebar-nav a .nav-label { display: none; }
  .sidebar-section { display: none; }
  .sidebar-user { display: none; }
  .main-content { padding: 16px; }
  .stat-cards { grid-template-columns: 1fr; }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.25s ease; }

/* ============ LOADING ============ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }
