/* ==============================================================================
   Project: Integrated Radiology Log & Maintenance System (HSgB)
   Design System: Google Store Inspired Premium Minimalist Corporate & FlyonUI
   Strict Constraints: Clinical aesthetics, high legibility, crisp borders, Charcoal Dark Mode
   ============================================================================== */

:root {
  /* Soft Light Theme Tokens (Soft White & Cream scheme #f5f5f5) */
  --bg: #f5f5f5;
  --card: #ffffff;
  --text-primary: #1f1f1f;
  --text-secondary: #5f6368;
  --text-muted: #80868b;
  --border: #e0e0e0;
  --border-hover: #c7c7c7;
  
  /* Semantic & Brand Accents (Google Store Blue & Soft Statuses) */
  --accent-brand: #1a73e8;
  --accent-brand-bg: #e8f0fe;
  --accent-ok: #1e8e3e;
  --accent-ok-bg: #e6f4ea;
  --accent-not-ok: #d93025;
  --accent-not-ok-bg: #fce8e6;
  --accent-alert: #f9ab00;
  --accent-alert-bg: #fef7e0;
  
  /* Layout Metrics (Google Store Premium Pill & Rounded Aesthetics) */
  --header-height: 76px;
  --radius-sm: 12px;
  --radius-md: 9999px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"], html.dark {
  /* Charcoal Grey Dark Theme Tokens (Sleek Charcoal Grey instead of bluish slate) */
  --bg: #18181b;
  --card: #222226;
  --text-primary: #f3f4f6;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #323238;
  --border-hover: #484850;
  
  /* Dark Semantic & Brand Accents */
  --accent-brand: #8ab4f8;
  --accent-brand-bg: rgba(138, 180, 248, 0.16);
  --accent-ok: #81c995;
  --accent-ok-bg: rgba(129, 201, 149, 0.16);
  --accent-not-ok: #f28b82;
  --accent-not-ok-bg: rgba(242, 139, 130, 0.16);
  --accent-alert: #fdd663;
  --accent-alert-bg: rgba(253, 214, 99, 0.16);
  --shadow-sm: none;
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Google Sans Flex', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Utility Hidden */
.hidden {
  display: none !important;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--text-muted); }

/* Global Header */
.global-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
}

.header-content {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.brand-logo {
  width: 42px;
  height: 42px;
  background-color: var(--text-primary);
  color: var(--card);
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  letter-spacing: -0.5px;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

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

.top-nav-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.top-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.15rem;
  border-radius: 9999px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.top-nav-link:hover {
  color: var(--text-primary);
  background-color: var(--accent-brand-bg);
  border-color: var(--border);
}

.top-nav-link.active {
  color: var(--accent-brand);
  background-color: var(--accent-brand-bg);
  border-color: var(--accent-brand);
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .top-nav-menu {
    width: 100%;
    justify-content: space-around;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.auth-badge-group {
  display: flex;
  align-items: center;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background-color: var(--bg);
  cursor: pointer;
}

.role-badge.super_admin {
  border-color: #8b5cf6;
  color: #8b5cf6;
  background-color: rgba(139, 92, 246, 0.1);
}

.role-badge.admin {
  border-color: var(--accent-brand);
  color: var(--accent-brand);
  background-color: var(--accent-brand-bg);
}

/* Theme Toggle Button (Minimum 48px Target) */
.theme-toggle-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background-color: var(--card);
  color: var(--text-primary);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--text-secondary);
  background-color: var(--bg);
}

/* Global Alert Banner (Smart Missing Logs) */
.global-alert-banner {
  background-color: var(--accent-alert-bg);
  border-bottom: 1px solid var(--accent-alert);
  padding: 0.75rem 1.5rem;
}

.alert-content {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.alert-link-btn {
  padding: 0.35rem 0.85rem;
  background-color: var(--accent-alert);
  color: #111827;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
}

/* Main Container */
.app-main-container {
  max-width: 1280px;
  margin: 2rem auto;
  padding: 0 1.5rem 4rem;
}

/* Root Navigation Cards (`/`) */
.portal-hero {
  margin-bottom: 2.5rem;
}

.portal-hero h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.portal-hero p {
  color: var(--text-secondary);
  font-size: 1rem;
}

.nav-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.nav-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  min-height: 220px;
}

.nav-card:hover {
  border-color: var(--accent-brand);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.nav-card-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.nav-card h3 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.nav-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.nav-card-arrow {
  font-weight: 600;
  color: var(--accent-brand);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Discrete Corner Admin Lock */
.portal-footer-lock {
  display: flex;
  justify-content: flex-end;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.lock-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px dashed transparent;
  transition: all 0.15s ease;
}

.lock-link:hover {
  color: var(--text-primary);
  border-color: var(--border);
}

/* Form Layout & Cards */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background-color: var(--card);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  min-height: 48px;
}

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

.form-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.form-section-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1.35rem;
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 9999px;
  transition: all 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-brand);
  box-shadow: 0 0 0 4px var(--accent-brand-bg);
}

.form-textarea {
  min-height: 120px;
  border-radius: 20px;
  padding: 1rem 1.35rem;
  resize: vertical;
}

/* Conditional Crimson Warning Border when NOT OK */
.form-textarea.textarea-danger {
  border-color: var(--accent-not-ok) !important;
  background-color: var(--accent-not-ok-bg);
}

/* Segmented Shift & Status Selectors */
.segmented-control {
  display: grid;
  grid-auto-flow: column;
  gap: 0.5rem;
  background-color: var(--bg);
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
}

.segmented-option {
  position: relative;
}

.segmented-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.segmented-option label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.segmented-option input[type="radio"]:checked + label {
  background-color: var(--card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Evaluation Toggle OK / NOT OK */
.eval-toggle.ok input:checked + label {
  background-color: var(--accent-ok);
  color: #ffffff;
}

.eval-toggle.not-ok input:checked + label {
  background-color: var(--accent-not-ok);
  color: #ffffff;
}

/* Checkbox Grid (Duty Area / Checklist Items) */
.checkbox-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.checkbox-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 54px;
}

.checkbox-card:hover {
  border-color: var(--text-secondary);
}

.checkbox-card input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-brand);
  cursor: pointer;
}

