:root {
  --bg-primary: #080e1e;
  --bg-secondary: #0c1428;
  --bg-card: #111b33;
  --bg-input: #0d162d;
  --bg-hover: #1a2a4a;
  --text-primary: #e8edf5;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #1e2d4a;
  --accent-blue: #3b82f6;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-yellow: #eab308;
  --accent-purple: #a855f7;
  --accent-cyan: #06b6d4;
  --radius: 16px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Login */
.screen { min-height: 100vh; }
.screen.hidden { display: none !important; }
#login-screen { display: flex; align-items: center; justify-content: center; }
#dashboard-screen { display: flex; flex-direction: column; }

.login-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  margin: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-icon { font-size: 3rem; color: var(--accent-blue); margin-bottom: 12px; }
.login-header h1 { font-size: 1.5rem; font-weight: 700; }
.login-header p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

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

.login-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: var(--transition);
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.setup-form { margin-top: 20px; }
.setup-form hr { border: none; border-top: 1px solid var(--border-color); margin-bottom: 16px; }

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent-blue);
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-offset {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-username {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-normal { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.badge-offset { background: rgba(234,179,8,0.15); color: var(--accent-yellow); }
.badge-scale { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.badge-freeze { background: rgba(168,85,247,0.15); color: var(--accent-purple); }
.badge-jump { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-warp { background: rgba(168,85,247,0.15); color: var(--accent-purple); }
.badge-custom { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-mode { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-offset { background: rgba(234,179,8,0.15); color: var(--accent-yellow); }
.badge-scale { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.badge-freeze { background: rgba(168,85,247,0.15); color: var(--accent-purple); }
.badge-jump { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-reset { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.badge-unfreeze { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.badge-normal { background: rgba(34,197,94,0.15); color: var(--accent-green); }

/* Dashboard layout */
#dashboard-screen { height: 100vh; }
.dashboard-container {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-nav { padding: 12px 8px; flex: 1; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
}

.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: rgba(59,130,246,0.12);
  color: var(--accent-blue);
}

.sidebar-link i { width: 18px; text-align: center; font-size: 0.95rem; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
}

.server-info { line-height: 1.6; }
.server-info small { display: block; color: var(--text-muted); font-size: 0.75rem; }

/* Main content */
.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-width: 1200px;
}

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

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

.tab-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.stat-primary .stat-icon { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.stat-success .stat-icon { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.stat-info .stat-icon { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.stat-warning .stat-icon { background: rgba(234,179,8,0.15); color: var(--accent-yellow); }
.stat-danger .stat-icon { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.stat-secondary .stat-icon { background: rgba(148,163,184,0.15); color: var(--text-secondary); }

.stat-body { flex: 1; min-width: 0; }
.stat-label { display: block; font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 2px; }
.stat-value { display: block; font-size: 1.15rem; font-weight: 700; font-family: var(--font-mono); }

/* Time display */
.time-display-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
}

.time-display-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.time-display-header h3 {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.time-display-values {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.time-value {
  flex: 1;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 12px 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  text-align: center;
}

.time-value-manipulated {
  color: var(--accent-yellow);
  border-color: rgba(234,179,8,0.3);
}

.time-diff {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 8px;
  font-family: var(--font-mono);
}

/* Control cards */
.control-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.control-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.control-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-btn {
  flex: 1;
  min-width: 100px;
}

.mode-btn.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 8px;
}

.input-group input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-mono);
}

.input-group input:focus { outline: none; border-color: var(--accent-blue); }

.input-suffix {
  padding: 10px 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.quick-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

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

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-blue); color: white; }
.btn-primary:hover { background: #2563eb; }

.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background: var(--border-color); }

.btn-success { background: var(--accent-green); color: white; }
.btn-success:hover { background: #16a34a; }

.btn-danger { background: var(--accent-red); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-warning { background: var(--accent-yellow); color: #000; }
.btn-warning:hover { background: #d97706; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

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

.btn-block { width: 100%; }

/* Tables */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

tbody td {
  padding: 10px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

/* Settings */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

/* Info rows */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.85rem;
}

.info-label { color: var(--text-secondary); }
.info-value { font-weight: 600; }

/* Clocks */
.clocks-container {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  justify-content: center;
}

.clock-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.clock-card h4 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.clock-card canvas {
  display: block;
  margin: 0 auto;
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease;
}

.toast.success { background: rgba(34,197,94,0.2); border: 1px solid rgba(34,197,94,0.3); color: var(--accent-green); }
.toast.error { background: rgba(239,68,68,0.2); border: 1px solid rgba(239,68,68,0.3); color: var(--accent-red); }
.toast.info { background: rgba(59,130,246,0.2); border: 1px solid rgba(59,130,246,0.3); color: var(--accent-blue); }
.toast.warning { background: rgba(234,179,8,0.2); border: 1px solid rgba(234,179,8,0.3); color: var(--accent-yellow); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }
  .nav-status { display: none; }
  .nav-username { display: none; }

  .dashboard-container {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 260px;
  }

  .sidebar.open { transform: translateX(0); }

  .main-content {
    padding: 16px;
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }

  .stat-value { font-size: 1rem; }
  .time-display-values { flex-direction: column; }
  .time-display-header { flex-direction: column; gap: 4px; }

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

  .clocks-container { flex-direction: column; align-items: center; }

  .mode-buttons { flex-direction: column; }
  .mode-btn { min-width: unset; }

  .tab-header { flex-direction: column; align-items: flex-start; gap: 8px; }

  table { font-size: 0.8rem; }
  thead th { padding: 8px 10px; font-size: 0.7rem; }
  tbody td { padding: 8px 10px; }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); width: 100%; max-width: 480px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 16px 20px; }
.modal-body .form-group { margin-bottom: 12px; }
.modal-body label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 4px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--border-color);
}
.input-full {
  width: 100%; padding: 8px 12px; background: var(--bg-input);
  color: var(--text-primary); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); font-size: 0.9rem;
}
.input-full:focus { outline: none; border-color: var(--accent-blue); }
.modal-body select.input-full { cursor: pointer; }

/* Schedule/Policy tables */
#schedules-table code,
#policies-table code {
  font-family: var(--font-mono); font-size: 0.85rem;
  background: var(--bg-input); padding: 2px 6px; border-radius: 4px;
}
#schedules-table input[type="checkbox"],
#policies-table input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-green);
}