/* ==========================================================================
   ADMIN – Dashboard styles
   Clean, data-dense, minimalist UI perfectly mapped to your existing HTML
   ========================================================================== */

/* ----- Core Utilities & Visibility Fixes ----- */
.page {
  display: block;
  animation: fadeIn 0.3s ease;
}
.page.hidden {
  display: none !important;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----- Login Screen ----- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 40px 32px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.login-box h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
  color: var(--ink);
  letter-spacing: -0.02em;
}
#loginError {
  color: var(--down);
  margin-top: 16px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  display: none;
}

/* ----- Layout Structure ----- */
.admin-layout {
  display: none; /* Toggled by JS */
  min-height: 100vh;
  background: var(--bg);
}
.admin-layout.active {
  display: flex;
}

/* ----- Sidebar Navigation ----- */
.sidebar {
  width: 220px; /* Reverted from 240px */
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.nav-menu {
  list-style: none;
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}
.nav-item:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}
.nav-item.active {
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ----- Main Content Area ----- */
.main-content {
  margin-left: 220px; /* Reverted from 240px */
  padding: 36px 44px; /* Reverted from 48px */
  /* Remove max-width entirely to match the old behavior */
}

/* ----- Header ----- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.header h1 {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--ink);
  line-height: 1;
  margin: 0;
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.875rem;
  color: var(--ink-soft);
}
.user-role-tag {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink-soft);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- Stats Grid ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
}
.stat-card:hover {
  border-color: var(--border-strong);
}
.stat-label {
  font-size: 0.75rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  font-weight: 600;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--ink);
}
.stat-value.operational { color: var(--operational); }
.stat-value.degraded { color: var(--degraded); }
.stat-value.down { color: var(--down); }

/* ----- Standard Cards (Lists & Tables) ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  padding: 28px 32px !important;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px !important;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

/* ----- Custom Toggle Switch ----- */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.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;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border-strong);
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: var(--surface);
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--ink);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

.toggle-label {
  font-size: 0.875rem;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
}

/* ----- Tables & Lists ----- */
.table-container {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th {
  padding: 12px 24px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
td {
  padding: 16px 24px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--ink);
}

/* Update Table density to match old style */
th, td {
  padding: 12px 10px !important;
  font-size: 0.875rem;
}

/* Update Header text style to match old style */
th {
  color: var(--ink-faint);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: var(--surface-sunken);
}

/* ----- Sortable Groups ----- */
.sortable-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sortable-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
  background: transparent;
}
.sortable-item:last-child {
  border-bottom: none;
}
.sortable-item:hover {
  background: var(--surface-sunken);
}
.drag-handle {
  color: var(--ink-faint);
  cursor: grab;
  font-size: 1.2rem;
}

/* ----- Modals ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 24px;
}
.modal-overlay.active {
  display: flex; /* Assuming JS toggles an active class or manipulates inline styles */
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.2s;
  padding: 0;
  line-height: 1;
}
.close-btn:hover {
  color: var(--ink);
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
}
.modal-footer {
  padding: 16px 24px;
  background: var(--surface-sunken);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ----- Back Link ----- */
.back-to-index {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 150;
  background: var(--surface);
  color: var(--ink-soft);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  text-decoration: none;
}
.back-to-index:hover {
  color: var(--ink);
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

/* ----- Forms embedded in settings page ----- */
#settingsForm {
  padding: 24px;
}

/* ----- Responsive Adjustments ----- */
@media (max-width: 860px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main-content {
    margin-left: 0;
    padding: 24px;
  }
  .nav-menu {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 16px;
  }
  .nav-item {
    white-space: nowrap;
  }
}