/* ============================================================
   Flyin' Wrench Dashboard — Design System v2
   Staging global stylesheet (drop-in replacement)
   ============================================================ */

/* ---------- Font Imports ---------- */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ============================================================
   DESIGN TOKENS — Light Theme (default)
   ============================================================ */
:root,
[data-theme="light"] {
  /* --- Surfaces --- */
  --surface-base: #eef1f5;
  --surface-card: #f7f8fa;
  --surface-inset: #e8ebf0;
  --surface-nav: rgba(244,246,249,0.75);

  /* --- Text --- */
  --text-primary: #1a2332;
  --text-secondary: #5a6577;
  --text-tertiary: #8a94a6;
  --text-brand: #2d8fdd;

  /* --- Brand --- */
  --brand: #2d8fdd;
  --brand-light: #e8f4fd;
  --brand-dark: #1a6cb5;

  /* --- Status --- */
  --status-good: #1a9a5a;
  --status-good-bg: #e8f7ef;
  --status-warning: #c47f17;
  --status-warning-bg: #fef6e7;
  --status-bad: #c93b3b;
  --status-bad-bg: #fde8e8;

  /* --- Borders --- */
  --border-default: rgba(26,35,50,0.07);
  --border-strong: rgba(26,35,50,0.12);

  /* --- Shadows --- */
  --shadow-sm: 0 1px 3px rgba(26,35,50,0.04);
  --shadow-md: 0 2px 8px rgba(26,35,50,0.06);
  --shadow-lg: 0 8px 24px rgba(26,35,50,0.10);

  /* --- Radii --- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* --- Typography --- */
  --font-primary: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* --- Motion --- */
  --transition-fast: 120ms ease-out;
  --transition-normal: 200ms ease-out;

  /* ========================================
     BACKWARD-COMPAT MAPPINGS (old names)
     ======================================== */
  --primary: var(--brand);
  --primary-dark: var(--brand-dark);
  --primary-light: var(--brand-light);

  --success: var(--status-good);
  --success-dark: #15803d;
  --success-light: var(--status-good-bg);

  --warning: var(--status-warning);
  --warning-dark: #b45309;
  --warning-light: var(--status-warning-bg);

  --error: var(--status-bad);
  --error-dark: #b91c1c;
  --error-light: var(--status-bad-bg);

  --bg: var(--surface-base);
  --bg-card: var(--surface-card);
  --bg-hover: var(--surface-inset);

  --card: var(--surface-card);
  --card-strong: var(--surface-inset);

  --text: var(--text-primary);
  --muted: var(--text-tertiary);

  --border: var(--border-default);
  --border-dark: var(--border-strong);

  --shadow: var(--shadow-md);
  --radius: var(--radius-sm);
  /* --radius-lg already defined above */

  --font-display: var(--font-primary);
  --font-data: var(--font-mono);

  /* Sidebar compat (mapped even though sidebar is removed) */
  --sidebar: var(--surface-card);
  --sidebar-deep: var(--surface-inset);
  --sidebar-text: var(--text-primary);
  --sidebar-muted: var(--text-tertiary);
  --sidebar-hover: var(--surface-inset);
  --sidebar-active: var(--brand-light);
  --sidebar-glow: var(--brand);
}

/* ============================================================
   DESIGN TOKENS — Dark Theme
   ============================================================ */
