/* Critical CSS Server — Dashboard (design v3) */

/* ─── Design System ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0b;
  --surface: #141416;
  --surface-hover: #1c1c1f;
  --border: #232326;
  --border-light: #2a2a2e;
  --text: #f5f5f7;
  --text-secondary: #8e8e93;
  --text-tertiary: #636366;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-subtle: rgba(99, 102, 241, 0.1);
  --green: #34d399;
  --green-subtle: rgba(52, 211, 153, 0.1);
  --red: #f87171;
  --red-subtle: rgba(248, 113, 113, 0.1);
  --amber: #fbbf24;
  --amber-subtle: rgba(251, 191, 36, 0.1);
  --blue: #60a5fa;
  --sidebar-width: 240px;
  --radius: 10px;
  --radius-sm: 6px;
}

.light-mode {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f0f2;
  --border: #e0e0e5;
  --border-light: #d4d4d9;
  --text: #1a1a2e;
  --text-secondary: #6b6b80;
  --text-tertiary: #9e9eb0;
  --accent: #4f46e5;
  --accent-hover: #6366f1;
  --accent-subtle: rgba(79, 70, 229, 0.08);
  --green: #10b981;
  --green-subtle: rgba(16, 185, 129, 0.08);
  --red: #ef4444;
  --red-subtle: rgba(239, 68, 68, 0.08);
  --amber: #f59e0b;
  --amber-subtle: rgba(245, 158, 11, 0.08);
  --blue: #3b82f6;
}

html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ─── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-box h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-box p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

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

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.sidebar-brand {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.sidebar-brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: -1px;
}

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

.nav-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item.active svg { opacity: 1; }

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

.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  margin-bottom: 8px;
}
.theme-toggle-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.theme-toggle-btn svg { width: 15px; height: 15px; }

.nav-item-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-item-footer:hover { background: var(--surface-hover); color: var(--text); }

.nav-item-footer .avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: white;
  flex-shrink: 0;
}

/* ─── Main ─── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 56px;
}

.top-bar h1 {
  font-size: 18px;
  font-weight: 600;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content {
  padding: 24px 32px;
}

/* ─── Page system ─── */
.page { display: none; }
.page.active { display: block; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--surface-hover); border-color: var(--text-tertiary); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger {
  background: var(--red-subtle);
  border-color: transparent;
  color: var(--red);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon.danger:hover { border-color: var(--red); color: var(--red); }

/* ─── Stats Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

/* ─── Table Card ─── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.table-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.table-header .actions { display: flex; gap: 8px; }

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

thead th {
  text-align: left;
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

tbody td {
  padding: 12px 20px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }

/* ─── Status Indicators ─── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.active, .status-dot.success { background: var(--green); }
.status-dot.revoked, .status-dot.error { background: var(--red); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-active, .badge-success { background: var(--green-subtle); color: var(--green); }
.badge-revoked, .badge-error { background: var(--red-subtle); color: var(--red); }

.domain-name {
  font-weight: 500;
  color: var(--accent-hover);
}

.key-display {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 400px; margin: 0 auto 20px; }

/* ─── Chart ─── */
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-container h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding-top: 10px;
}
.bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}
.bar {
  width: 100%;
  max-width: 32px;
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.3s;
  background: var(--accent);
  opacity: 0.7;
}
.bar.highlight { opacity: 1; background: var(--accent-hover); }
.bar-label {
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ─── Forms ─── */
.field-group {
  margin-bottom: 16px;
}
.field-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field-group input, .field-group select, .field-group textarea {
  width: 100%;
  max-width: 400px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  border-color: var(--accent);
}
.field-group textarea { min-height: 80px; resize: vertical; }

/* ─── Cards for settings/users etc ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  max-width: 600px;
}

/* ─── Filters ─── */
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.filters input, .filters select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.filters input:focus, .filters select:focus { border-color: var(--accent); }

/* ─── Pagination ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}
.pagination button {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.pagination button:hover { background: var(--surface-hover); color: var(--text); }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination span { font-size: 13px; color: var(--text-secondary); }

/* ─── Modal ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

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

/* ─── Flash Messages ─── */
#flash-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
}

.flash {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-success { background: var(--green-subtle); color: var(--green); border-color: var(--green); }
.flash-error { background: var(--red-subtle); color: var(--red); border-color: var(--red); }

/* ─── New Key Display ─── */
.new-key-box {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  word-break: break-all;
  margin-bottom: 12px;
}
.new-key-box .copy-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  flex-shrink: 0;
}
.new-key-box .copy-btn:hover { background: var(--accent-hover); }

/* ─── Danger zone ─── */
.danger-zone {
  border-color: rgba(248, 113, 113, 0.3);
}
.danger-zone h3 { color: var(--red); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand, .nav-item span, .nav-section, .nav-item-footer span { display: none; }
  .sidebar-header { padding: 16px 14px; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item.active::before { left: 0; }
  .nav-item-footer { justify-content: center; }
  .main-content { margin-left: 60px; }
  .top-bar, .content { padding-left: 16px; padding-right: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
