/* ==========================================================================
   IniChat Admin Panel — Styles
   Custom palette: clean slate neutrals + messaging blue accent
   ========================================================================== */

/* --- Design Tokens --- */
:root,
[data-theme='light'] {
  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Surfaces — cool slate */
  --color-bg: #f1f3f7;
  --color-surface: #ffffff;
  --color-surface-2: #f7f9fc;
  --color-surface-offset: #e8edf4;
  --color-surface-dynamic: #dde4ee;
  --color-divider: #e2e7ee;
  --color-border: #d4dbe6;

  /* Text */
  --color-text: #1a2233;
  --color-text-muted: #5a6678;
  --color-text-faint: #9aa5b8;
  --color-text-inverse: #ffffff;

  /* Primary — messaging blue */
  --color-primary: #016494;
  --color-primary-hover: #014f74;
  --color-primary-active: #013c5a;
  --color-primary-highlight: #d6e6f1;

  /* Semantic */
  --color-success: #1a7a3e;
  --color-success-highlight: #d4ecdc;
  --color-warning: #b5630a;
  --color-warning-highlight: #f5e4cc;
  --color-error: #c4234b;
  --color-error-highlight: #f4d4dd;
  --color-info: #016494;
  --color-info-highlight: #d6e6f1;

  /* Badge tier colors */
  --color-free: #5a6678;
  --color-free-bg: #e8edf4;
  --color-premium: #8b5e00;
  --color-premium-bg: #f5e9cc;
  --color-early: #6b2d8a;
  --color-early-bg: #e8dcf0;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Transitions */
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(26, 34, 51, 0.06);
  --shadow-md: 0 4px 12px rgba(26, 34, 51, 0.08);
  --shadow-lg: 0 12px 32px rgba(26, 34, 51, 0.12);

  /* Layout */
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --topbar-height: 64px;

  /* Fonts */
  --font-display: 'Cabinet Grotesk', 'Inter', sans-serif;
  --font-body: 'General Sans', 'Inter', system-ui, sans-serif;
}

[data-theme='dark'] {
  --color-bg: #0f131c;
  --color-surface: #161b26;
  --color-surface-2: #1a2030;
  --color-surface-offset: #1e2535;
  --color-surface-dynamic: #2a3346;
  --color-divider: #232a3a;
  --color-border: #2d3548;

  --color-text: #d8dee9;
  --color-text-muted: #8a93a5;
  --color-text-faint: #5c6478;
  --color-text-inverse: #0f131c;

  --color-primary: #3d9dd6;
  --color-primary-hover: #2b85bd;
  --color-primary-active: #1f6da0;
  --color-primary-highlight: #1a2a3a;

  --color-success: #4caf6f;
  --color-success-highlight: #1a3025;
  --color-warning: #d4903e;
  --color-warning-highlight: #2f2516;
  --color-error: #e85a7a;
  --color-error-highlight: #2f1820;
  --color-info: #3d9dd6;
  --color-info-highlight: #1a2a3a;

  --color-free: #8a93a5;
  --color-free-bg: #1e2535;
  --color-premium: #d4a93e;
  --color-premium-bg: #2f2516;
  --color-early: #b070d4;
  --color-early-bg: #2a1a35;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

img, svg { display: block; max-width: 100%; height: auto; }
ul[role='list'], ol[role='list'] { list-style: none; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; font-family: var(--font-display); font-weight: 700; }
p, li { text-wrap: pretty; }

::selection { background: color-mix(in oklab, var(--color-primary) 25%, transparent); color: var(--color-text); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }

/* Ensure hidden attribute always wins over display rules */
[hidden] { display: none !important; }

a, button, [role='button'], input, textarea, select {
  transition: color var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  white-space: nowrap;
  min-height: 40px;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn-primary:hover { background: var(--color-primary-hover); }

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

.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover { background: var(--color-surface-offset); border-color: var(--color-text-muted); }

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: color-mix(in oklab, var(--color-error) 30%, transparent);
}
.btn-danger:hover { background: var(--color-error-highlight); }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); min-height: 32px; }
.btn-block { width: 100%; }
.btn-icon { padding: var(--space-2); min-width: 36px; min-height: 36px; }

.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid color-mix(in oklab, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Login Screen --- */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--color-bg);
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-12);
  width: 100%;
  max-width: 420px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}
.login-logo { flex-shrink: 0; }
.login-title {
  font-size: var(--text-xl);
  color: var(--color-text);
}
.login-subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-8);
}

.login-form { display: flex; flex-direction: column; gap: var(--space-4); }

.form-field { display: flex; flex-direction: column; gap: var(--space-2); }
.form-field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], textarea, select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  min-height: 40px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-primary) 15%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--color-text-faint); }

textarea { resize: vertical; min-height: 80px; }