[data-theme="dark"] {
  /* --- Surfaces --- */
  --surface-base: #0f1419;
  --surface-card: #1c2128;
  --surface-inset: #131820;
  --surface-nav: rgba(15,20,25,0.8);

  /* --- Text --- */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #7a8494;
  --text-brand: #4ba3e6;

  /* --- Brand --- */
  --brand: #3795d8;
  --brand-light: rgba(55,149,216,0.10);
  --brand-dark: #2d8fdd;

  /* --- Status --- */
  --status-good: #2ea86f;
  --status-good-bg: rgba(46,168,111,0.12);
  --status-warning: #d9952b;
  --status-warning-bg: rgba(217,149,43,0.12);
  --status-bad: #d94848;
  --status-bad-bg: rgba(217,72,72,0.12);

  /* --- Borders --- */
  --border-default: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.10);

  /* --- Shadows --- */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);

  /* ========================================
     BACKWARD-COMPAT MAPPINGS (dark overrides)
     ======================================== */
  --primary: var(--brand);
  --primary-dark: var(--brand-dark);
  --primary-light: var(--brand-light);

  --success: var(--status-good);
  --success-dark: #4ade80;
  --success-light: var(--status-good-bg);

  --warning: var(--status-warning);
  --warning-dark: #fcd34d;
  --warning-light: var(--status-warning-bg);

  --error: var(--status-bad);
  --error-dark: #f87171;
  --error-light: var(--status-bad-bg);

  --bg: var(--surface-base);
  --bg-card: var(--surface-card);
  --bg-hover: var(--surface-inset);

  --card: var(--surface-card);
  --card-strong: var(--surface-inset);

  --text: var(--text-primary);
  --muted: var(--text-tertiary);

  --border: var(--border-default);
  --border-dark: var(--border-strong);

  --shadow: var(--shadow-md);

  --font-display: var(--font-primary);
  --font-data: var(--font-mono);

  --sidebar: var(--surface-card);
  --sidebar-deep: var(--surface-inset);
  --sidebar-text: var(--text-primary);
  --sidebar-muted: var(--text-tertiary);
  --sidebar-hover: var(--surface-inset);
  --sidebar-active: var(--brand-light);
  --sidebar-glow: var(--brand);

  color-scheme: dark;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-primary);
  background: var(--surface-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--brand-dark);
}

img { max-width: 100%; height: auto; }

code, pre, .mono, .font-mono {
  font-family: var(--font-mono);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-primary);
  color: var(--text-primary);
  line-height: 1.3;
  font-weight: 700;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 0.75rem; }

::selection {
  background: var(--brand);
  color: #ffffff;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* ============================================================
   APP SHELL — Full-width with top nav (no sidebar)
   ============================================================ */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.main {
  max-width: 100%;
  margin: 0 auto;
  padding: 24px 32px;
  width: 100%;
  flex: 1;
}

/* ============================================================
   TOP NAVIGATION
   ============================================================ */
.top-nav {
  background: var(--surface-nav);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  padding: 0 32px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-nav .nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.top-nav .nav-brand img {
  height: 28px;
  width: auto;
}

.top-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.top-nav .nav-links a,
.top-nav .nav-links .nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.top-nav .nav-links a:hover,
.top-nav .nav-links .nav-link:hover {
  color: var(--text-primary);
  background: var(--surface-inset);
}

.top-nav .nav-links a.active,
.top-nav .nav-links .nav-link.active {
  color: var(--brand);
  background: var(--brand-light);
}

.top-nav .nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.page-header .subtitle,
.page-header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-default);
}

.card-header h2,
.card-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
}

.card-body {
  /* default flow */
}

.card-footer {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-default);
}

.card.card-flush {
  padding: 0;
}

/* ============================================================
   KPI GRID
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.kpi-card .kpi-label,
.kpi-card .label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.kpi-card .kpi-value,
.kpi-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-card .kpi-delta,
.kpi-card .delta {
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 4px;
}

.kpi-card .kpi-delta.up,
.kpi-card .delta.up { color: var(--status-good); }
.kpi-card .kpi-delta.down,
.kpi-card .delta.down { color: var(--status-bad); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  user-select: none;
}

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

.btn.primary,
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}
.btn.primary:hover,
.btn-primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

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

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

.btn.danger,
.btn-danger {
  background: var(--status-bad);
  border-color: var(--status-bad);
  color: #ffffff;
}
.btn.danger:hover,
.btn-danger:hover {
  background: var(--error-dark);
  border-color: var(--error-dark);
}

.btn.success,
.btn-success {
  background: var(--status-good);
  border-color: var(--status-good);
  color: #ffffff;
}
.btn.success:hover,
.btn-success:hover {
  background: var(--success-dark);
  border-color: var(--success-dark);
}

.btn.warning,
.btn-warning {
  background: var(--status-warning);
  border-color: var(--status-warning);
  color: #ffffff;
}
.btn.warning:hover,
.btn-warning:hover {
  background: var(--warning-dark);
  border-color: var(--warning-dark);
}

.btn.sm,
.btn-sm {
  font-size: 0.75rem;
  padding: 5px 10px;
}

.btn.lg,
.btn-lg {
  font-size: 0.9375rem;
  padding: 10px 22px;
}

.btn.icon-only {
  padding: 8px;
  min-width: 34px;
}

.btn-group {
  display: inline-flex;
  gap: 0;
}
.btn-group .btn {
  border-radius: 0;
}
.btn-group .btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.btn-group .btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.btn-group .btn + .btn {
  margin-left: -1px;
}

/* ============================================================
   TABLES
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: var(--surface-inset);
}

tbody tr.selected {
  background: var(--brand-light);
}

tfoot td {
  padding: 10px 12px;
  font-weight: 600;
  border-top: 2px solid var(--border-strong);
  color: var(--text-primary);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   FORMS & INPUTS
   ============================================================ */
