/* ============================================================
   Qalizer — Global Design System
   ============================================================ */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  font-size: 16px;
}

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  /* Palette */
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-active: #4338ca;
  --primary-dim:    rgba(99, 102, 241, 0.15);

  --success:        #22c55e;
  --success-dim:    rgba(34, 197, 94, 0.15);
  --warning:        #f59e0b;
  --warning-dim:    rgba(245, 158, 11, 0.15);
  --danger:         #ef4444;
  --danger-dim:     rgba(239, 68, 68, 0.15);
  --info:           #38bdf8;
  --info-dim:       rgba(56, 189, 248, 0.15);

  /* Surfaces */
  --bg:             #0f1117;
  --surface:        #161b27;
  --surface-alt:    #1a2035;
  --card-bg:        #1e2130;
  --card-hover:     #232840;
  --sidebar-bg:     #13171f;

  /* Borders */
  --border:         rgba(255, 255, 255, 0.08);
  --border-strong:  rgba(255, 255, 255, 0.15);

  /* Text */
  --text:           #e2e8f0;
  --text-muted:     #94a3b8;
  --text-faint:     #4a5568;
  --text-inverse:   #0f1117;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.6);

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Type */
  --font-body:    'Inter', system-ui, sans-serif;
  --text-xs:      0.75rem;
  --text-sm:      0.875rem;
  --text-base:    1rem;
  --text-lg:      1.125rem;
  --text-xl:      1.25rem;
  --text-2xl:     1.5rem;
  --text-3xl:     1.875rem;

  /* Transitions */
  --transition: 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.6;
  transition: background-color 0.15s ease, color 0.15s ease;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }
h1,h2,h3,h4,h5,h6 { line-height: 1.2; text-wrap: balance; }
p { text-wrap: pretty; max-width: 72ch; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

::selection {
  background: rgba(99,102,241,0.3);
  color: var(--text);
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.nav-link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}
.nav-link:hover,
.nav-link.active {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

/* Mobile Navigation */
.mobile-nav-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 101;
}

@media (max-width: 768px) {
  .navbar {
    padding: 0 var(--space-4);
  }
  
  .mobile-nav-btn {
    display: block;
  }
  
  .nav-links {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100vh - 60px);
    background: var(--surface);
    flex-direction: column;
    padding: var(--space-6);
    gap: var(--space-3);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
  }
  
  .nav-links.active {
    transform: translateX(0);
  }
  
  .nav-link {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--text-base);
  }
}

/* Mobile Form Enhancements */
@media (max-width: 768px) {
  /* Input/Textarea Enhancements */
  .form-control, .inp, textarea, select {
    padding: 16px;
    font-size: 16px;
    min-height: 48px;
  }

  /* Button Sizing */
  .btn {
    padding: 14px 20px;
    min-width: 120px;
    min-height: 48px;
  }

  /* Form Group Spacing */
  .form-group {
    margin-bottom: 24px;
  }

  /* Stacked Layout */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* Input Types */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"] {
    padding: 14px;
  }

  /* Validation States */
  .form-error {
    font-size: 14px;
    padding: 8px 0;
  }
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  min-height: calc(100dvh - 60px);
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  /* removed overflow:hidden so nested cards render correctly */
}

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

.card-title {
  font-size: var(--text-base);
  font-weight: 600;
}

.card-body {
  padding: var(--space-6);
}

/* card with overflow hidden only when explicitly needed (e.g. tables inside cards) */
.card-overflow { overflow: hidden; }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

/* ── Flex helpers ─────────────────────────────────────────── */
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}
.mb-20 { margin-bottom: 20px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); }

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: var(--text-xs);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: rgba(255,255,255,0.1);
  color: var(--text-muted);
}
.badge-primary   { background: var(--primary-dim); color: var(--primary); }
.badge-success   { background: var(--success-dim); color: var(--success); }
.badge-warning   { background: var(--warning-dim); color: var(--warning); }
.badge-danger    { background: var(--danger-dim);  color: var(--danger); }
.badge-info      { background: var(--info-dim);    color: var(--info); }
.badge-secondary { background: rgba(255,255,255,0.08); color: var(--text-muted); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-4); }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.form-control,
.inp {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control::placeholder,
.inp::placeholder { color: var(--text-faint); }
.form-control:focus,
.inp:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}
.form-control:disabled,
.inp:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea.form-control,
textarea.inp { resize: vertical; min-height: 80px; }

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: var(--space-1);
}

