/* ============================================================
   Battery Data Viewer – Hlavní stylesheet
   Strunk Connect CZ, s.r.o.
   ============================================================ */

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

:root {
  --blue:        #0067c0;
  --blue-dark:   #0058a3;
  --blue-light:  #e6f0fb;
  --green:       #16a34a;
  --green-light: #dcfce7;
  --red:         #dc2626;
  --red-light:   #fee2e2;
  --orange:      #ea580c;
  --orange-light:#fff7ed;
  --yellow:      #ca8a04;
  --yellow-light:#fefce8;
  --gray-50:     #f9fafb;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-300:    #d1d5db;
  --gray-400:    #9ca3af;
  --gray-500:    #6b7280;
  --gray-600:    #4b5563;
  --gray-700:    #374151;
  --gray-800:    #1f2937;
  --gray-900:    #111827;
  --white:       #ffffff;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.1);
  --shadow-md:   0 4px 12px rgba(0,0,0,.1);
  --radius:      6px;
  --radius-lg:   10px;
  --header-h:    56px;
  --toolbar-h:   48px;
  --panel-w:     290px;
  --stats-h:     280px;
  --font:        'Segoe UI', Arial, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-100);
  overflow: hidden;
}

/* ============================================================
   APP SHELL LAYOUT
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-h) var(--toolbar-h) auto 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --- Header --- */
.app-header {
  background: var(--blue);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 200;
}
.app-header .logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.app-header .logo-img {
  height: 32px;
  width: auto;
  object-fit: contain;
}
.app-header .header-divider {
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,.3);
  flex-shrink: 0;
}
.app-header .app-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.2px;
}
.app-header .header-spacer { flex: 1; }

/* Admin button */
.admin-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
  margin-right: 8px;
}
.admin-btn:hover { background: rgba(255,255,255,0.25); }

/* Admin Modal */
.admin-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.admin-overlay.hidden { display: none; }
.admin-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 440px;
  max-width: 90vw;
  overflow: hidden;
}
.admin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--primary);
  color: #fff;
}
.admin-modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.admin-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.admin-modal-body {
  padding: 20px;
}
.admin-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin: 0 0 4px;
}
.admin-hint {
  font-size: 11px;
  color: var(--gray-400);
  margin: 0 0 16px;
}
.admin-field {
  margin-bottom: 12px;
}
.admin-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 4px;
}
.admin-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  font-family: 'SF Mono', Consolas, monospace;
  box-sizing: border-box;
}
.admin-input:read-only {
  background: var(--gray-100);
  color: var(--gray-500);
}
.admin-save-btn {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.admin-save-btn:hover { background: #005bb0; }
.admin-msg {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}
.admin-msg.success { background: #dcfce7; color: #166534; }
.admin-msg.error   { background: #fee2e2; color: #991b1b; }

.logout-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: var(--white);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: background .15s;
  white-space: nowrap;
}
.app-header .logout-btn:hover { background: rgba(255,255,255,.25); }

/* --- Toolbar --- */
.app-toolbar {
  background: var(--white);
  border-bottom: 1.5px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  z-index: 100;
  flex-wrap: nowrap;
}
.app-toolbar::-webkit-scrollbar { height: 3px; }
.app-toolbar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--gray-200);
  flex-shrink: 0;
}
.toolbar-label {
  font-size: 12px;
  color: var(--gray-500);
  white-space: nowrap;
  font-weight: 500;
}

/* Line tabs */
.line-tabs {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  padding: 3px;
  border-radius: var(--radius);
}
.line-tab {
  padding: 4px 12px;
  border-radius: 4px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-600);
  font-family: var(--font);
  transition: all .15s;
  white-space: nowrap;
}
.line-tab.active {
  background: var(--blue);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}
.line-tab:not(.active):hover {
  background: var(--gray-200);
  color: var(--gray-800);
}

/* Date inputs */
.date-input {
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--gray-800);
  background: var(--white);
  font-family: var(--font);
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.date-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }

