:root {
  /* Dark theme (default) */
  --bg-primary: #000000;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.05);
  --bg-elevated: rgba(255, 255, 255, 0.06);
  --bg-sidebar: #0a0a0a;
  --bg-input: rgba(255, 255, 255, 0.04);

  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  --border-active: rgba(255, 255, 255, 0.2);

  --text-primary: #fafafa;
  --text-secondary: #888888;
  --text-muted: #555555;

  --accent-green: #22c55e;
  --accent-blue: #3b82f6;
  --accent-red: #dc2626;
  --accent-yellow: #eab308;

  /* Buttons */
  --btn-primary-bg: #ffffff;
  --btn-primary-color: #000000;
  --btn-primary-hover: rgba(255, 255, 255, 0.85);

  /* Components */
  --modal-bg: #0a0a0a;
  --scrollbar-thumb: rgba(255, 255, 255, 0.1);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);

  /* Auth form side */
  --auth-form-bg: #0a0a0a;

  /* Layout */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --sidebar-width: 240px;

  color-scheme: dark;
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-card: rgba(0, 0, 0, 0.02);
  --bg-card-hover: rgba(0, 0, 0, 0.04);
  --bg-elevated: rgba(0, 0, 0, 0.04);
  --bg-sidebar: #f8f8f8;
  --bg-input: rgba(0, 0, 0, 0.03);

  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --border-active: rgba(0, 0, 0, 0.25);

  --text-primary: #0a0a0a;
  --text-secondary: #666666;
  --text-muted: #999999;

  --accent-green: #16a34a;
  --accent-blue: #2563eb;
  --accent-red: #dc2626;
  --accent-yellow: #ca8a04;

  --btn-primary-bg: #0a0a0a;
  --btn-primary-color: #ffffff;
  --btn-primary-hover: #1a1a1a;

  --modal-bg: #ffffff;
  --scrollbar-thumb: rgba(0, 0, 0, 0.15);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.25);

  --auth-form-bg: #ffffff;

  color-scheme: light;
}

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

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

a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--text-secondary);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* App Shell */
.app-shell {
  max-width: 1320px;
  margin: 16px auto;
  min-height: calc(100vh - 32px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
}

.app-layout {
  display: flex;
  min-height: calc(100vh - 32px);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  display: flex;
  align-items: center;
}

.sidebar-logo:hover {
  opacity: 0.8;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.nav-item:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.07);
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logout:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

/* Mobile Topbar */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 150;
  height: 56px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.mobile-menu-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 190;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-overlay.open {
  opacity: 1;
}

/* Main Content */
.main-content {
  flex: 1;
  min-width: 0;
  min-height: calc(100vh - 32px);
  padding: 2rem 3rem;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  height: 2.25rem;
  white-space: nowrap;
  line-height: 1;
  font-family: inherit;
}

.btn svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.btn:hover {
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px rgba(255, 255, 255, 0.2);
}

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

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

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-active);
}

.btn-danger {
  background: var(--accent-red);
  color: #ffffff;
  border-color: transparent;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  height: 1.875rem;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Forms */
.input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: all 0.2s ease;
  height: 2.5rem;
}

.input:focus {
  outline: none;
  border-color: var(--border-active);
  background: rgba(255, 255, 255, 0.06);
}

.input::placeholder {
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  backdrop-filter: blur(12px);
  transition: border-color 0.2s ease;
}

/* Alerts */
.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  border: 1px solid;
}

.alert-error {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.2);
  color: #fca5a5;
}

.alert-success {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

[data-theme="light"] .alert-error {
  color: #b91c1c;
}

[data-theme="light"] .alert-success {
  color: #15803d;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  letter-spacing: -0.025em;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  text-transform: capitalize;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-sent {
  background: rgba(34, 197, 94, 0.12);
  color: var(--accent-green);
}

.status-sent .status-dot {
  background: var(--accent-green);
}

.status-failed {
  background: rgba(220, 38, 38, 0.12);
  color: #f87171;
}

.status-failed .status-dot {
  background: var(--accent-red);
}

.status-stopped {
  background: rgba(234, 179, 8, 0.12);
  color: var(--accent-yellow);
}

.status-stopped .status-dot {
  background: var(--accent-yellow);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.empty-state svg {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  opacity: 0.5;
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.empty-state p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Admin */
.admin-container {
  padding-bottom: 2rem;
}

.admin-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  backdrop-filter: blur(12px);
}

.admin-card h2 {
  margin-bottom: 0.5rem;
  font-size: 1.125rem;
}

.admin-form {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
}

.admin-inline {
  grid-template-columns: 1fr auto;
  align-items: end;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .data-table tbody tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Auth Pages */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  backdrop-filter: blur(12px);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  letter-spacing: -0.025em;
}

.auth-header p {
  color: var(--text-secondary);
}

.auth-form {
  margin-bottom: 1.5rem;
}

/* Error Page */
.error-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.error-card {
  text-align: center;
  max-width: 400px;
}

.error-card h1 {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.error-card p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Theme Toggle */
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.theme-icon-sun { display: block; }
.theme-icon-moon { display: none; }
[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="light"] .theme-icon-moon { display: block; }

.theme-toggle-float {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 50;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(12px);
  transition: all 0.15s ease;
  padding: 0;
}

.theme-toggle-float:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Responsive */
@media (max-width: 768px) {
  .app-shell {
    margin: 0;
    border: none;
    border-radius: 0;
    min-height: 100vh;
  }

  .app-layout {
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    padding: 1.5rem;
  }

  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 640px) {
  .page-header {
    flex-direction: column;
    gap: 1rem;
  }

  .admin-inline {
    grid-template-columns: 1fr;
  }

  .main-content {
    padding: 1.25rem;
  }

  .data-table {
    font-size: 0.8125rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.625rem 0.75rem;
  }
}
