:root {
  --primary: var(--primary-color, #0F6E56);
  --secondary: var(--secondary-color, #042C53);
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --text: #1A2230;
  --text-muted: #6B7785;
  --border: #E2E8F0;
  --success: #16A34A;
  --warning: #F59E0B;
  --error: #DC2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.10);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--secondary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo, .sidebar-logo-placeholder {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
.sidebar-logo { object-fit: contain; background: transparent; }
.sidebar-title { font-size: 15px; font-weight: 600; }

.sidebar-nav { display: flex; flex-direction: column; padding: 12px 8px; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.12);
  border-radius: 6px;
  font-size: 12px; font-weight: 700;
}
.nav-label { font-weight: 500; }

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

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.menu-toggle {
  display: none;
  background: none; border: none;
  font-size: 22px; cursor: pointer;
  color: var(--text);
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-logo { height: 32px; }

.content { padding: 24px; flex: 1; }

/* ---------- Typography ---------- */
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 20px; }

/* ---------- Status banner ---------- */
.status-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}
.status-online { background: #E8F7EF; color: #0B6B3A; border: 1px solid #B8E8CB; }
.status-offline { background: #FEE8E8; color: #9B1C1C; border: 1px solid #FBCACA; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.8s infinite;
}
.status-meta { margin-left: auto; opacity: 0.8; font-size: 13px; }
.status-error { display: block; width: 100%; font-size: 13px; opacity: 0.85; margin-top: 4px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 currentColor; }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.value-positive { color: var(--success); }
.value-negative { color: var(--error); }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2 { font-size: 16px; font-weight: 600; }

/* ---------- Config grid ---------- */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.config-grid > div { display: flex; flex-direction: column; gap: 2px; }
.config-key { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.config-val { font-size: 15px; font-weight: 600; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  background: #EEF2F6;
  color: var(--text-muted);
}
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-muted { background: #EEF2F6; color: var(--text-muted); }
.badge-active { background: var(--primary); color: #fff; }
.badge-open { background: #FEF3C7; color: #92400E; }
.badge-closed { background: #E0E7FF; color: #3730A3; }
.badge-rejected { background: #FEE2E2; color: #991B1B; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #FAFBFC;
}
.data-table tbody tr:hover { background: #F8FAFC; }
.empty-row { text-align: center; color: var(--text-muted); padding: 24px; }
.dir-buy { color: var(--success); font-weight: 600; }
.dir-sell { color: var(--error); font-weight: 600; }

/* ---------- Settings ---------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.settings-form .form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,110,86,0.15);
}
input[type="color"] {
  width: 48px; height: 38px;
  padding: 2px; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; background: #fff;
}
.color-text { margin-top: 6px; }
.form-check { display: flex; align-items: center; gap: 10px; }
.form-check label { margin: 0; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-block { width: 100%; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FBCACA; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }

/* ---------- Auth pages ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.auth-brand {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; margin-bottom: 24px;
}
.auth-logo {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
}
.auth-brand h1 { font-size: 20px; font-weight: 600; color: var(--text); }
.auth-form .form-group { margin-bottom: 16px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-muted); }
.auth-foot a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-foot a:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 16px; }
  .kpi-value { font-size: 22px; }
  .form-row { flex-direction: column; }
}