.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 44px; }
.toggle-password {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  padding: var(--space-1);
  display: flex;
}
.toggle-password:hover { color: var(--color-text); }

.login-error {
  color: var(--color-error);
  font-size: var(--text-sm);
  padding: var(--space-3);
  background: var(--color-error-highlight);
  border-radius: var(--radius-md);
}

/* --- Dashboard Layout --- */
.dashboard {
  display: flex;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: width var(--transition);
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-name,
.sidebar.collapsed .user-details,
.sidebar.collapsed #logout-btn span { display: none; }
.sidebar.collapsed .brand-logo { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .sidebar-footer { gap: var(--space-2); }
.sidebar.collapsed .user-info { justify-content: center; }
.sidebar.collapsed #logout-btn { justify-content: center; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  min-height: var(--topbar-height);
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--color-primary); overflow: hidden; }
.brand-logo { flex-shrink: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-text);
  white-space: nowrap;
}
.sidebar-toggle { color: var(--color-text-muted); padding: var(--space-1); display: flex; }
.sidebar-toggle:hover { color: var(--color-text); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--space-3); }
.sidebar-nav ul { display: flex; flex-direction: column; gap: var(--space-1); }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
.nav-item:hover { background: var(--color-surface-offset); color: var(--color-text); }
.nav-item.active {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  font-weight: 600;
}
.nav-item svg { flex-shrink: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow: hidden;
  min-width: 0;
}
#logout-btn { width: 100%; justify-content: flex-start; }
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.user-name { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main wrapper */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-wrapper { margin-left: var(--sidebar-collapsed); }

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: var(--text-xl); font-weight: 700; color: var(--color-text); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }
.theme-toggle {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}
.theme-toggle:hover { background: var(--color-surface-offset); color: var(--color-text); }

.mobile-menu-btn { display: none; padding: var(--space-2); color: var(--color-text); }

.main-content {
  flex: 1;
  padding: var(--space-6);
  overflow-x: auto;
}

/* --- Section --- */
.section { display: none; }
.section.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.section-header h2 { font-size: var(--text-lg); color: var(--color-text); }
.section-header p { font-size: var(--text-sm); color: var(--color-text-muted); }

.section-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* --- Cards (Resumen) --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-3);
}
.stat-icon.primary { background: var(--color-primary-highlight); color: var(--color-primary); }
.stat-icon.success { background: var(--color-success-highlight); color: var(--color-success); }
.stat-icon.warning { background: var(--color-warning-highlight); color: var(--color-warning); }
.stat-icon.info { background: var(--color-info-highlight); color: var(--color-info); }

.stat-label { font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-1); }
.stat-value { font-size: var(--text-xl); font-weight: 700; font-family: var(--font-display); color: var(--color-text); }
.stat-sub { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-1); }

/* --- Card / Panel --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.card-header h3 { font-size: var(--text-base); color: var(--color-text); }
.card-body { padding: var(--space-5); }

/* --- Table --- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
table.data-table {
  width: 100%;
  font-size: var(--text-sm);
}
.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-surface-2); }
.data-table .cell-mono { font-family: monospace; font-size: var(--text-xs); color: var(--color-text-muted); }
.data-table .cell-id { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .emoji-preview { font-size: 1.5rem; text-align: center; }

.table-scroll { max-height: 600px; overflow-y: auto; }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge-free { background: var(--color-free-bg); color: var(--color-free); }
.badge-premium { background: var(--color-premium-bg); color: var(--color-premium); }
.badge-early { background: var(--color-early-bg); color: var(--color-early); }
.badge-active { background: var(--color-success-highlight); color: var(--color-success); }
.badge-inactive { background: var(--color-surface-offset); color: var(--color-text-muted); }
.badge-emoji { background: var(--color-info-highlight); color: var(--color-info); }
.badge-animoji { background: var(--color-early-bg); color: var(--color-early); }
.badge-status-active { background: var(--color-success-highlight); color: var(--color-success); }
.badge-status-paused { background: var(--color-warning-highlight); color: var(--color-warning); }
.badge-status-cancelled { background: var(--color-error-highlight); color: var(--color-error); }
.badge-admin { background: var(--color-primary-highlight); color: var(--color-primary); }

/* --- Toggle Switch --- */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: var(--color-surface);
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--color-primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* --- Toolbar --- */
.toolbar {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.toolbar .search-box {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  position: relative;
}
.toolbar .search-box input { padding-left: 38px; }
.toolbar .search-box svg {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-faint);
}

/* --- Inline edit --- */
.inline-edit {
  background: transparent;
  border: 1px solid transparent;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  width: 100%;
  min-width: 60px;
}
.inline-edit:hover { border-color: var(--color-border); background: var(--color-surface-2); }
.inline-edit:focus { border-color: var(--color-primary); background: var(--color-surface-2); outline: none; }