select.form-control,
select.inp { cursor: pointer; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }

thead th,
table tr th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td,
table tr td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td,
table tr:last-child td { border-bottom: none; }
tbody tr:hover,
table tr:hover { background: rgba(255,255,255,0.03); }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--text-muted);
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
  color: var(--text-faint);
}

.empty-state h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--text-sm);
  max-width: 36ch;
  margin-bottom: var(--space-6);
}

/* ── Monitor layout (sidebar + main) ──────────────────────── */
.monitor-layout {
  display: flex;
  gap: 0;
  min-height: calc(100dvh - 60px);
  margin: calc(-1 * var(--space-8));  /* bleed out of .main-content padding */
}

.monitor-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: var(--space-6) 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 60px;
  height: calc(100dvh - 60px);
  overflow-y: auto;
}

.sidebar-header {
  padding: 0 var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-3);
}

.sidebar-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  transition: color var(--transition);
}
.sidebar-back:hover { color: var(--text); }

.sidebar-monitor-info {
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-monitor-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}
.sidebar-monitor-url {
  font-size: var(--text-xs);
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.sidebar-nav {
  padding: 0 var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
}
.sidebar-link:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}
.sidebar-link.active {
  color: var(--primary);
  background: var(--primary-dim);
  font-weight: 500;
}
.sidebar-link svg { flex-shrink: 0; }

.monitor-main {
  flex: 1;
  padding: var(--space-8);
  overflow-x: hidden;
  max-width: calc(1200px - 220px);
}

/* ── Grid utilities ───────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

@media (max-width: 900px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── KPI / stat cards ─────────────────────────────────────── */
.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.kpi-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kpi-good .kpi-value { color: var(--success); }
.kpi-warn .kpi-value { color: var(--warning); }
.kpi-bad  .kpi-value { color: var(--danger); }

/* ── Text utilities ───────────────────────────────────────── */
.text-center  { text-align: center; }
.text-muted   { color: var(--text-muted); }
.text-faint   { color: var(--text-faint); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: var(--text-xs); }
.text-lg      { font-size: var(--text-lg); }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

/* ── Layout helpers ───────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

/* ── Divider ──────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-4) 0;
}

/* ── Code / pre ───────────────────────────────────────────── */
code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.875em;
  background: rgba(255,255,255,0.08);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

pre {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.7;
}
pre code { background: none; padding: 0; }

/* ── Skeleton loader ──────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--card-hover) 50%, var(--surface-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text    { height: 1em;   margin-bottom: var(--space-2); }
.skeleton-heading { height: 1.5em; width: 40%; margin-bottom: var(--space-4); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid transparent;
}
.alert-info    { background: var(--info-dim);    color: var(--info);    border-color: rgba(56,189,248,0.3); }
.alert-success { background: var(--success-dim); color: var(--success); border-color: rgba(34,197,94,0.3); }
.alert-warning { background: var(--warning-dim); color: var(--warning); border-color: rgba(245,158,11,0.3); }
.alert-danger  { background: var(--danger-dim);  color: var(--danger);  border-color: rgba(239,68,68,0.3); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: min(540px, 95vw);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: var(--text-lg); font-weight: 600; }
.modal-body { padding: var(--space-6); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
}

/* ── Loading spinner ──────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Responsive nav ───────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { padding: 0 var(--space-4); }
  .main-content { padding: var(--space-4); }
  .monitor-layout { flex-direction: column; }
  .monitor-sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: var(--space-4);
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .monitor-main { padding: var(--space-4); max-width: 100%; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