label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select,
.form-control {
  font-family: var(--font-primary);
  font-size: 0.875rem;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  color: var(--text-primary);
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="tel"],
[data-theme="dark"] input[type="url"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="datetime-local"],
[data-theme="dark"] textarea,
[data-theme="dark"] select,
[data-theme="dark"] .form-control {
  background: var(--surface-inset);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--brand);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.form-row > * {
  flex: 1;
  min-width: 0;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.form-error {
  font-size: 0.75rem;
  color: var(--status-bad);
  margin-top: 4px;
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group input,
.input-group select {
  border-radius: 0;
  flex: 1;
}

.input-group > :first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-group > :last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 0.8125rem;
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Toggle / Switch */
.toggle, .switch {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
}

.toggle input, .switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider, .switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toggle .slider::before, .switch .slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

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

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

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  line-height: 1.5;
  white-space: nowrap;
}

.badge-primary {
  background: var(--brand-light);
  color: var(--brand-dark);
}

[data-theme="dark"] .badge-primary {
  color: var(--text-brand);
}

.badge-success, .badge-good {
  background: var(--status-good-bg);
  color: var(--status-good);
}

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

.badge-error, .badge-danger, .badge-bad {
  background: var(--status-bad-bg);
  color: var(--status-bad);
}

.badge-neutral, .badge-default {
  background: var(--surface-inset);
  color: var(--text-secondary);
}

.badge-sm {
  font-size: 0.625rem;
  padding: 1px 6px;
}

.badge-lg {
  font-size: 0.75rem;
  padding: 3px 10px;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-info {
  background: var(--brand-light);
  color: var(--brand-dark);
  border-color: var(--brand);
}

[data-theme="dark"] .alert-info {
  color: var(--text-brand);
}

.alert-success {
  background: var(--status-good-bg);
  color: var(--status-good);
  border-color: var(--status-good);
}

.alert-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
  border-color: var(--status-warning);
}

.alert-error, .alert-danger {
  background: var(--status-bad-bg);
  color: var(--status-bad);
  border-color: var(--status-bad);
}

.alert .alert-title {
  font-weight: 700;
  margin-bottom: 2px;
}

.alert .alert-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.125rem;
  cursor: pointer;
  opacity: 0.6;
  color: inherit;
  padding: 0;
  line-height: 1;
}

.alert .alert-close:hover {
  opacity: 1;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-primary);
  margin-bottom: -1px;
}

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

.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.active,
.modal-backdrop.active,
.modal-overlay.show,
.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  z-index: 1001;
  transform: translateY(8px) scale(0.98);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal,
.modal-backdrop.active .modal,
.modal-overlay.show .modal,
.modal-backdrop.show .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-default);
}

.modal-header h2,
.modal-header h3 {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  line-height: 1;
}

.modal-close:hover {
  background: var(--surface-inset);
  color: var(--text-primary);
}

.modal-body {
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-default);
}

.modal.lg, .modal-lg {
  max-width: 720px;
}

.modal.sm, .modal-sm {
  max-width: 400px;
}

.modal.fullscreen, .modal-fullscreen {
  width: 95%;
  max-width: 1100px;
  max-height: 90vh;
}

/* ============================================================
   SPINNER / LOADING
   ============================================================ */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-default);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.spinner.sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner.lg {
  width: 36px;
  height: 36px;
  border-width: 4px;
}

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

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(var(--surface-base), 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-inset) 25%, var(--border-default) 50%, var(--surface-inset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   TOOLTIPS
   ============================================================ */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 5px 10px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: #ffffff;
  background: var(--text-primary);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: 500;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   DROPDOWN / SELECT MENUS
   ============================================================ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}