select.inline-select {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  min-height: 32px;
  cursor: pointer;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 28, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
}
.modal-header h3 { font-size: var(--text-lg); color: var(--color-text); }
.modal-close {
  color: var(--color-text-muted);
  padding: var(--space-2);
  display: flex;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--color-surface-offset); color: var(--color-text); }
.modal-body { padding: var(--space-6); }
.modal-body .form-field { margin-bottom: var(--space-4); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 400px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.removing { animation: slideOut 0.2s ease forwards; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(100%); opacity: 0; } }
.toast-success { border-left: 3px solid var(--color-success); }
.toast-error { border-left: 3px solid var(--color-error); }
.toast-info { border-left: 3px solid var(--color-info); }
.toast-icon { flex-shrink: 0; margin-top: 2px; }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error .toast-icon { color: var(--color-error); }
.toast-info .toast-icon { color: var(--color-info); }
.toast-content { flex: 1; }
.toast-title { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); }
.toast-msg { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.toast-close { color: var(--color-text-faint); padding: 0; }
.toast-close:hover { color: var(--color-text); }

/* --- Loading / Empty --- */
.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  color: var(--color-text-muted);
}
.loading-state .spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--color-surface-offset);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: var(--space-4);
}
.empty-state svg { width: 48px; height: 48px; color: var(--color-text-faint); margin-bottom: var(--space-4); }
.empty-state h3 { color: var(--color-text); margin-bottom: var(--space-2); font-size: var(--text-base); }
.empty-state p { max-width: 36ch; font-size: var(--text-sm); }

.skeleton-row { height: 48px; background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-surface-dynamic) 50%, var(--color-surface-offset) 75%); background-size: 200% 100%; animation: shimmer 1.5s ease-in-out infinite; }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* --- Action buttons in tables --- */
.action-btns { display: flex; gap: var(--space-1); }
.action-btn {
  padding: var(--space-1);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  display: flex;
}
.action-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.action-btn.danger:hover { background: var(--color-error-highlight); color: var(--color-error); }

/* --- Responsive --- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: var(--sidebar-width); }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .brand-name,
  .sidebar.collapsed .user-details { display: block; }
  .main-wrapper { margin-left: 0; }
  .sidebar.collapsed ~ .main-wrapper { margin-left: 0; }
  .mobile-menu-btn { display: flex; }
  .main-content { padding: var(--space-4); }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .toast-container { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); max-width: none; }
}

@media (max-width: 500px) {
  .login-card { padding: var(--space-8) var(--space-5); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: var(--text-lg); }
  .topbar { padding: 0 var(--space-4); }
}

/* Backdrop for mobile sidebar */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 28, 0.4);
  z-index: 99;
  display: none;
}
.sidebar-backdrop.show { display: block; }

/* --- Logs viewer --- */
.log-row td { vertical-align: top; }
.log-error { background: rgba(220, 38, 38, 0.08); }
.log-error:hover { background: rgba(220, 38, 38, 0.14); }
.log-warn { background: rgba(217, 119, 6, 0.07); }
.log-level { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.log-level-error { background: rgba(220, 38, 38, 0.15); color: #dc2626; }
.log-level-warn { background: rgba(217, 119, 6, 0.15); color: #b45309; }
.log-level-info { background: rgba(37, 99, 235, 0.12); color: #2563eb; }
.log-level-debug { background: rgba(100, 116, 139, 0.15); color: #64748b; }
.log-level-verbose { background: rgba(100, 116, 139, 0.1); color: #94a3b8; }
.log-tag { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-family: monospace; background: var(--surface-2, #eef2f7); color: var(--text-muted, #64748b); }
.log-tag-chat { background: rgba(16, 185, 129, 0.12); color: #059669; }
.log-tag-call { background: rgba(139, 92, 246, 0.12); color: #7c3aed; }
.log-tag-wallet { background: rgba(245, 158, 11, 0.14); color: #d97706; }
.log-tag-mesh { background: rgba(14, 165, 233, 0.12); color: #0284c7; }
.log-tag-files { background: rgba(236, 72, 153, 0.12); color: #db2777; }
.log-tag-auth { background: rgba(220, 38, 38, 0.1); color: #dc2626; }
.log-tag-system, .log-tag-net, .log-tag-sync, .log-tag-push, .log-tag-app { background: rgba(100, 116, 139, 0.15); color: #64748b; }
#logs-tbody pre { margin: 4px 0 0; background: var(--surface-2, #f1f5f9); padding: 6px 8px; border-radius: 6px; }
.input { padding: 7px 10px; border: 1px solid var(--border, #d1d5db); border-radius: 8px; font-size: 13px; background: var(--surface, #fff); color: var(--text, #111); }

