/* styles.css */
/* Global styles and CSS variables */

:root{
  /* light palette */
  --bg: #f8fafc;            /* page background */
  --card: #ffffff;          /* panels/cards */
  --ink: #0f172a;           /* primary text */
  --muted: #64748b;         /* secondary text */
  --primary: #2563eb;       /* brand blue */
  --accent: #16a34a;        /* green */
  --danger: #dc2626;        /* red */
  --border: #e5e7eb;        /* borders */
  --header: #ffffff;        /* topbar bg */
  --header-border: #e5e7eb; /* topbar border */
  --table-header-bg: #f9fafb;
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --focus: rgba(37,99,235,.15);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0; background:var(--bg); color:var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell;
}

/* Top bar */
.topbar{
  position: sticky; top:0; z-index:10;
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 16px; background:var(--header); border-bottom:1px solid var(--header-border);
}
.brand{ display:flex; align-items:center; gap:8px; font-weight:600; }
.brand svg{ fill:var(--primary); }
.nav a{ color:var(--muted); text-decoration:none; margin-left:16px; }
.nav a.active, .nav a:hover{ color:var(--ink); }

/* Layout */
.layout{
  display:grid; grid-template-columns: 1fr 1.4fr; gap:16px; padding:16px;
  max-width:1400px; margin:0 auto;
}
.panel{ display:flex; flex-direction:column; gap:16px; }
.panel-header{ display:flex; justify-content:space-between; align-items:center; }
.panel h2{ margin:0; font-size:16px; }

/* CRM view should span full width (both columns) */
#secCrm{
  grid-column: 1 / -1;
}

/* Cards */
.card{
  background:var(--card); border:1px solid var(--border); border-radius:12px; padding:12px;
  box-shadow: 0 8px 20px rgba(15,23,42,.06);
}
.card.totals .row{ display:flex; justify-content:space-between; padding:8px 0; border-bottom:1px dashed var(--border); }
.card.totals .row:last-child{ border-bottom:0; }
.total-strong{ font-weight:700; color:var(--ink); }

/* Grid helpers */
.grid{ display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
.grid-3{ grid-template-columns: 2fr 1fr auto; }
@media (max-width: 980px){
  .layout{ grid-template-columns: 1fr; }
  .grid, .grid-3{ grid-template-columns: 1fr; }
}

/* Fields & inputs */
.field{ display:flex; flex-direction:column; gap:6px; }
.field > span{ color:var(--muted); font-size:12px; }
.field input, .field select, input.money-input{
  background:var(--input-bg); border:1px solid var(--input-border); color:var(--ink);
  padding:8px 10px; border-radius:8px; outline:none;
}
.field input::placeholder{ color:#9ca3af; }
.field input:focus, .field select:focus{
  border-color:#93c5fd; box-shadow: 0 0 0 3px var(--focus);
}

/* Read‑only vzhled polí v Obhlídce */
#secInspection :is(input, select, textarea).is-readonly{
  background: #f7f7f7;
  color: var(--muted);
}

/* Read-only (hlavička obhlídky) */
.field input[readonly],
.field textarea[readonly],
.field select:disabled{
  background:#f7f7f7;
  color: var(--muted);
  box-shadow: none;
}

/* Select nemá readonly → vizuálně ho „zamrazíme“ */
#secInspection select.is-readonly{
  pointer-events: none;   /* neklikatelný */
  cursor: default;
}

/* Nepřehánět focus ring u readonly */
#secInspection :is(input, select, textarea).is-readonly:focus{
  border-color: var(--input-border);
  box-shadow: none;
}


