:root {
  --bg: #090e17;
  --surface: #111a28;
  --surface-2: #162234;
  --surface-3: #1d2d44;
  --border: #24354d;
  --border-strong: #324765;
  --text: #eaf1fb;
  --text-muted: #92a4bc;
  --text-faint: #62748c;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-border: rgba(59, 130, 246, 0.35);
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.15);
  --ok-border: rgba(16, 185, 129, 0.35);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --warn-border: rgba(245, 158, 11, 0.35);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --danger-border: rgba(239, 68, 68, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --font-heading: "Manrope", system-ui, -apple-system, sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

[data-theme="light"] {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #edf2f8;
  --surface-3: #e2eaf4;
  --border: #d4e0ee;
  --border-strong: #b8cbe0;
  --text: #141d2b;
  --text-muted: #576b85;
  --text-faint: #8a9bb2;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-border: rgba(37, 99, 235, 0.25);
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, 0.1);
  --ok-border: rgba(5, 150, 105, 0.25);
  --shadow: 0 4px 16px rgba(20, 29, 43, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 29, 43, 0.12);
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

*, *::before, *::after {
  box-sizing: border-box;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px 80px;
  overflow-x: hidden;
}

/* Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  margin-bottom: 18px;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}
.logo-box {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  user-select: none;
}
.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.4);
}
.logo-text h1 {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border-radius: 8px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulseGreen 2s infinite;
}

@keyframes pulseGreen {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Navigation Tabs (Vertical Stack / Menu) */
.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.tab-btn {
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14.5px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  transition: all 0.18s ease;
}
.tab-btn .tab-icon {
  font-size: 18px;
  width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tab-btn .tab-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab-btn .tab-arrow {
  font-size: 18px;
  color: var(--text-faint);
  opacity: 0.5;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.tab-btn:hover {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--border);
}
.tab-btn.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}
.tab-btn.active .tab-arrow {
  color: #ffffff;
  opacity: 1;
  transform: translateX(3px);
}

/* Cards & Layout */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.card-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Stat Box */
.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.stat-box .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 4px;
}
.stat-box .val {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
}
.stat-box .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border: 1px solid #3b82f6;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.5);
  transform: translateY(-1px);
}
.btn-success {
  background: linear-gradient(135deg, #059669, #047857);
  color: #fff;
  border: 1px solid #10b981;
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 7px;
}
.btn-block { width: 100%; }

/* Form Inputs */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.form-control {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.form-control {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

/* Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1.2;
}
.pill-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }

/* Progress Bar */
.progress-container {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  height: 20px;
  overflow: hidden;
  position: relative;
  margin: 12px 0;
}
.progress-bar-fill {
  background: linear-gradient(90deg, #3b82f6, #10b981);
  height: 100%;
  width: 0%;
  transition: width 0.4s ease;
  border-radius: 10px;
}
.progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Terminal Console */
.terminal {
  background: #080d14;
  border: 1px solid #1a293f;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #c9d8ec;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.6;
}
.terminal .line { margin-bottom: 2px; }
.terminal .time { color: #5a7394; margin-right: 6px; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-2);
  font-family: var(--font-heading);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  max-width: 480px;
  width: 90%;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}
.modal-backdrop.open .modal-box {
  transform: translateY(0);
}

/* Telegram Mini App & Mobile Layout Optimization */
@media (max-width: 640px) {
  .container {
    padding: 0 12px 60px;
  }
  .top-header {
    padding: 8px 0;
    margin-bottom: 14px;
  }
  .header-inner {
    padding: 0 12px;
  }
  .card {
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
  }
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .card-header .btn {
    width: 100%;
  }
  .form-control, textarea.form-control {
    font-size: 16px; /* Prevents auto-zoom in iOS Safari & Telegram Webview */
  }
  .pill {
    font-size: 11.5px;
    padding: 4px 8px;
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
}
