/* ============================================
   Dashboard — Sidebar layout + shared styles
   ============================================ */

/* Optimalizace pro Safari / macOS (vendor prefixy, scrollbary, autofill) */
@import url('safari-compat.css');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1e1e2e;
  --surface: #282840;
  --surface2: #313150;
  --text: #e0e0f0;
  --text2: #a0a0c0;
  --accent: #6c8cff;
  --accent2: #4ecdc4;
  --border: #3a3a5c;
  --sidebar-w: 250px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-logo svg {
  width: 36px;
  height: 36px;
  display: block;
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 600;
}
.sidebar-header p {
  font-size: 11px;
  color: var(--text2);
  margin-top: 1px;
}

.sidebar-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text2);
  padding: 16px 20px 8px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.15s;
  margin-bottom: 2px;
  cursor: pointer;
  border: 1px solid transparent;
}
.sidebar-item:hover {
  background: var(--surface2);
  color: var(--text);
}
.sidebar-item.active {
  background: rgba(108, 140, 255, 0.12);
  color: var(--text);
  border-color: rgba(108, 140, 255, 0.25);
}
.sidebar-item.disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.sidebar-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.sidebar-item-info {
  flex: 1;
  min-width: 0;
}
.sidebar-item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-item-tag {
  font-size: 10px;
  margin-top: 1px;
  opacity: 0.6;
}

.sidebar-user {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
  text-align: center;
}

/* === MAIN CONTENT === */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.main-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.main-header-right {
  font-size: 12px;
  color: var(--text2);
}

.main-content {
  flex: 1;
  padding: 28px 32px;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.2); }
.btn-danger { background: #5c2a2a; border-color: #7a3a3a; color: #ff8888; }
.btn-danger:hover { background: #7a3a3a; color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* === MODULE CARDS (for welcome page) === */
.welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.welcome-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(108, 140, 255, 0.12);
}
.welcome-card.placeholder {
  border-style: dashed;
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.welcome-card-title { font-size: 15px; font-weight: 600; }
.welcome-card-desc { font-size: 12px; color: var(--text2); line-height: 1.5; }

/* === SIMULATION LIST === */
.sim-list { display: flex; flex-direction: column; gap: 10px; }

.sim-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.2s;
}
.sim-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(108, 140, 255, 0.1);
}

.sim-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(139,92,246,0.15);
  color: #8b5cf6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sim-info { flex: 1; min-width: 0; }
.sim-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sim-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text2);
  flex-wrap: wrap;
}

.sim-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 14px; line-height: 1.6; margin-bottom: 20px; }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 380px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.5);
}
.modal-box h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-box p { font-size: 13px; color: var(--text2); margin-bottom: 18px; line-height: 1.5; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* === RENAME INPUT === */
.rename-input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  width: 100%;
  max-width: 300px;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 13px;
  color: var(--text);
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === HAMBURGER MENU BUTTON === */
.hamburger-btn {
  display: none; /* hidden on desktop */
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ============================================
   RESPONSIVE — Mobile & Tablet
   ============================================ */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 0px;
  }

  /* Hamburger visible */
  .hamburger-btn {
    display: flex;
  }

  /* Sidebar slides in/out */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 150;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }

  /* Main content full width */
  .main-wrapper {
    margin-left: 0 !important;
  }

  /* Header */
  .main-header {
    padding: 14px 16px;
    padding-left: 56px; /* space for hamburger */
  }
  .main-header h2 {
    font-size: 16px;
  }

  /* Content */
  .main-content {
    padding: 16px;
  }

  /* Welcome grid — single column */
  .welcome-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .welcome-card {
    padding: 16px;
  }

  /* Buttons — larger touch targets */
  .btn {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 40px;
  }
  .btn-sm {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  /* Simulation cards */
  .sim-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px;
  }
  .sim-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Modal — full width */
  .modal-overlay {
    align-items: flex-end;
  }
  .modal-box {
    width: 100%;
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 85vh;
    overflow-y: auto;
  }

  /* AI button — adjust position */
  .ai-fab {
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
  }
}

/* Module page specific responsive */
@media (max-width: 768px) {
  /* Module header */
  .module-header {
    padding: 16px !important;
    padding-left: 56px !important; /* hamburger space */
  }
  .module-header h1 {
    font-size: 18px !important;
  }
  .module-header-icon,
  .module-icon {
    font-size: 28px !important;
    width: 40px !important;
    height: 40px !important;
  }

  /* Tabs — scrollable */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px !important;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    white-space: nowrap;
    padding: 10px 14px !important;
    font-size: 12px !important;
  }

  /* Stats bar */
  .stats-bar {
    padding: 12px !important;
    gap: 8px !important;
    overflow-x: auto;
    flex-wrap: nowrap !important;
  }
  .stat-card {
    min-width: 120px !important;
    padding: 12px !important;
    flex-shrink: 0;
  }
  .stat-card .stat-value {
    font-size: 22px !important;
  }

  /* Content */
  .content {
    padding: 0 12px 16px !important;
  }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .toolbar input[type="text"] {
    width: 100% !important;
  }

  /* Data tables — horizontal scroll */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Form grids — single column */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* Modal on module pages */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 14px 14px 0 0 !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
  }

  /* Permissions matrix scroll */
  .perm-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Org chart scroll */
  .org-chart-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .org-level-cards {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }
  .org-card {
    min-width: 220px;
  }
}

