/* ============================================================
   Smart-IFE Admin Panel — Design System
   Linear/Vercel/Stripe aesthetic · Inter font
   ============================================================ */

/* ── Custom Properties ────────────────────────────────────────── */
:root {
  /* Brand */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* Neutral (light mode) */
  --bg:           #ffffff;
  --bg-subtle:    #f8fafc;
  --bg-muted:     #f1f5f9;
  --bg-elevated:  #ffffff;
  --border:       #e2e8f0;
  --border-muted: #f1f5f9;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;

  /* Sidebar */
  --sidebar-bg:   #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active:#ffffff;
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-border:rgba(255,255,255,0.06);
  --sidebar-w:    240px;

  /* Status */
  --green:   #22c55e;
  --green-bg:#f0fdf4;
  --red:     #ef4444;
  --red-bg:  #fef2f2;
  --yellow:  #f59e0b;
  --yellow-bg:#fffbeb;
  --blue:    #3b82f6;
  --blue-bg: #eff6ff;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast:   120ms ease;
  --t-base:   200ms ease;
  --t-slow:   350ms ease;
}

/* Dark mode */
[data-theme="dark"] {
  --bg:           #0d1117;
  --bg-subtle:    #161b22;
  --bg-muted:     #1c2128;
  --bg-elevated:  #21262d;
  --border:       #30363d;
  --border-muted: #21262d;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --text-faint:   #484f58;

  --sidebar-bg:   #010409;
  --sidebar-border: rgba(255,255,255,0.08);

  --green-bg: #0d2a1a;
  --red-bg:   #2a0d0d;
  --yellow-bg:#2a1f0d;
  --blue-bg:  #0d1a2a;
}

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

html { font-size: 14px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

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

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  border-right: 1px solid var(--sidebar-border);
  transition: transform var(--t-slow);
}

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

.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--brand-600);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.sidebar-logo-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--brand-400);
  background: rgba(99,102,241,0.15);
  border-radius: var(--r-full);
  padding: 1px 7px;
  margin-left: auto;
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  opacity: .4;
  padding: 12px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-active); }

.nav-item.active {
  background: rgba(99,102,241,.18);
  color: var(--sidebar-active);
}

.nav-item svg { opacity: .75; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--brand-600);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--r-full);
  padding: 0 7px;
  min-width: 20px;
  text-align: center;
  line-height: 18px;
}

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}

.sidebar-user:hover { background: var(--sidebar-hover); }

.avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--brand-600);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar-lg { width: 40px; height: 40px; font-size: 16px; }

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text); opacity: .6; }

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

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 40;
}

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

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Page ─────────────────────────────────────────────────────── */
.page { padding: 24px; flex: 1; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

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

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}

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

.card-title { font-size: 14px; font-weight: 600; }
.card-body  { padding: 20px; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t-fast), border-color var(--t-fast);
}

.stat-card:hover { box-shadow: var(--shadow-md); border-color: var(--brand-200); }

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-top: 6px;
  line-height: 1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary {
  background: var(--brand-600);
  color: #fff;
  border-color: var(--brand-600);
}
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); box-shadow: 0 0 0 3px rgba(99,102,241,.25); }

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

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

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