/* Buttons */
.actions{ display:flex; gap:8px; align-items:center; }
.btn{
  appearance:none; border:1px solid #e2e8f0; border-radius:8px; padding:8px 12px;
  background:#f1f5f9; color:#111827; cursor:pointer;
}
.btn:hover{ background:#e2e8f0; }
.btn.primary{
  border-color:#2563eb; background:#2563eb; color:#fff; font-weight:700;
}
.btn.primary:hover{ background:#1d4ed8; }
.btn.danger{ border-color:#dc2626; background:#dc2626; color:#fff; }
.btn.danger:hover{ background:#b91c1c; }

/* Tables */
.table-wrap{ overflow:auto; border-radius:8px; border:1px solid var(--border); }
.table{ width:100%; border-collapse: collapse; }
.table thead th{
  font-size:12px; color:#475569; text-transform: uppercase; letter-spacing:.04em;
  background:var(--table-header-bg);
}
.table th, .table td{ padding:10px 12px; border-bottom:1px solid var(--border); }
.table tbody tr:hover{ background:#f1f5f9; }

#tblQuoteOverview tbody tr{ cursor:pointer; }
#tblQuoteOverview tbody tr.selected{ background:#e0f2fe; }
#tblQuoteOverview tbody tr.selected:hover{ background:#bae6fd; }

.quote-overview-actions{ flex-wrap:wrap; }
.quote-overview-actions input{ flex:1; min-width:180px; padding:8px 10px; border:1px solid var(--border); border-radius:8px; background:#fff; }

/* Přehled nabídek: list má omezenou výšku a vlastní scroll */
#cardQuoteOverview .table-wrap{
  max-height: clamp(220px, 40vh, 520px);
}
#cardQuoteOverview .table-wrap thead th{
  position: sticky;
  top: 0;
  z-index: 2;
}
.table td.right, .right{ text-align:right; }
.table td.center{ text-align:center; }

/* Text helpers */
.muted{ color:var(--muted); }
.meta{ margin: 6px 0 0 0; }

/* Footer */
footer.footer{ padding:10px 16px; border-top:1px solid var(--border); color:var(--muted); background:#ffffff80; backdrop-filter:saturate(120%) blur(2px); }

/* Dialogs */
dialog{ border:none; border-radius:12px; padding:0; background:transparent; }
dialog::backdrop{ background: rgba(0,0,0,.35); }

/*
  Některé dialogy stále používají jako wrapper `.panel` (např. CRM Detail,
  picker CRM v reportu, apod.). Protože samotný `<dialog>` má záměrně
  průhledné pozadí (kvůli `.dialog-card`), tak by `.panel` bez vlastního
  pozadí působil "neviditelně".

  Tohle pravidlo dá `.panel` uvnitř dialogu stejné vizuální vlastnosti
  jako karta.
*/
dialog > .panel{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.12);
  overflow: hidden;
  max-height: 92vh;
}

/*
  Některé nové dialogy používají jako wrapper `<form class="modal-content">`
  (typicky pro `method="dialog"`). Pokud wrapper nemá pozadí, dialog působí
  průhledně. Tady sjednotíme vzhled s ostatními kartami v dialogu.
*/
dialog > .modal-content{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.12);
  overflow: hidden;
  max-height: 92vh;
  min-width: min(560px, 96vw);
}

dialog > .modal-content .dialog-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  padding: 12px 12px 0 12px;
}
dialog > .modal-content .dialog-body{ padding: 12px; }
dialog > .modal-content .dialog-footer{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap: 10px;
  padding: 0 12px 12px 12px;
}

dialog > .panel > .panel-header{ padding: 12px 12px 0 12px; }
dialog > .panel > .panel-body{ padding: 12px; }
.dialog-card{
  background:var(--card); border:1px solid var(--border); padding:16px; border-radius:12px;
  min-width: min(560px, 96vw); box-shadow: 0 20px 60px rgba(0,0,0,.12);
}
menu{ display:flex; justify-content:flex-end; gap:8px; margin:12px 0 0 0; padding:0; }

/* === Collapsible cards === */
.card.collapsible .card-bar{
  display:flex; align-items:center; justify-content:space-between;
  margin:-4px -4px 8px; padding:6px 8px; border-radius:8px;
  background: var(--table-header-bg);
  user-select: none;
}
.card.collapsible .bar-title{ font-weight:600; }

.card.collapsible .toggle{
  display:inline-flex; align-items:center; gap:6px;
  border:1px solid var(--border); background:#f1f5f9; color:#111827;
  padding:4px 8px; border-radius:6px; cursor:pointer;
}
.card.collapsible .toggle:hover{ background:#e2e8f0; }

.card.collapsible .chev{ display:inline-block; transition: transform .15s ease; }
.card.collapsible.collapsed .chev{ transform: rotate(-90deg); }

/* skryj obsah karty, nech jen lištu */
.card.collapsible.collapsed > :not(.card-bar){ display:none !important; }

/* Close button on dialogs */
.dialog-card{ position:relative; }
.dialog-close{
  position:absolute; top:8px; right:8px;
  border:1px solid var(--border); background:#f1f5f9; color:#111827;
  border-radius:8px; padding:6px 10px; cursor:pointer; line-height:1;
}
.dialog-close:hover{ background:#e2e8f0; }



#secReportSections .fp-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  user-select: none;
}

#secReportSections .fp-titlebar .bar-title {
  font-weight: 600;
}

#secReportSections .fp-actions .btn { margin-left: 6px; }

#secReportSections .fp-body {
  height: calc(100% - 42px);
  overflow: auto;
  padding: 8px 12px;
}

/* během dragování zobraz kurzor move a vypni text selection */
body.dragging, body.dragging * { cursor: move !important; user-select: none !important; }


/* === Left panel collapse =============================================== */
.left-collapsed .layout{
  grid-template-columns: 1fr; /* pravý panel přes celou šířku */
}

.left-collapsed .layout .panel:first-child{
  display: none; /* levý panel pryč z layoutu */
}

/* “Rail” tlačítko pro rozbalení */
.left-rail{
  position: fixed;
  left: 8px;
  top: 96px;                /* pod horní lištu */
  z-index: 10001;
  display: none;            /* ukáže se jen když je sbaleno */
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0,0,0,.12);
  padding: 8px 12px;
}