/* Quick buttons */
.quick-btn {
  padding: 5px 11px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
  white-space: nowrap;
}
.quick-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.quick-btn.active { background: var(--blue); color: var(--white); border-color: var(--blue); }

/* Filter radios */
.filter-radio-group {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  padding: 3px;
  border-radius: var(--radius);
}
.filter-radio-group label {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-600);
  transition: all .15s;
  white-space: nowrap;
  user-select: none;
}
.filter-radio-group input[type="radio"] { display: none; }
.filter-radio-group input:checked + label {
  background: var(--blue);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}
.filter-radio-group label:hover { background: var(--gray-200); color: var(--gray-800); }
.filter-radio-group input:checked + label:hover { background: var(--blue); color: var(--white); }

/* Search input */
.search-input {
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 5px 10px 5px 30px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--gray-800);
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 9px center;
  outline: none;
  width: 180px;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.app-body {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  overflow: hidden;
  height: 100%;
}

/* ============================================================
   LEFT PANEL – File list
   ============================================================ */
.file-panel {
  background: var(--white);
  border-right: 1.5px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.file-panel-header {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.file-panel-header h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.file-count {
  font-size: 11px;
  background: var(--blue);
  color: var(--white);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.file-list::-webkit-scrollbar { width: 5px; }
.file-list::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.file-item {
  display: flex;
  align-items: flex-start;
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
  gap: 8px;
}
.file-item:hover { background: var(--gray-50); }
.file-item.selected {
  background: var(--blue-light);
  border-left-color: var(--blue);
}
.file-item-icon {
  flex-shrink: 0;
  margin-top: 2px;
}
.file-item-body { flex: 1; min-width: 0; }
.file-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.file-item.selected .file-item-name { color: var(--blue-dark); }
.file-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.file-item-date {
  font-size: 10px;
  color: var(--gray-500);
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.5;
  letter-spacing: .2px;
}
.badge-ok    { background: var(--green-light);  color: var(--green); }
.badge-nok   { background: var(--red-light);    color: var(--red); }
.badge-today { background: var(--orange-light); color: var(--orange); }
.badge-live  { background: #fff3cd; color: #856404; animation: pulse-badge 2s infinite; }

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50%       { opacity: .6; }
}

.file-panel-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--gray-200);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.footer-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.footer-stat-num {
  font-weight: 800;
  font-size: 15px;
}
.footer-stat-num.num-total { color: var(--blue); }
.footer-stat-num.num-ok    { color: var(--green); }
.footer-stat-num.num-nok   { color: var(--red); }

.file-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--gray-400);
  font-size: 13px;
}

.file-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--gray-400);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}
.file-empty svg { opacity: .4; }

/* ============================================================
   RIGHT PANEL – Table + Stats
   ============================================================ */
.content-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

/* --- Table area --- */
.table-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--gray-50);
}

.table-toolbar {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.table-toolbar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-800);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-row-filter {
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
  outline: none;
  width: 140px;
  transition: border-color .15s;
}
.table-row-filter:focus { border-color: var(--blue); }

.export-btn {
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .15s;
  white-space: nowrap;
}
.export-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.export-btn.pdf:hover { border-color: var(--red); color: var(--red); background: var(--red-light); }

.table-wrap {
  flex: 1;
  overflow: auto;
}
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 900px;
}
.data-table thead th {
  background: var(--gray-800);
  color: var(--white);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
  cursor: pointer;
  user-select: none;
  letter-spacing: .2px;
  border-right: 1px solid rgba(255,255,255,.1);
  transition: background .1s;
}
.data-table thead th:last-child { border-right: none; }
.data-table thead th:hover { background: #2d3748; }
.data-table thead th .sort-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: .5;
  font-size: 9px;
  vertical-align: middle;
}
.data-table thead th.sorted-asc  .sort-icon::after { content: '▲'; opacity: 1; }
.data-table thead th.sorted-desc .sort-icon::after { content: '▼'; opacity: 1; }
.data-table thead th:not(.sorted-asc):not(.sorted-desc) .sort-icon::after { content: '⇅'; }