.btn-warning {
  background: var(--yellow-bg);
  color: #b45309;
  border-color: transparent;
}
.btn-warning:hover { background: var(--yellow); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 7px; }
.btn-icon.btn-sm { padding: 5px; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-control {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-control::placeholder { color: var(--text-faint); }

select.form-control { cursor: pointer; }

.form-hint { font-size: 11.5px; color: var(--text-faint); }
.form-error { font-size: 11.5px; color: var(--red); }

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

/* ── Table ────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

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

thead tr { border-bottom: 1px solid var(--border); }

th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-muted);
  color: var(--text);
}

tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--bg-subtle); }
tbody tr:last-child td { border-bottom: none; }

.td-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: var(--green-bg);  color: #16a34a; }
.badge-red    { background: var(--red-bg);    color: #dc2626; }
.badge-yellow { background: var(--yellow-bg); color: #d97706; }
.badge-blue   { background: var(--blue-bg);   color: #2563eb; }
.badge-gray   { background: var(--bg-muted);  color: var(--text-muted); }
.badge-brand  { background: var(--brand-100); color: var(--brand-700); }

[data-theme="dark"] .badge-green  { color: #4ade80; }
[data-theme="dark"] .badge-red    { color: #f87171; }
[data-theme="dark"] .badge-yellow { color: #fbbf24; }
[data-theme="dark"] .badge-blue   { color: #60a5fa; }
[data-theme="dark"] .badge-brand  { color: var(--brand-400); }

/* ── Search / Filter bar ──────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 380px;
}

.search-input svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.search-input input {
  padding-left: 34px;
}

/* ── Pagination ───────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border-muted);
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-controls { display: flex; gap: 4px; }

.page-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.page-btn:hover { background: var(--bg-muted); }
.page-btn.active { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.page-btn:disabled { opacity: .4; pointer-events: none; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in var(--t-slow) cubic-bezier(.34,1.56,.64,1) both;
}

.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }

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

.modal-title { font-size: 16px; font-weight: 700; }

.modal-body  { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-muted);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Toast notifications ──────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: all;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  font-size: 13px;
  animation: toast-in .25s cubic-bezier(.34,1.56,.64,1) both;
}

.toast.removing { animation: toast-out .2s ease both; }

.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-title { font-weight: 600; }
.toast-msg   { color: var(--text-muted); margin-top: 1px; }

.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }
.toast-warning { border-left: 3px solid var(--yellow); }

@keyframes toast-in  { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes toast-out { from { opacity:1; transform:translateX(0); }    to { opacity:0; transform:translateX(20px); } }

/* ── Skeleton loader ──────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-muted) 25%, var(--border-muted) 50%, var(--bg-muted) 75%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

.skeleton-text  { height: 14px; border-radius: 4px; }
.skeleton-title { height: 20px; border-radius: 4px; }
.skeleton-stat  { height: 60px; border-radius: var(--r-lg); }
.skeleton-row   { height: 44px; border-radius: var(--r-sm); }

/* ── Empty state ──────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  color: var(--text-faint);
}

.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-desc  { font-size: 13px; }

/* ── Progress / quota bars ────────────────────────────────────── */
.quota-bar { height: 6px; border-radius: var(--r-full); background: var(--bg-muted); overflow: hidden; }
.quota-fill { height: 100%; border-radius: var(--r-full); background: var(--brand-600); transition: width .5s ease; }
.quota-fill.warn    { background: var(--yellow); }
.quota-fill.danger  { background: var(--red); }

/* ── Divider ──────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-muted); margin: 16px 0; }

/* ── Utilities ────────────────────────────────────────────────── */
.flex    { display: flex; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }
.mt-4   { margin-top: 16px; }
.mt-6   { margin-top: 24px; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.w-full { width: 100%; }
.text-sm   { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.font-mono  { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only    { position: absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }

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

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  padding: 40px;
  animation: modal-in .4s cubic-bezier(.34,1.56,.64,1) both;
}

.login-logo {
  width: 48px; height: 48px;
  background: var(--brand-600);
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 24px;
}

.login-title { font-size: 22px; font-weight: 800; text-align: center; letter-spacing: -0.5px; }
.login-sub   { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: 4px; margin-bottom: 32px; }

/* ── Chart containers ─────────────────────────────────────────── */
.chart-wrapper { position: relative; }

/* ── Code / device IDs ────────────────────────────────────────── */
.device-id {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11.5px;
  background: var(--bg-muted);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid, .grid-2 { grid-template-columns: 1fr; }
  .form-grid-3, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
}

/* ── Transitions for Alpine x-show ──────────────────────────────── */
[x-cloak] { display: none !important; }

.fade-enter-active, .fade-leave-active { transition: opacity var(--t-base); }
.fade-enter-from, .fade-leave-to { opacity: 0; }
