/* ==========================================================================
   SolidusTech UI — MOBILE-FIRST REDESIGN
   Base: 320px+ (Mobile) → 768px+ (Tablet) → 1024px+ (Desktop)
   ========================================================================== */

/* ========== MOBILE FIRST (320px+) ========== */

/* ---------- 0) Reset & Viewport Fix ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  scroll-behavior: smooth;
  font-size: 16px; /* Base pro rem */
}

body {
  font-family: "Inter", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  font-size: 1rem; /* 16px */
  line-height: 1.6;
  color: #0f172a;
  background: #ffffff;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden; /* Prevent horizontal scroll */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: #2563eb;
  text-decoration: none;
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
}

a:active {
  opacity: 0.7;
}

:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- 1) Design Tokens ---------- */
:root {
  /* Colors */
  --brand: #1f3b72;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0ea5e9;
  
  /* Spacing (Mobile first - menší mezery) */
  --space-xs: 0.25rem; /* 4px */
  --space-sm: 0.5rem; /* 8px */
  --space-md: 1rem; /* 16px */
  --space-lg: 1.5rem; /* 24px */
  --space-xl: 2rem; /* 32px */
  
  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  
  /* Touch Target Size (WCAG AAA) */
  --touch-min: 48px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition: 250ms ease;
}

/* ---------- 2) Layout Container (Mobile First) ---------- */
.container {
  width: 100%;
  max-width: 100%;
  padding: 0 var(--space-md); /* 16px sides */
  margin: 0 auto;
}

/* ---------- 3) Typography (Mobile Optimized) ---------- */
h1 {
  font-size: 1.75rem; /* 28px */
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--space-md);
  color: var(--text);
}

h2 {
  font-size: 1.5rem; /* 24px */
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: var(--space-md);
  color: var(--text);
}

h3 {
  font-size: 1.25rem; /* 20px */
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: var(--space-sm);
  color: var(--text);
}

p {
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

.muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ---------- 4) Buttons (Touch Friendly - 48px min) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: var(--touch-min);
  padding: 0 var(--space-lg);
  border-radius: var(--radius-md);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f8dfc);
  color: white;
  box-shadow: var(--shadow);
}

.btn-primary:active {
  background: var(--accent-hover);
}

.btn-secondary {
  background: white;
  color: var(--accent);
  border: 2px solid var(--border);
}

.btn-secondary:active {
  background: var(--bg-secondary);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-sm {
  min-height: 40px;
  padding: 0 var(--space-md);
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

/* ---------- 5) Forms (Mobile First - Full Width) ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  width: 100%;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
}

.label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  margin-bottom: var(--space-xs);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-md);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--text);
  background: white;
  transition: border-color var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input::placeholder {
  color: var(--text-muted);
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

/* Form Row - Mobile: Stack, Tablet: 2 cols */
.form-row {
  display: grid;
  grid-template-columns: 1fr; /* Mobile: 1 column */
  gap: var(--space-md);
}

/* ---------- 6) Cards ---------- */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-lg);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

/* ---------- 7) Tables (Mobile: Responsive Wrapper) ---------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-lg);
}

.table {
  width: 100%;
  min-width: 600px; /* Force scroll on mobile */
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
}

.table th {
  background: var(--bg-secondary);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
}

.table td {
  font-size: 0.875rem;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--bg-secondary);
}

