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

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

:root {
  --primary: #7c3aed;
  --primary-dark: #5b21b6;
  --accent: #1a6fab;
  --text: #e8edf5;
  --text-muted: rgba(232, 237, 245, 0.5);
  --bg: #07111f;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-sidebar: #060e1a;
  --border: rgba(255, 255, 255, 0.08);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-w: 240px;
  --font: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
}

/* ── Sidebar ────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-badge {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  font-family: var(--mono);
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px; font-weight: 700;
  letter-spacing: -0.02em;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg-card-hover); color: var(--text); }
.nav-item.active { background: rgba(124, 58, 237, 0.15); color: var(--primary); }
.nav-item.active .nav-icon { color: var(--primary); }

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

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

.nav-item-danger:hover { background: rgba(220, 38, 38, 0.1); color: #f87171; }

/* ── Main layout ────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0; /* prevent flex item from expanding beyond viewport */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0;
  background: rgba(7, 17, 31, 0.95);
  backdrop-filter: blur(8px);
  z-index: 50;
}

.hamburger {
  display: none;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 20px; cursor: pointer;
  padding: 4px;
}

.topbar-title {
  font-size: 14px; font-weight: 600;
  flex: 1;
}

.topbar-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600;
  font-family: var(--mono);
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 20px;
}

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

/* ── Page header ────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h1 {
  font-size: 22px; font-weight: 800;
  letter-spacing: -0.02em;
}

.page-header p {
  font-size: 13px; color: var(--text-muted);
  margin-top: 2px;
}

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-ghost {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--text); }

.btn-danger {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: #f87171;
}
.btn-danger:hover { background: rgba(220, 38, 38, 0.2); }

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

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: border-color 0.15s;
}

.stat-card:hover { border-color: rgba(124, 58, 237, 0.3); }

.stat-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-family: var(--mono);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px; font-weight: 900;
  font-family: var(--mono);
  line-height: 1;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card.stat-yes .stat-value { background: none; -webkit-text-fill-color: #34d399; }
.stat-card.stat-no .stat-value { background: none; -webkit-text-fill-color: #f87171; }
.stat-card.stat-pending .stat-value { background: none; -webkit-text-fill-color: #fbbf24; }

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

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

.card-title {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  font-family: var(--mono); color: var(--text-muted);
}

/* ── Tables ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Table is always at least full width, but grows wider than its container
   when content demands it — table-wrap scrolls horizontally */
.table-wrap table { width: max-content; min-width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-family: var(--mono);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--bg-card-hover); }

.td-primary { font-weight: 600; }
.td-mono { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  font-family: var(--mono); letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-sent { background: rgba(59, 130, 246, 0.12); color: #60a5fa; }
.badge-yes { background: rgba(5, 150, 105, 0.12); color: #34d399; }
.badge-no { background: rgba(220, 38, 38, 0.12); color: #f87171; }
.badge-error { background: rgba(217, 119, 6, 0.12); color: #fbbf24; }
.badge-active { background: rgba(5, 150, 105, 0.12); color: #34d399; }
.badge-inactive { background: rgba(107, 114, 128, 0.12); color: #9ca3af; }
.badge-economic { background: rgba(26, 111, 171, 0.15); color: #60a5fa; }
.badge-dinero { background: rgba(124, 58, 237, 0.15); color: #a78bfa; }
.badge-warning { background: rgba(217, 119, 6, 0.15); color: #fbbf24; }

/* ── Alerts / Flash ─────────────────────────── */
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  margin-bottom: 16px;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-success { background: rgba(5, 150, 105, 0.1); border: 1px solid rgba(5, 150, 105, 0.25); color: #34d399; }
.alert-error { background: rgba(220, 38, 38, 0.1); border: 1px solid rgba(220, 38, 38, 0.25); color: #f87171; }
.alert-warning { background: rgba(217, 119, 6, 0.1); border: 1px solid rgba(217, 119, 6, 0.3); color: #fbbf24; }
.alert-info { background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.25); color: #60a5fa; }

/* ── Forms ──────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  font-family: var(--mono);
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="email"],
input[type="number"],
select,
textarea {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

select { appearance: none; cursor: pointer; }
textarea { resize: vertical; min-height: 90px; font-family: var(--font); }

.form-hint {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--mono);
}

.form-section {
  margin-bottom: 28px;
}

.form-section-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--primary); font-family: var(--mono);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.token-field {
  display: flex; gap: 8px; align-items: center;
}

.token-field input { font-family: var(--mono); font-size: 12px; flex: 1; }

/* ── Login page ─────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
}

.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
}

.login-logo .logo-badge { width: 44px; height: 44px; font-size: 14px; }
.login-logo .logo-text { font-size: 18px; font-weight: 800; }

.login-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }

/* ── Filters ────────────────────────────────── */
.filter-bar {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
}

.filter-bar select {
  width: auto; min-width: 160px;
}

/* ── Empty state ────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px;
}

.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.3; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text-muted); }
.empty-sub { font-size: 13px; color: var(--text-muted); opacity: 0.6; margin-top: 4px; }

/* ── Sidebar overlay (mobile) ───────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
}

/* ── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slide-in */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }

  /* Spacing */
  .topbar { padding: 0 16px; gap: 10px; }
  .page-content { padding: 16px; }

  /* Page header: stack title + action button */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header > .btn { width: 100%; justify-content: center; }

  /* Card headers: wrap when cramped */
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* Stat cards: 2 columns */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Forms: single column */
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }
  .token-field { flex-direction: column; }

  /* Filter bar: stack */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select,
  .filter-bar .btn { width: 100%; }

  /* Tables scroll horizontally — no size reductions needed */
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .login-card { margin: 16px; padding: 28px; }
  .topbar-badge { display: none; }
}

/* ── Utilities ──────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--mono); font-size: 12px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.actions { display: flex; gap: 6px; align-items: center; }
