/* ==================== CSS Variables (Material Dark Theme) ==================== */
:root {
  --md-primary: #90caf9;
  --md-primary-dark: #5d99c6;
  --md-primary-light: #c3fdff;
  --md-secondary: #ce93d8;
  --md-surface: #1e1e1e;
  --md-surface-variant: #2d2d2d;
  --md-surface-container: #252525;
  --md-surface-container-high: #333333;
  --md-surface-container-highest: #3d3d3d;
  --md-background: #121212;
  --md-on-primary: #003258;
  --md-on-surface: #e0e0e0;
  --md-on-surface-variant: #b0b0b0;
  --md-outline: #555555;
  --md-outline-variant: #3a3a3a;
  --md-error: #f48fb1;
  --md-error-container: #93000a;
  --md-success: #81c784;
  --md-warning: #ffb74d;
  --md-info: #64b5f6;

  --md-elevation-1: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --md-elevation-2: 0 3px 6px rgba(0,0,0,0.4), 0 3px 6px rgba(0,0,0,0.3);
  --md-elevation-3: 0 10px 20px rgba(0,0,0,0.3), 0 6px 6px rgba(0,0,0,0.2);

  --md-radius-sm: 8px;
  --md-radius-md: 12px;
  --md-radius-lg: 16px;
  --md-radius-xl: 28px;

  --sidebar-width: 260px;
  --topbar-height: 64px;
}

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

[x-cloak] { display: none !important; }

html, body {
  height: 100%;
  font-family: 'Roboto', sans-serif;
  background: var(--md-background);
  color: var(--md-on-surface);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--md-primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }

/* ==================== Toast ==================== */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--md-radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--md-elevation-3);
  min-width: 280px;
  max-width: 480px;
  animation: slideIn 0.3s ease;
}

.toast-success { background: #1b5e20; color: #c8e6c9; }
.toast-error { background: #b71c1c; color: #ffcdd2; }
.toast-warning { background: #e65100; color: #ffe0b2; }
.toast-info { background: #0d47a1; color: #bbdefb; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==================== Login Page ==================== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--md-surface);
  border-radius: var(--md-radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--md-elevation-3);
}

.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 24px;
  font-weight: 500;
  color: var(--md-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.login-card .subtitle {
  text-align: center;
  color: var(--md-on-surface-variant);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-error {
  background: var(--md-error-container);
  color: var(--md-error);
  padding: 12px 16px;
  border-radius: var(--md-radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==================== Form Controls ==================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--md-surface-container);
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
  color: var(--md-on-surface);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:hover {
  border-color: var(--md-on-surface-variant);
}

.form-input:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.2);
}

.form-input::placeholder {
  color: var(--md-on-surface-variant);
  opacity: 0.6;
}

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='%23b0b0b0'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 36px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--md-primary);
  cursor: pointer;
}

.checkbox-group label {
  font-size: 14px;
  color: var(--md-on-surface);
  cursor: pointer;
  margin-bottom: 0;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--md-radius-xl);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--md-primary); color: var(--md-on-primary); }
.btn-secondary { background: var(--md-surface-container-high); color: var(--md-on-surface); }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-success { background: #388e3c; color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
}
.btn-outline:hover { background: rgba(144, 202, 249, 0.08); }

.btn-sm { padding: 6px 16px; font-size: 13px; }
.btn-icon {
  padding: 8px;
  border-radius: 50%;
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-full { width: 100%; justify-content: center; }

/* ==================== Top App Bar ==================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--md-surface);
  border-bottom: 1px solid var(--md-outline-variant);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 500;
  color: var(--md-primary);
  text-decoration: none;
}

.app-title:hover { text-decoration: none; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-on-surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:hover { background: var(--md-surface-container-high); }

.username-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--md-radius-xl);
  background: var(--md-surface-container-high);
  font-size: 14px;
  color: var(--md-on-surface-variant);
}

/* ==================== Sidebar ==================== */
.app-layout {
  display: flex;
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--md-surface);
  border-right: 1px solid var(--md-outline-variant);
  padding: 12px 8px;
  position: fixed;
  top: var(--topbar-height);
  bottom: 0;
  left: 0;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 50;
}

.sidebar:not(.open) {
  transform: translateX(-100%);
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-label {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--md-on-surface-variant);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--md-radius-xl);
  font-size: 14px;
  color: var(--md-on-surface);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  margin: 2px 0;
}

.sidebar-item:hover {
  background: var(--md-surface-container-high);
  text-decoration: none;
}

.sidebar-item.active {
  background: rgba(144, 202, 249, 0.12);
  color: var(--md-primary);
  font-weight: 500;
}

.sidebar-item .material-symbols-outlined {
  font-size: 22px;
}