/* Inline tables (legacy style.css classes) */
.table-inline {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-scrollable {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: white;
  max-height: none; /* Remove desktop height constraint */
}

.table-scrollable .table-inline {
  width: 100%;
  min-width: 500px; /* Ensure horizontal scroll on mobile */
}

.table-header {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-header th {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  color: #374151;
  font-weight: 600;
  white-space: nowrap;
}

.table-header .th-center {
  text-align: center;
  width: auto;
  min-width: 50px;
}

.table-header .th-left {
  text-align: left;
}

.table-header .th-right {
  text-align: right;
}

.table-header .th-cnt {
  text-align: center;
  width: auto;
  min-width: 70px;
}

.table-row-data {
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
}

.table-row-data:active {
  background: #f8fafc;
}

.table-row-data td {
  padding: 12px 8px;
  font-size: 13px;
}

.td-center {
  text-align: center;
  color: #6b7280;
  font-weight: 500;
  white-space: nowrap;
}

.td-left {
  color: #374151;
}

.td-right {
  text-align: right;
  color: #111827;
  font-weight: 600;
  white-space: nowrap;
}

.td-mono {
  text-align: center;
  color: #111827;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  white-space: nowrap;
}

.td-date-cell {
  white-space: normal;
}

.date-primary {
  font-weight: 600;
  color: #1e40af;
  font-size: 13px;
}

.date-secondary {
  color: #64748b;
  font-size: 12px;
  margin-top: 2px;
}

.td-cnt-cell,
.td-stav-cell,
.td-temp-max-cell,
.td-temp-min-cell,
.td-battery-cell {
  white-space: nowrap;
}

/* Mobile Table - Card View (Optional Alternative) */
.table-cards {
  display: grid;
  gap: var(--space-md);
}

.table-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.table-card-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
}

.table-card-row:last-child {
  border-bottom: none;
}

.table-card-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.table-card-value {
  font-size: 0.875rem;
  color: var(--text);
  text-align: right;
}

/* Mobile table optimizations */
@media (max-width: 768px) {
  /* Card padding override for full-width tables */
  .card {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }
  
  .table-container {
    width: calc(100% + calc(var(--space-md) * 2)) !important;
    max-width: calc(100% + calc(var(--space-md) * 2)) !important;
    margin-left: calc(-1 * var(--space-md)) !important;
    margin-right: calc(-1 * var(--space-md)) !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  
  .table-scrollable {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    border: none;
    border-radius: 0;
    margin: 0;
    padding: 0 var(--space-md);
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  
  .table-scrollable .table-inline {
    min-width: 850px; /* Force horizontal scroll - show all columns */
    width: auto;
  }
  
  .table-header th {
    padding: 12px 10px;
    font-size: 13px;
    white-space: nowrap;
  }
  
  .table-row-data td {
    padding: 12px 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  
  .table-header .th-center,
  .table-header .th-cnt {
    min-width: 60px;
    width: auto;
  }
  
  .date-primary {
    font-size: 13px;
  }
  
  .date-secondary {
    font-size: 11px;
  }
  
  .td-mono {
    font-size: 11px;
  }
  
  /* Mobile: Show EITHER graph OR table, not both */
  .chart-table-container.side-by-side {
    flex-direction: column !important;
  }
  
  /* When table is visible (side-by-side class), hide the chart */
  .chart-table-container.side-by-side .chart-container {
    display: none !important;
  }
  
  .chart-table-container.side-by-side .table-container {
    display: block !important;
    width: calc(100% + calc(var(--space-md) * 2)) !important;
    max-width: calc(100% + calc(var(--space-md) * 2)) !important;
    border-left: none !important;
    border-top: none !important;
    padding: 0 !important;
    margin: 0 !important;
    margin-left: calc(-1 * var(--space-md)) !important;
    margin-right: calc(-1 * var(--space-md)) !important;
  }
  
  /* When table is hidden (no side-by-side class), show only chart */
  .chart-table-container:not(.side-by-side) .chart-container {
    display: block !important;
    width: 100% !important;
  }
  
  .chart-table-container:not(.side-by-side) .table-container {
    display: none !important;
  }
}

/* ---------- 8) Navigation (Mobile: Hamburger + Drawer) ---------- */
/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: white;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  gap: var(--space-md);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--brand);
  text-decoration: none;
}

.logo-icon {
  font-size: 1.5rem;
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
  position: fixed !important;
  top: 16px !important;
  left: 16px !important;
  z-index: 10001 !important;
  width: 48px !important;
  height: 48px !important;
  background: linear-gradient(135deg, #007bff, #0056b3) !important;
  border: none !important;
  border-radius: 12px !important;
  cursor: pointer !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  -webkit-tap-highlight-color: transparent !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.mobile-menu-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
}

.hamburger-line {
  width: 24px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Hamburger animation when active */
.mobile-menu-toggle.active .hamburger-line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active .hamburger-line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.mobile-menu-overlay.active {
  display: block !important;
  opacity: 1 !important;
  pointer-events: all !important;
  visibility: visible !important;
}

/* Sidebar Navigation (Mobile: Hidden by default, shown via toggle) */
.nav-sidebar,
.modern-sidebar.nav-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  height: 100vh;
  background: white;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: var(--space-lg);
  -webkit-overflow-scrolling: touch;
}

.nav-sidebar.open,
.nav-sidebar.mobile-open,
.modern-sidebar.nav-sidebar.mobile-open {
  transform: translateX(0) !important;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2) !important;
  display: block !important;
  visibility: visible !important;
}

/* Nav Overlay (Mobile: dimmed background when menu open) */
.nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.nav-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Nav Items */
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: var(--touch-min);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.nav-item:active {
  background: var(--bg-secondary);
}

.nav-item.active {
  background: #eff6ff;
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

/* ---------- 9) Dashboard Stats (Mobile: 1 column) ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr; /* Mobile: 1 column */
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.stat-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--accent);
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-xs);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ---------- 10) Charts (Mobile: Full Width) ---------- */
.chart-responsive {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 250px;
  min-height: 250px;
  max-height: 250px;
  margin-bottom: var(--space-lg);
  overflow: hidden;
}