.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:nth-child(even) { background: var(--white); }
.data-table tbody tr:nth-child(odd)  { background: var(--gray-50); }
.data-table tbody tr:hover           { background: var(--blue-light); }
.data-table tbody tr.row-nok         { background: #fff5f5; }
.data-table tbody tr.row-nok:hover   { background: #fee2e2; }

.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
  vertical-align: middle;
}
.data-table td:first-child { font-weight: 600; color: var(--gray-700); }

/* Cell values */
.cell-ok  { color: var(--green); font-weight: 600; }
.cell-nok { color: var(--red);   font-weight: 700; }

/* Tfoot — NOK součty pod kamerovými sloupci */
.data-table tfoot {
  background: var(--gray-100);
  border-top: 2px solid var(--gray-300);
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.data-table tfoot .tfoot-cell {
  font-size: 10px;
  font-weight: 600;
  padding: 5px 10px;
  color: var(--gray-400);
  text-align: center;
  letter-spacing: .2px;
  white-space: nowrap;
  border-bottom: none;
}
.data-table tfoot .tfoot-nok {
  color: var(--red);
  font-weight: 700;
}
.data-table tfoot .tfoot-zero {
  color: var(--gray-300);
}

/* Klikací NOK buňka s ikonou kamery */
.cell-nok-clickable {
  cursor: pointer;
  position: relative;
  user-select: none;
}
.cell-nok-clickable:hover {
  background: var(--red-light) !important;
}
.cell-nok-clickable .nok-cam-icon {
  display: inline-block;
  vertical-align: middle;
  margin-left: 4px;
  color: var(--red);
  opacity: .6;
  transition: opacity .15s;
}
.cell-nok-clickable:hover .nok-cam-icon {
  opacity: 1;
}
.cell-edited {
  background: #dbeafe !important;
  outline: 1px solid #93c5fd;
  border-radius: 3px;
}

/* Editable cell */
.data-table td[contenteditable="true"] {
  cursor: text;
  outline: none;
}
.data-table td[contenteditable="true"]:focus {
  background: #eff6ff;
  outline: 2px solid var(--blue);
  border-radius: 2px;
}

/* NOK image link */
.nok-img-link {
  color: var(--blue);
  text-decoration: none;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--blue-light);
  transition: background .12s;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  font-family: var(--font);
  font-weight: 500;
}
.nok-img-link:hover { background: #bfdbfe; }

.table-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  gap: 10px;
  color: var(--gray-400);
  font-size: 13px;
  text-align: center;
  padding: 40px;
}
.table-empty-state svg { opacity: .35; }

/* ============================================================
   PALLET KPI BAR — souhrn palet za vybrané období
   ============================================================ */
.pallet-kpi-bar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 10px 20px;
  background: var(--gray-800);
  color: var(--white);
  flex-shrink: 0;
}
.pallet-kpi-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.pallet-kpi-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  opacity: .7;
}
.pallet-kpi-num {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}
.kpi-color-total { color: #60a5fa; }
.kpi-color-ok    { color: #4ade80; }
.kpi-color-nok   { color: #f87171; }
.kpi-color-pct   { color: rgba(255,255,255,.8); }
.pallet-kpi-item.over-threshold .kpi-color-pct {
  color: #f87171;
}
.pallet-kpi-item.over-threshold {
  background: rgba(248,113,113,.2);
  padding: 6px 12px;
  margin: -6px 0;
  border-radius: var(--radius);
  animation: pulse-badge 2s infinite;
}

/* ============================================================
   STATS PANEL — kamerové inspekce pro vybraný soubor
   ============================================================ */
.stats-panel {
  background: var(--white);
  border-top: 2px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stats-header {
  display: flex;
  align-items: center;
  padding: 8px 16px 6px;
  border-bottom: 1px solid var(--gray-200);
  gap: 16px;
  flex-shrink: 0;
}
.stats-header h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.stats-header .stats-summary {
  display: flex;
  gap: 24px;
  margin-left: auto;
}
.stats-kpi {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-600);
}
.stats-kpi .kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.stats-kpi .kpi-num {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--blue);
}

.stats-body {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 6px 12px;
}
.stats-body::-webkit-scrollbar { height: 4px; }
.stats-body::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.stats-table {
  border-collapse: collapse;
  font-size: 11.5px;
  white-space: nowrap;
}
.stats-table th {
  padding: 4px 12px 4px 6px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  font-size: 11px;
  border-bottom: 1.5px solid var(--gray-200);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.stats-table td {
  padding: 4px 12px 4px 6px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table .stat-nok { color: var(--red); font-weight: 700; }
.stats-table .stat-ok  { color: var(--green); font-weight: 600; }
.stats-table .stat-pct {
  font-weight: 500;
  color: var(--gray-500);
}
.stats-table .stat-bar-cell { width: 100px; }
.stats-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--gray-200);
  overflow: hidden;
}
.stats-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--red);
  transition: width .3s ease;
}
.stats-empty {
  color: var(--gray-400);
  font-size: 12px;
  padding: 8px 0;
}