.dropdown-menu.active,
.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.8125rem;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-primary);
}

.dropdown-item:hover {
  background: var(--surface-inset);
}

.dropdown-item.active {
  background: var(--brand-light);
  color: var(--brand);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress {
  height: 8px;
  background: var(--surface-inset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--brand);
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
}

.progress-bar.success { background: var(--status-good); }
.progress-bar.warning { background: var(--status-warning); }
.progress-bar.danger  { background: var(--status-bad); }

/* ============================================================
   TAGS / CHIPS
   ============================================================ */
.tag, .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.tag .remove, .chip .remove {
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1;
  opacity: 0.6;
}

.tag .remove:hover, .chip .remove:hover {
  opacity: 1;
}

/* ============================================================
   ACCORDION
   ============================================================ */
.accordion-item {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-card);
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.accordion-header:hover {
  background: var(--surface-inset);
}

.accordion-body {
  padding: 0 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 250ms ease-out, padding 250ms ease-out;
}

.accordion-item.open .accordion-body {
  max-height: 1000px;
  padding: 12px 16px;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.pagination .page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  background: var(--surface-card);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.pagination .page-link:hover {
  background: var(--surface-inset);
  color: var(--text-primary);
}

.pagination .page-link.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.pagination .page-link.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ============================================================
   TOAST / NOTIFICATION
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  min-width: 300px;
  max-width: 420px;
  font-size: 0.8125rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn 200ms ease-out;
}

.toast.success { border-left: 3px solid var(--status-good); }
.toast.warning { border-left: 3px solid var(--status-warning); }
.toast.error   { border-left: 3px solid var(--status-bad); }
.toast.info    { border-left: 3px solid var(--brand); }

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

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state .title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state .description {
  font-size: 0.8125rem;
  max-width: 320px;
}

/* ============================================================
   AVATAR
   ============================================================ */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-light);
  color: var(--brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.sm { width: 28px; height: 28px; font-size: 0.6875rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1.125rem; }

/* ============================================================
   DIVIDER
   ============================================================ */
.divider, hr {
  border: none;
  height: 1px;
  background: var(--border-default);
  margin: 16px 0;
}

/* ============================================================
   STATUS DOT
   ============================================================ */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.online, .status-dot.active, .status-dot.good { background: var(--status-good); }
.status-dot.warning { background: var(--status-warning); }
.status-dot.offline, .status-dot.error, .status-dot.bad  { background: var(--status-bad); }
.status-dot.neutral { background: var(--text-tertiary); }

.status-dot.pulse {
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; }
  50%      { box-shadow: 0 0 0 4px transparent; }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-tertiary) !important; }
.text-brand { color: var(--brand) !important; }
.text-success { color: var(--status-good) !important; }
.text-warning { color: var(--status-warning) !important; }
.text-error, .text-danger { color: var(--status-bad) !important; }

.bg-brand { background: var(--brand) !important; color: #fff; }
.bg-success { background: var(--status-good-bg) !important; }
.bg-warning { background: var(--status-warning-bg) !important; }
.bg-error, .bg-danger { background: var(--status-bad-bg) !important; }
.bg-card { background: var(--surface-card) !important; }
.bg-inset { background: var(--surface-inset) !important; }

.font-mono { font-family: var(--font-mono) !important; }
.font-display { font-family: var(--font-primary) !important; }

.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }

.fs-xs   { font-size: 0.6875rem; }
.fs-sm   { font-size: 0.75rem; }
.fs-base { font-size: 0.875rem; }
.fs-md   { font-size: 1rem; }
.fs-lg   { font-size: 1.25rem; }
.fs-xl   { font-size: 1.5rem; }
.fs-2xl  { font-size: 2rem; }