.chart-responsive canvas {
  max-width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Chart containers - prevent growth loops */
.chart-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 250px;
  min-height: 250px;
  max-height: 250px;
  overflow: hidden;
}

/* ---------- 11) Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-md);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

/* ---------- 12) Utilities ---------- */
.hide-mobile {
  display: none;
}

.show-mobile {
  display: block;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }

/* ---------- 13) Grid Utilities (Mobile: 1 col, override later) ---------- */
.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr; /* Mobile: stack */
  gap: var(--space-md);
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr; /* Mobile: stack */
  gap: var(--space-md);
}

/* ========== TABLET (768px+) ========== */
@media (min-width: 768px) {
  /* Container */
  .container {
    padding: 0 var(--space-xl); /* 32px sides */
    max-width: 1400px;
  }
  
  /* Typography */
  h1 {
    font-size: 2.25rem; /* 36px */
  }
  
  h2 {
    font-size: 1.875rem; /* 30px */
  }
  
  h3 {
    font-size: 1.5rem; /* 24px */
  }
  
  /* Form Rows - 2 columns on tablet */
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
  
  /* Stats Grid - 2 columns */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Grid Utilities */
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Show/Hide */
  .hide-mobile {
    display: block;
  }
  
  .show-mobile {
    display: none;
  }
}
  
/* ========== DESKTOP (1024px+) ========== */
@media (min-width: 1024px) {
  /* Hide mobile menu toggle on desktop */
  .mobile-menu-toggle {
    display: none !important;
  }
  
  .mobile-menu-overlay {
    display: none !important;
  }
  
  /* Sidebar - Fixed on desktop */
  .nav-sidebar,
  .modern-sidebar.nav-sidebar {
    position: fixed;
    left: 0;
    width: 280px;
    max-width: 280px;
    transform: translateX(0) !important;
  }
  
  /* Main content - Add left margin for sidebar */
  .main-content {
    margin-left: 280px !important;
  }
  
  /* No overlay needed on desktop */
  .nav-overlay {
    display: none;
  }
  
  /* Typography */
  h1 {
    font-size: 2.5rem; /* 40px */
  }
  
  h2 {
    font-size: 2rem; /* 32px */
  }
  
  /* Stats Grid - 4 columns */
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Grid Utilities */
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Charts - Larger on desktop */
  .chart-responsive {
    height: 400px;
    min-height: 400px;
    max-height: 400px;
  }
  
  .chart-container {
    height: 400px;
    min-height: 400px;
    max-height: 400px;
  }
  
  /* Tables - Reset min-width for large screens */
  .table {
    min-width: 100%;
  }
}

/* ========== LARGE DESKTOP (1440px+) ========== */
@media (min-width: 1440px) {
  .container {
    max-width: 1400px;
  }
}

/* ========== PRINT ========== */
@media print {
  .nav-sidebar,
  .mobile-menu-toggle,
  .nav-overlay,
  .btn {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
  }
}
