/* Design System Tokens */
:root {
  /* Colors - Modern Dark/Industrial Theme */
  --bg-base: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #334155;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  
  --status-ok: #10b981; /* Green > 3 days */
  --status-warning: #f59e0b; /* Yellow 1-3 days */
  --status-danger: #ef4444; /* Red due/overdue */
  --status-tested: #64748b; /* Gray tested */
  
  --border-color: rgba(255, 255, 255, 0.1);
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  
  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  
  /* Radii */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* App Layout handles scroll */
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
}

a {
  color: var(--primary);
  text-decoration: none;
}

ul {
  list-style: none;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
}

.sidebar-header {
  height: 76px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
}

.logo img {
  max-height: 52px;
  width: auto;
  filter: drop-shadow(0 2px 8px rgba(14, 165, 233, 0.25));
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(to right, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  color: transparent;
}

.nav-links {
  flex: 1;
  padding: var(--space-4) 0;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-link.active {
  color: var(--primary);
  background-color: rgba(14, 165, 233, 0.1);
  border-left-color: var(--primary);
}

.sidebar-footer {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Important for flex children to truncate */
}

.topbar {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
}

.view-container {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
}

/* Glassmorphism Cards */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 0 15px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
}

/* Native Dialog (Modal) */
.glass-dialog {
  margin: auto;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
}

.glass-dialog::backdrop {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
}

dialog:not([open]) {
  display: none !important;
}

dialog[open], .glass-dialog[open] {
  display: block !important;
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  margin: 0 !important;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 999999 !important;
}

.glass-dialog h3 {
  margin-bottom: var(--space-2);
}

.glass-dialog p {
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-size: 0.875rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

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

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

input, select, textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.25);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-ok { background-color: rgba(16, 185, 129, 0.2); color: var(--status-ok); }
.badge-warning { background-color: rgba(245, 158, 11, 0.2); color: var(--status-warning); }
.badge-danger { background-color: rgba(239, 68, 68, 0.2); color: var(--status-danger); }
.badge-tested { background-color: rgba(100, 116, 139, 0.2); color: var(--text-muted); }

/* Utilities */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.view {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.view.active {
  display: block;
}

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

/* Grid System for Dashboard */
.grid-dashboard {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-6);
}

.col-span-full { grid-column: span 12; }
.col-span-8 { grid-column: span 8; }
.col-span-4 { grid-column: span 4; }

@media (max-width: 1024px) {
  .col-span-8, .col-span-4 { grid-column: span 12; }
}

@media (max-width: 768px) {
  /* Tablet layout for RasPi */
  .sidebar {
    width: 60px;
  }
  .logo-text, .nav-link span {
    display: none;
  }
  .nav-link {
    justify-content: center;
    padding: var(--space-4) 0;
  }
}