.checkbox-card span {
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
}

.checkbox-card:has(input:checked) {
  border-color: var(--accent-brand);
  background-color: var(--accent-brand-bg);
}

/* Case Stepper Counters (DRY Component) */
.stepper-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  gap: 1rem;
  flex-wrap: wrap;
}

.stepper-label {
  font-weight: 600;
  font-size: 1rem;
}

.stepper-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stepper-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background-color: var(--card);
  color: var(--text-primary);
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  user-select: none;
}

.stepper-btn:hover {
  border-color: var(--accent-brand);
  background-color: var(--accent-brand-bg);
  color: var(--accent-brand);
}

.stepper-btn:active {
  transform: scale(0.95);
}

.stepper-input {
  width: 70px;
  height: 48px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--card);
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.85rem 1.85rem;
  min-height: 48px;
  border-radius: 9999px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

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

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  background-color: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.btn-success {
  background-color: var(--accent-ok);
  color: #ffffff;
}

.btn-danger {
  background-color: var(--accent-not-ok);
  color: #ffffff;
}

.btn-sm {
  min-height: 38px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

/* Executive Admin Navigation Tabs */
.admin-tabs {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  overflow-x: auto;
}

.tab-btn {
  padding: 0.7rem 1.45rem;
  border-radius: 9999px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

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

.tab-btn.active {
  color: var(--text-primary);
  background-color: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

/* KPI Cards & Analytics Grid (`/admin/analytics`) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Data Table Grid */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  background-color: var(--bg);
  padding: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.data-table tr:hover td {
  background-color: var(--bg);
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge.ok {
  background-color: var(--accent-ok-bg);
  color: var(--accent-ok);
}

.status-badge.not-ok {
  background-color: var(--accent-not-ok-bg);
  color: var(--accent-not-ok);
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-card {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.modal-body {
  padding: 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 380px;
}

.toast {
  background-color: var(--text-primary);
  color: var(--card);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  animation: slideIn 0.25s ease;
}

.toast.error {
  background-color: var(--accent-not-ok);
  color: #ffffff;
}

.toast.success {
  background-color: var(--accent-ok);
  color: #ffffff;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Spinner */
.loading-spinner-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
  color: var(--text-secondary);
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent-brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Custom Searchable Dropdown & Pills */
.custom-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  z-index: 50;
}

.dropdown-item {
  transition: background-color 0.15s ease;
}

.dropdown-item:hover {
  background-color: rgba(59, 130, 246, 0.08);
}

.dropdown-item.selected {
  background-color: rgba(59, 130, 246, 0.12);
}

.single-select-pill:hover {
  border-color: var(--accent-brand);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .global-header {
    height: auto;
    padding: 1rem 1.5rem;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}