.left-collapsed .left-rail{
  display: inline-flex;
}

/* drobná úprava btn-light (pokud chceš jemnější vzhled) */
.btn.btn-light{
  background:#fff;
  border-color: var(--border);
}
.btn.btn-light:hover{
  background:#f8fafc;
}

#secReportSections.floating-panel {
  position: fixed;
  top: 72px;
  left: 72px;
  width: 640px;
  height: 460px;
  max-width: 95vw;
  max-height: 88vh;
  /* ▼ DOPLNIT: pevné minimum */
  min-width: 320px;
  min-height: 160px;

  background: #fff;
  border: 1px solid #dadde1;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,.2), 0 2px 6px rgba(0,0,0,.12);
  z-index: 9999;
  display: none;
  resize: both;
  overflow: hidden;
}


.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px,1fr));
  gap: 8px;
}
.thumb {
  border: 1px solid #eee; padding: 4px; border-radius: 4px; text-align: center;
}
.thumb img {
  max-width: 100%; height: 100px; object-fit: cover; display: block; margin: 0 auto 4px;
}


/* [PL-INSP-CSS:FIELD-PHOTOS:BEGIN] */
.photo-strip { display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; }
.photo-strip .ph { position:relative; width:72px; height:72px; }
.photo-strip .ph img { width:100%; height:100%; object-fit:cover; border:1px solid #ddd; border-radius:4px; display:block; }
.photo-strip .ph button.ph-del {
  position:absolute; right:-6px; top:-6px; width:20px; height:20px;
  border:none; border-radius:50%; background:#e53935; color:#fff; cursor:pointer; line-height:20px;
}
/* [PL-INSP-CSS:FIELD-PHOTOS:END] */


/* [PL-INSP-CSS:GALLERY-CAPTION] */
.thumb .caption{
  margin: 6px 0 8px;
  font-size: 12px;
  color: var(--muted);
}


/* Obhlídka – podsekce */
#secInspection #inspSectionsContainer{
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#secInspection .card.subsec .card-bar{
  background: var(--table-header-bg);
}
#secInspection .card.subsec .subsec-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 980px){
  #secInspection .card.subsec .subsec-grid{ grid-template-columns: 1fr; }
}

/* inline kamera u polí obhlídky */
#secInspection .btn-photo { margin-left: 6px; }
#secInspection .field :is(input, select, textarea) + .btn-photo{
  align-self: flex-start;
  margin-top: 4px;
}