/* Legend */
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  font-size: 10.5px;
  color: var(--gray-500);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 3px;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

/* ============================================================
   NOK IMAGE MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
  overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-title { font-size: 14px; font-weight: 700; color: var(--gray-800); flex: 1; }
.modal-subtitle { font-size: 12px; color: var(--gray-500); }
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--gray-100);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-600);
  transition: background .12s;
  font-size: 16px;
  font-family: var(--font);
}
.modal-close:hover { background: var(--gray-200); }

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-50);
  min-height: 300px;
}
.modal-img {
  max-width: 100%;
  max-height: calc(90vh - 120px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  object-fit: contain;
}
.modal-img-loading {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--gray-400); font-size: 13px;
}
.modal-img-error {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--red); font-size: 13px; text-align: center;
}

.modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-nav-btn {
  padding: 5px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font);
  transition: all .12s;
  color: var(--gray-700);
}
.modal-nav-btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.modal-nav-btn:disabled { opacity: .4; cursor: not-allowed; }
.modal-nav-info { font-size: 12px; color: var(--gray-500); }

/* ============================================================
   SPINNER / LOADER
   ============================================================ */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ============================================================
   LOADING OVERLAY (file / csv loading)
   ============================================================ */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.8);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  color: var(--gray-600);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--gray-800);
  color: var(--white);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .25s ease, toastOut .25s ease forwards;
  animation-delay: 0s, 2.8s;
  pointer-events: auto;
  max-width: 320px;
}
.toast.toast-success { background: var(--green); }
.toast.toast-error   { background: var(--red); }
@keyframes toastIn  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ============================================================
   RESPONSIVE – Mobilní / Tablety < 1100px
   ============================================================ */
@media (max-width: 1100px) {
  :root {
    --panel-w: 100%;
    --stats-h: 240px;
  }
  .app-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .file-panel {
    border-right: none;
    border-bottom: 2px solid var(--gray-200);
    max-height: 220px;
  }
  .app-toolbar { flex-wrap: wrap; height: auto; min-height: var(--toolbar-h); }
  .toolbar-divider { display: none; }
  .search-input { width: 140px; }
}

@media (max-width: 700px) {
  :root { --header-h: 48px; }
  .app-header .app-title { font-size: 13px; }
  .line-tabs { gap: 1px; }
  .line-tab { padding: 4px 8px; font-size: 11px; }
  .stats-panel { display: none; }
  .modal-box { max-height: 95vh; }
}

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.relative { position: relative; }
.hidden { display: none !important; }

/* Search highlight */
.hl {
  background: #fef08a;
  border-radius: 2px;
  padding: 0 1px;
}

/* Scrollbar always visible on table */
.table-wrap { scrollbar-gutter: stable; }