/* ==================== Main Content ==================== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.25s ease;
  min-width: 0;
}

.sidebar:not(.open) ~ .main-content {
  margin-left: 0;
}

.page-container {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

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

.page-title {
  font-size: 24px;
  font-weight: 400;
  color: var(--md-on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-title .material-symbols-outlined {
  color: var(--md-primary);
}

/* ==================== Cards ==================== */
.card {
  background: var(--md-surface);
  border-radius: var(--md-radius-md);
  box-shadow: var(--md-elevation-1);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--md-outline-variant);
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* Dashboard Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--md-surface);
  border-radius: var(--md-radius-md);
  padding: 24px;
  box-shadow: var(--md-elevation-1);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.stat-card:hover {
  box-shadow: var(--md-elevation-2);
  transform: translateY(-2px);
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--md-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-card .stat-icon .material-symbols-outlined {
  font-size: 28px;
}

.stat-icon-blue { background: rgba(144, 202, 249, 0.15); color: var(--md-primary); }
.stat-icon-green { background: rgba(129, 199, 132, 0.15); color: var(--md-success); }
.stat-icon-orange { background: rgba(255, 183, 77, 0.15); color: var(--md-warning); }
.stat-icon-purple { background: rgba(206, 147, 216, 0.15); color: var(--md-secondary); }

.stat-card .stat-info h3 {
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  color: var(--md-on-surface);
}

.stat-card .stat-info p {
  font-size: 13px;
  color: var(--md-on-surface-variant);
  margin-top: 4px;
}

/* ==================== Tables ==================== */
.table-container {
  overflow-x: auto;
  border-radius: var(--md-radius-md);
  background: var(--md-surface);
  box-shadow: var(--md-elevation-1);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table thead {
  background: var(--md-surface-container);
}

.data-table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--md-on-surface-variant);
  border-bottom: 1px solid var(--md-outline-variant);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface);
}

.data-table tbody tr:hover {
  background: var(--md-surface-container);
}

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

.table-actions {
  display: flex;
  gap: 4px;
}

/* ==================== Badges ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--md-radius-xl);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-blue { background: rgba(66, 165, 245, 0.15); color: #64b5f6; }
.badge-purple { background: rgba(171, 71, 188, 0.15); color: #ce93d8; }
.badge-green { background: rgba(102, 187, 106, 0.15); color: #81c784; }
.badge-orange { background: rgba(255, 167, 38, 0.15); color: #ffb74d; }
.badge-gray { background: rgba(189, 189, 189, 0.15); color: #bdbdbd; }
.badge-teal { background: rgba(38, 198, 218, 0.15); color: #4dd0e1; }
.badge-red { background: rgba(229, 115, 115, 0.15); color: #ef9a9a; }
.badge-yellow { background: rgba(255, 238, 88, 0.15); color: #fff176; }

.badge-success { background: rgba(76, 175, 80, 0.15); color: var(--md-success); }
.badge-danger { background: rgba(244, 67, 54, 0.15); color: var(--md-error); }
.badge-active { background: rgba(76, 175, 80, 0.2); color: var(--md-success); }
.badge-inactive { background: rgba(158, 158, 158, 0.2); color: #9e9e9e; }

/* ==================== Dialogs / Modals ==================== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.dialog {
  background: var(--md-surface-container);
  border-radius: var(--md-radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--md-elevation-3);
  animation: scaleIn 0.2s ease;
}

.dialog-header {
  padding: 24px 24px 0;
  font-size: 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-body {
  padding: 20px 24px;
}

.dialog-actions {
  padding: 8px 24px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ==================== Empty State ==================== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--md-on-surface-variant);
}

.empty-state .material-symbols-outlined {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 16px;
  margin-bottom: 16px;
}

/* ==================== Loading ==================== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--md-on-surface-variant);
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--md-outline);
  border-top-color: var(--md-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== Status dot ==================== */
.status-active { color: var(--md-success); }
.status-inactive { color: var(--md-on-surface-variant); }

/* ==================== Info banner ==================== */
.info-banner {
  background: rgba(144, 202, 249, 0.08);
  border: 1px solid rgba(144, 202, 249, 0.2);
  border-radius: var(--md-radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--md-info);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 150;
  }

  .sidebar:not(.open) {
    transform: translateX(-100%);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .page-container {
    padding: 16px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .dialog {
    max-width: 100%;
    margin: 12px;
  }
}

/* ==================== Utility ==================== */
.text-muted { color: var(--md-on-surface-variant); }
.text-error { color: var(--md-error); }
.text-success { color: var(--md-success); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex-gap { display: flex; gap: 8px; align-items: center; }
.mono { font-family: 'Roboto Mono', monospace; font-size: 13px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