.customer-header { margin: 8px 0 12px; line-height: 1.3; }
.customer-header .muted { color: var(--muted-text, #6b7280); }

/* --- Top nav --- */
#app-nav { position: sticky; top: 0; z-index: 1000; }
.topnav { display: flex; align-items: center; gap: 1rem; background: #f8f9fa; border-bottom: 1px solid #e5e7eb; padding: .5rem 1rem; }
.topnav .nav-brand a { text-decoration: none; font-weight: 600; color: #111827; }
.topnav .nav-burger { margin-left: auto; display: none; background: transparent; border: 1px solid #e5e7eb; padding: .25rem .5rem; border-radius: .25rem; }
.topnav .nav-list { list-style: none; display: flex; gap: .5rem; margin: 0; padding: 0; flex-wrap: wrap; }
.nav-item { position: relative; }
.nav-link, .dropdown-item { display: block; padding: .5rem .75rem; text-decoration: none; color: #111827; border-radius: .375rem; }
.nav-link:hover, .dropdown-item:hover { background: #eef2ff; }
.nav-link.active, .dropdown-item.active { background: #e0e7ff; font-weight: 600; }
.dropdown-menu { position: absolute; left: 0; top: 100%; min-width: 220px; background: white; border: 1px solid #e5e7eb; border-radius: .375rem; padding: .25rem 0; display: none; box-shadow: 0 10px 20px rgba(0,0,0,.06); }
.nav-item.dropdown.open > .dropdown-menu { display: block; }
@media (max-width: 768px) {
  .topnav { flex-wrap: wrap; }
  .topnav .nav-burger { display: inline-block; }
  .topnav.open .nav-list { display: block; width: 100%; }
  .nav-list { display: none; }
  .dropdown-menu { position: static; border: 0; box-shadow: none; }
}

/* Global nav nahoře */
#global-nav { position: sticky; top: 0; z-index: 1100; }

/* Starý topbar zůstane pod ním – většinou není třeba nic měnit */

/* === ANCHOR: NAV_ENHANCE (BEGIN) === */

/* -------------------------------------------------------------------------
   Hamburger menu (always collapsed by default)
   ------------------------------------------------------------------------- */

/* Hlavička může zalomit na více řádků (brand + burger, pak rozbalené menu). */
#app-nav.topbar{ flex-wrap: wrap; }

/* Burger je vždy vidět. */
#app-nav .topbar-burger{
  margin-left: auto;
  display: inline-block;
  background: transparent;
  border: 1px solid #e5e7eb;
  padding: .25rem .55rem;
  border-radius: .375rem;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* Navigace: defaultně schovaná (menu je „zavřené“). */
#app-nav .nav{ width: 100%; }
#app-nav:not(.open) .nav{ display: none; }

/* Otevřený stav: zobraď jako „drawer“ (svisle, celá šířka). */
#app-nav.open .nav{
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0,0,0,.08);
}

/* Zruš globální odsazování odkazů v .nav (ve „drawer“ režimu by to rušilo). */
#app-nav .nav a{ margin-left: 0; }

/* Skupiny v hamburger menu */
#app-nav .nav.nav-drawer .nav-section{
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#app-nav .nav.nav-drawer .nav-section-title{
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 2px 4px;
}

/* Položky */
#app-nav .nav.nav-drawer .nav-link,
#app-nav.open .nav > a{
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: #111827;
}
#app-nav .nav.nav-drawer .nav-link:hover,
#app-nav.open .nav > a:hover{ background: #eef2ff; }
#app-nav .nav.nav-drawer .nav-link.active,
#app-nav.open .nav > a.active{ background: #e0e7ff; font-weight: 600; }

/* Uživatelská část (jméno + odhlášení) */
#app-nav .nav.nav-drawer .nav-user{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
#app-nav .nav.nav-drawer .nav-user #navLogout{
  border: 1px solid var(--border);
  background: #f1f5f9;
  padding: 8px 10px;
  border-radius: 10px;
}
#app-nav .nav.nav-drawer .nav-user #navLogout:hover{ background:#e2e8f0; }

/* Dropdowny (ponecháno pro kompatibilitu; v drawer režimu se chovají jako vnořené položky) */
#app-nav .nav .nav-item{
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
#app-nav .nav .nav-caret{
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: .9em;
  padding: 2px 4px;
}
#app-nav .nav .dropdown-menu{
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  min-width: 220px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 10px 20px rgba(0,0,0,.06);
  padding: 4px 0;
  display: none;
  z-index: 1200;
}
#app-nav .nav .dropdown-menu li{ list-style: none; }
#app-nav .nav .dropdown-menu .dropdown-item{
  display: block;
  padding: 8px 12px;
  text-decoration: none;
  color: #374151;
}
#app-nav .nav .dropdown-menu .dropdown-item:hover{ background: #eef2ff; }
#app-nav .nav .nav-item.open > .dropdown-menu{ display: block; }

/* Přístupnost: focus ring pro ovládací prvky v nav */
#app-nav .topbar-burger:focus-visible,
#app-nav .nav .nav-caret:focus-visible,
#app-nav .nav a:focus-visible{
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
/* === ANCHOR: NAV_ENHANCE (END) === */

/* ALERT_STYLE_PATCH */
.table td.alert-note{ color:#a62; font-style:italic; max-width:24rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* === Mobile-first card lists (CRM, obhlídky, administrace) ================ */
.list-cards{ display:flex; flex-direction:column; gap:10px; }
.list-card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 8px 20px rgba(15,23,42,.06);
}
.list-card .lc-title{ font-weight: 700; }
.list-card .lc-meta{ color: var(--muted); font-size: 13px; margin-top: 4px; }
.list-card .lc-actions{ display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }

/* Hide mobile card lists by default (shown only on small screens) */
.crm-list,
.insp-list,
.admin-list,
.tpl-list,
.crm-pick-list{
  display: none;
}

@media (max-width: 900px){
  .panel-header{ flex-direction: column; align-items: stretch; gap: 10px; }
  .panel-header .actions{ width: 100%; }
  .actions{ flex-wrap: wrap; }
  .actions :is(input, select){ flex: 1 1 220px; min-width: 0; }

  /* CRM */
  #crmTableWrap{ display: none; }
  .crm-list{ display: flex; }

  /* Inspections report */
  #inspTableWrap{ display: none; }
  .insp-list{ display: flex; }

  /* CRM picker dialog */
  #crmPickTableWrap{ display: none; }
  .crm-pick-list{ display: flex; }

  /* Admin */
  #usersTableWrap,
  #customersTableWrap{
    display: none;
  }
  .admin-list{ display: flex; }

  /* Templates */
  #tplTableWrap{ display: none; }
  .tpl-list{ display: flex; }
}

