@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg-base:      #0d1117;
  --bg-surface:   #161b22;
  --bg-elevated:  #1c2230;
  --bg-hover:     #21273a;
  --border:       #30363d;
  --border-light: #21262d;

  --accent:       #00c896;
  --accent-dim:   rgba(0, 200, 150, 0.12);
  --accent-hover: #00e6aa;

  --blue:         #58a6ff;
  --blue-dim:     rgba(88, 166, 255, 0.12);
  --yellow:       #e3b341;
  --yellow-dim:   rgba(227, 179, 65, 0.12);
  --red:          #f85149;
  --red-dim:      rgba(248, 81, 73, 0.12);
  --purple:       #bc8cff;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  --sidebar-w: 240px;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), #00a37a);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: #0d1117;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-logo .logo-text {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.2;
}
.sidebar-logo .logo-sub {
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s ease;
  margin-bottom: 2px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.nav-item .nav-icon {
  width: 18px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.gateway-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  flex-shrink: 0;
}
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-dot.warning { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

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

.page-header {
  padding: 24px 32px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.page-header p {
  color: var(--text-secondary);
  font-size: 13px;
  padding-bottom: 20px;
}
.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
}

.page-body {
  padding: 28px 32px;
  flex: 1;
}

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

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card.blue::before  { background: var(--blue); }
.stat-card.yellow::before { background: var(--yellow); }
.stat-card.red::before   { background: var(--red); }
.stat-card.purple::before { background: var(--purple); }

.stat-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.stat-card .stat-icon {
  position: absolute;
  top: 16px; right: 16px;
  font-size: 28px;
  opacity: 0.12;
  color: var(--accent);
}
.stat-card.blue .stat-icon  { color: var(--blue); }
.stat-card.yellow .stat-icon { color: var(--yellow); }
.stat-card.red .stat-icon   { color: var(--red); }

/* ── Section Cards ──────────────────────────────────────────────────────────── */
.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}
.section-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.section-card-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.section-card-body {
  padding: 0;
}

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table thead th {
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody td {
  padding: 13px 16px;
  color: var(--text-primary);
  vertical-align: middle;
  font-size: 13.5px;
}
.data-table tbody tr.row-error  { background: var(--red-dim); }
.data-table tbody tr.row-success { background: transparent; }
.data-table tbody tr.row-consent { background: var(--accent-dim); }
.data-table .text-muted { color: var(--text-secondary); font-size: 12px; }
.data-table .mono { font-family: 'SF Mono', Consolas, monospace; font-size: 12px; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: var(--accent-dim);  color: var(--accent); }
.badge-blue   { background: var(--blue-dim);    color: var(--blue); }
.badge-yellow { background: var(--yellow-dim);  color: var(--yellow); }
.badge-red    { background: var(--red-dim);     color: var(--red); }
.badge-gray   { background: rgba(139,148,158,0.12); color: var(--text-secondary); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}
.form-label .required { color: var(--red); margin-left: 2px; }

.form-control, .form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control.mono { font-family: 'SF Mono', Consolas, monospace; font-size: 12px; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%238b949e' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 10px; padding-right: 30px; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}
.form-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.password-wrapper {
  position: relative;
}
.password-wrapper .form-control { padding-right: 40px; }
.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  transition: color 0.15s;
}
.password-toggle:hover { color: var(--text-primary); }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal-box { transform: translateY(0); }
.modal-box.modal-lg { max-width: 760px; }
.modal-box.modal-sm { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Auth Gate ──────────────────────────────────────────────────────────────── */
#auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card .logo-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--accent), #00a37a);
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; color: #0d1117; font-weight: 700;
  margin-bottom: 20px;
}
.auth-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.auth-card p { color: var(--text-secondary); font-size: 13px; margin-bottom: 24px; }

/* ── Alerts / Toasts ────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  min-width: 260px;
  max-width: 380px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn 0.25s ease;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
.toast-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.toast.success .toast-icon { color: var(--accent); }
.toast.error   .toast-icon { color: var(--red); }
.toast.info    .toast-icon { color: var(--blue); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ── Filter Bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }

/* ── Empty State ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; }

/* ── Loading ────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td {
  text-align: center;
  padding: 40px !important;
  color: var(--text-muted);
}

/* ── Utility ────────────────────────────────────────────────────────────────── */
.flex    { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 12px; }
.mt-1    { margin-top: 6px; }
.mt-2    { margin-top: 12px; }
.mb-2    { margin-bottom: 12px; }
.text-sm { font-size: 12px; }
.text-secondary { color: var(--text-secondary); }
.text-accent    { color: var(--accent); }
.text-red       { color: var(--red); }
.font-mono { font-family: 'SF Mono', Consolas, monospace; }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { min-width: 100%; }
}