/* Small phones */
@media (max-width: 400px) {
  .main-header {
    padding: 10px 12px 10px 52px;
  }
  .main-content {
    padding: 12px;
  }
  .welcome-card {
    padding: 14px;
  }
  .welcome-card-title {
    font-size: 14px;
  }
}

/* =============================================================================
   iOS / Mobile optimalizace — globálně pro celý HolyOS
   ============================================================================= */

/* Disable double-tap zoom & blue tap highlight na všech tlačítkách / odkazech /
   interaktivních prvcích. Touch-action: manipulation zachová pinch-zoom u textu,
   ale potlačí nechtěný 300ms double-tap delay. */
button,
a,
.btn,
.tab,
.sidebar-item,
.welcome-card,
input[type="checkbox"],
input[type="radio"],
select,
[onclick],
[role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* iOS Safari na vstupech s font-size <16 px ZOOM-uje stránku po fokusu —
   to je nepříjemné a po zrušení neumí samo odzoomovat. Globální opt-out. */
@media (hover: none) and (pointer: coarse) {
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="search"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="month"],
  input[type="week"],
  input[type="time"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Safe-area pro iPhone X+ (notch / home indicator) — sidebar a topbar dotykově
   nepřekrývejí systémové prvky. Body padding pokrývá fallback. */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* Top-bar (js/top-bar.js .holyos-topbar) — posuneme o safe-area-top */
  .holyos-topbar {
    padding-top: env(safe-area-inset-top) !important;
    height: calc(44px + env(safe-area-inset-top)) !important;
  }
  /* Hamburger v rohu — taky pod safe-area */
  .hamburger-btn {
    top: calc(8px + env(safe-area-inset-top)) !important;
  }
  /* Module headers se posunou o totéž — ať se nevpíchnou pod statusbar */
  .main-header,
  .module-header,
  .page-header {
    padding-top: calc(20px + env(safe-area-inset-top));
  }
}

/* Zabraň "rubber-band" scrollu (overscroll bouncing) na hlavním obsahu —
   jinak iOS po krajním scrollu odhaluje pozadí, což rozbíjí dojem aplikace. */
html, body {
  overscroll-behavior-y: contain;
}

/* Sidebar na mobilu — momentum scrolling + nezachytí systémový gest swipe
   from edge, který přivolává Control Center / app switcher. */
.sidebar {
  -webkit-overflow-scrolling: touch;
}

/* Modal-overlay na mobilu — drž se nad klávesnicí, neschovávej obsah pod ní.
   max-height bere v potaz visualViewport (CSS proměnná --vh nastavujeme v JS,
   pokud je definovaná, jinak fallback 100vh). */
@media (max-width: 768px) {
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal,
  .modal-box {
    max-height: 92vh !important;
    max-height: calc(var(--vh, 1vh) * 92) !important;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Form-row v modálech (Účetní doklady, AI atd.) */
  .modal-row,
  .form-row {
    margin-bottom: 12px;
  }

  /* form-grid uvnitř modálu — jeden sloupec, lepší pro úzkou obrazovku */
  .modal .modal-grid2,
  .modal .modal-grid3,
  .modal-box .modal-grid2,
  .modal-box .modal-grid3 {
    grid-template-columns: 1fr !important;
  }

  /* Detail-header (faktury) — víc jak 6 sloupců nemá smysl na mobilu */
  .detail-header {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .detail-col {
    min-width: 0;
  }

  /* Tabulky které mají inline data-table style — také scroll horizontálně */
  table {
    -webkit-overflow-scrolling: touch;
  }

  /* Větší touch terče na ikonové tlačítka — 🗑️ ✏️ 👁️ atp. */
  .btn-sm {
    min-width: 36px;
    min-height: 36px;
  }

  /* Stat-card hodnoty — drobnější písmo na úzké obrazovce */
  .stat-card .stat-value {
    font-size: 18px !important;
  }
}

/* iPhone SE / 5 / starší (≤375 px) — ještě úspornější padding */
@media (max-width: 380px) {
  .main-content,
  .content {
    padding: 8px !important;
  }
  .btn {
    padding: 8px 12px !important;
    font-size: 13px !important;
  }
  .data-table th,
  .data-table td {
    padding: 6px 8px !important;
    font-size: 12px !important;
  }
  /* AI floating bubble vlevo dole — mobilní layout */
  .ai-fab {
    width: 36px !important;
    height: 36px !important;
  }
}

/* Prevent text-selection bubbles na nedotčitelných UI prvcích (buttony, ikony) */
.btn,
.sidebar-item,
.tab,
.hamburger-btn,
.welcome-card-title,
.sidebar-icon,
.holyos-topbar {
  -webkit-user-select: none;
  user-select: none;
}

/* Inputs ale výběr POVOLENÉ — chceme aby šlo zkopírovat */
input,
textarea,
[contenteditable="true"] {
  -webkit-user-select: auto;
  user-select: auto;
}