/* === Global loading overlay ============================================= */
#loading-overlay{
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,.6);
  backdrop-filter: blur(2px);
  z-index: 10000;
}
#loading-overlay.show{ display: flex; }
#loading-overlay .spinner{
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Quote Builder ===================================================== */
.qb-layout{ display: grid; grid-template-columns: 260px 1fr; gap: 12px; }
.qb-sidebar{ border-right: 1px solid var(--border); padding-right: 12px; }
.qb-section-list{ display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.qb-section{ display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.qb-section.active{ background: #f5f7fb; border-color: #d7dbe6; }
.qb-section .meta{ font-size: 12px; opacity: .75; }
.qb-section-actions{ display: flex; gap: 6px; }
.qb-section-actions button{ padding: 4px 8px; }
.qb-table td input[type="number"],
.qb-table td input[type="text"],
.qb-table td select{ width: 100%; }
.qb-table td.actions{ white-space: nowrap; }

/* Quote Builder: name cell (readable text + inline rename) */
.qb-item-name-row{ display:flex; align-items:flex-start; gap:8px; }
.qb-name-label{ font-weight:600; white-space:normal; word-break:break-word; }
.btn.btn-icon{ padding: 4px 8px; line-height: 1.1; }
.qb-name-edit{ width:100%; }
.qb-item-sub code{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

/* === Quote Template Editor ============================================= */
.qt-grid{ display: grid; grid-template-columns: 260px 1fr; gap: 12px; }
.qt-sidebar{ border-right: 1px solid var(--border); padding-right: 12px; }
.qt-section-list{ display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.qt-section{ display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.qt-section.active{ background: #f5f7fb; border-color: #d7dbe6; }
.qt-section .meta{ font-size: 12px; opacity: .75; }
.qt-table td input[type="number"],
.qt-table td input[type="text"],
.qt-table td select{ width: 100%; }