.uppercase { text-transform: uppercase; letter-spacing: 0.05em; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.d-flex { display: flex; }
.d-grid { display: grid; }
.d-block { display: block; }
.d-inline { display: inline; }
.d-inline-flex { display: inline-flex; }
.d-none { display: none; }

.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.gap-24 { gap: 24px; }

.m-0  { margin: 0; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0  { padding: 0; }
.p-8  { padding: 8px; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded-sm   { border-radius: var(--radius-sm); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-none { box-shadow: none; }

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; }

.cursor-pointer { cursor: pointer; }
.select-none { user-select: none; }

.border { border: 1px solid var(--border-default); }
.border-0 { border: 0; }
.border-b { border-bottom: 1px solid var(--border-default); }
.border-t { border-top: 1px solid var(--border-default); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

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

.hidden { display: none !important; }
.visible { visibility: visible; }
.invisible { visibility: hidden; }

.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-100 { opacity: 1; }

/* ============================================================
   TRANSITIONS & ANIMATIONS
   ============================================================ */
.fade-in {
  animation: fadeIn 200ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.slide-up {
  animation: slideUp 200ms ease-out;
}

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

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .top-nav,
  .toast-container,
  .btn,
  .modal-overlay,
  .modal-backdrop {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  .main {
    max-width: 100%;
    padding: 0;
  }
}

/* ============================================================
   RESPONSIVE / MOBILE
   ============================================================ */
@media (max-width: 1024px) {
  .main {
    padding: 20px 24px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 768px) {
  .main {
    padding: 16px;
  }

  .top-nav {
    padding: 0 16px;
    height: 52px;
  }

  .top-nav .nav-links {
    display: none;
  }

  .card {
    padding: 16px;
    border-radius: var(--radius-sm);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .kpi-card {
    padding: 12px 14px;
  }

  .kpi-card .kpi-value,
  .kpi-card .value {
    font-size: 1.25rem;
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  .modal {
    width: 95%;
    padding: 20px;
    border-radius: var(--radius-md);
  }

  .tabs {
    gap: 0;
  }

  .tab {
    padding: 8px 12px;
    font-size: 0.75rem;
  }

  .btn {
    font-size: 0.75rem;
    padding: 7px 12px;
  }

  table {
    font-size: 0.75rem;
  }

  thead th {
    font-size: 0.625rem;
    padding: 8px;
  }

  tbody td {
    padding: 8px;
  }

  .toast-container {
    top: auto;
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  .toast {
    min-width: auto;
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 12px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .kpi-card .kpi-value,
  .kpi-card .value {
    font-size: 1.125rem;
  }

  h1 { font-size: 1.375rem; }
  h2 { font-size: 1.125rem; }
  h3 { font-size: 1rem; }

  .btn-group {
    flex-direction: column;
    width: 100%;
  }

  .btn-group .btn {
    border-radius: 0;
    width: 100%;
  }

  .btn-group .btn:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }

  .btn-group .btn:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* Mobile nav toggle (hamburger support) */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
}

@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .top-nav .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card);
    border-bottom: 1px solid var(--border-default);
    box-shadow: var(--shadow-md);
    padding: 8px;
    gap: 2px;
  }
}

/* ═══ LOGIN PAGE ═══ */
body.login {
  min-height: 100vh;
  background: var(--surface-base);
  margin: 0;
  padding: 0;
}

.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.login-card {
  width: 420px;
  max-width: 90vw;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.login-card .logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px auto;
  border-radius: 9999px;
  background: rgba(255,255,255,0.95);
  padding: 4px;
  object-fit: contain;
  display: block;
}

.login-card h1 {
  font-family: var(--font-primary);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.login-card label {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 12px;
}

.login-card input {
  margin-bottom: 4px;
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
}

.login-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(45,143,221,0.15);
}

.login-card .btn.primary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 120ms ease-out;
}

.login-card .btn.primary:hover {
  background: var(--brand-dark);
}

.login-card .error {
  background: var(--status-bad-bg);
  color: var(--status-bad);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(201,59,59,0.15);
}

/* ═══ REPORTS PAGE ═══ */
.reports-page { max-width: 900px; }
.reports-subtitle { margin-bottom: 14px; color: var(--text-secondary); }
.reports-list { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }

.report-box {
  display: block;
  border: 1px solid var(--border-default);
  background: var(--surface-card);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}

.report-box:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
}

.report-box-title { font-size: 18px; font-weight: 600; color: var(--brand); margin-bottom: 4px; }
.report-box-desc { color: var(--text-secondary); font-size: 14px; }

.btn-back {
  display: inline-block;
  margin-top: 16px;
  padding: 8px 16px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 500;
}

.btn-back:hover { border-color: var(--border-strong); background: var(--surface-inset); }
