/* =========================================================================
 * Kalkulačka kazetového podhledu — „digitální rýsovací prkno“
 * Tmavá pracovní deska, na ní dva listy: výkres a výkaz materiálu.
 * ========================================================================= */

:root {
  --bg: #232A34;            /* pracovní deska */
  --bg-deep: #1B212A;
  --panel: #2A323E;         /* panely na desce */
  --panel-edge: #37414F;
  --field: #1F2630;
  --text: #E9ECF0;
  --text-dim: #94A0AE;
  --text-faint: #6B7684;
  --accent: #E8A33D;        /* jantar — primární akce */
  --accent-ink: #2A2113;
  --paper: #FCFCFA;         /* list výkresu */
  --ink: #222B36;           /* tuš na papíru */
  --ink-dim: #66707C;
  --ok: #3F9B58;
  --warn: #E06A4F;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 6px;
  --shadow-sheet: 0 1px 2px rgba(0,0,0,.35), 0 12px 40px -12px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(255,255,255,.045), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* čísla všude tabulkově zarovnaná */
input[type="number"], output, .mono, td.c-num, .stat b, .edge b, .legend b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ============================== hlavička ============================== */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--panel-edge);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; color: var(--text); flex: none; }
.brand-text { min-width: 0; }
.brand-eyebrow {
  display: block; font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 1px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.topbar h1 {
  font-size: 16px; font-weight: 650; margin: 0; letter-spacing: .01em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.actions { display: flex; align-items: center; gap: 8px; }
.actions-sep { width: 1px; height: 22px; background: var(--panel-edge); margin: 0 4px; }

/* ============================== tlačítka ============================== */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  font: 600 12.5px/1 var(--sans); letter-spacing: .02em;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--panel-edge); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: #333D4B; border-color: #465364; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #F2B254; border-color: #F2B254; }
.btn-accent { background: rgba(232,163,61,.14); border-color: rgba(232,163,61,.45); color: var(--accent); }
.btn-accent:hover { background: rgba(232,163,61,.22); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(255,255,255,.06); }
.btn-sm { padding: 5px 10px; font-size: 11.5px; }

/* ============================== rozvržení ============================= */

.layout { display: flex; align-items: stretch; min-height: calc(100vh - 55px); }

.sidebar {
  flex: 0 0 296px;
  padding: 14px 14px 20px;
  display: flex; flex-direction: column; gap: 12px;
  border-right: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(255,255,255,.015), transparent 200px);
}

.workspace {
  flex: 1 1 auto; min-width: 0;
  padding: 14px 18px 26px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ============================== panely ================================ */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 13px 14px 14px;
}
.panel-title {
  margin: 0 0 11px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-dim);
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span {
  font-size: 11.5px; font-weight: 600; color: var(--text-dim);
  display: flex; align-items: baseline; gap: 5px;
}
.field > span em { font-style: normal; font-size: 10px; color: var(--text-faint); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 10px; }
.field-wide { margin-bottom: 10px; }
.panel .field-row:last-child, .panel .field-wide:last-child { margin-bottom: 0; }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 7px 9px;
  font-size: 13.5px; color: var(--text);
  background: var(--field);
  border: 1px solid var(--panel-edge); border-radius: var(--radius);
  transition: border-color .12s;
}
input[type="number"]:hover, input[type="text"]:hover, select:hover { border-color: #465364; }
input[type="text"] { font-family: var(--sans); }
input[type="text"]::placeholder { color: var(--text-faint); }
select { font-family: var(--sans); appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%2394A0AE' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 26px;
}

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--field); border: 1px solid var(--panel-edge);
  border-radius: var(--radius); padding: 2px; gap: 2px;
}
.segmented button {
  padding: 6px 4px; font: 600 12px/1.2 var(--sans);
  color: var(--text-dim); background: transparent; border: 0; border-radius: 4px;
  cursor: pointer; transition: background .12s, color .12s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: #3A4554; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }

.btn-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; margin-top: 2px; }
.btn-row .btn { justify-content: center; }

.hint { margin: 9px 0 0; font-size: 11px; color: var(--text-faint); }
.hint-touch { display: none; }
@media (hover: none) {
  .hint-pointer { display: none; }
  .hint-touch { display: block; }
}
.hint kbd {
  font: 600 10px var(--mono); color: var(--text-dim);
  background: var(--field); border: 1px solid var(--panel-edge); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 4px;
}

.readout {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11.5px; color: var(--text-dim);
}
.readout output { font-size: 14px; color: var(--text); font-weight: 500; }

/* přířezy u stěn */
.edges { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 11px; }
.edge {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5px 8px; font-size: 11px; color: var(--text-dim);
  background: var(--field); border: 1px solid var(--panel-edge); border-radius: 5px;
}
.edge b { font-size: 12px; font-weight: 500; color: var(--text); }
.edge.is-warn { border-color: rgba(224,106,79,.5); }
.edge.is-warn b { color: var(--warn); }
.edge.is-full b { color: var(--text-faint); }

/* upozornění */
.warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.warnings li {
  font-size: 11.5px; line-height: 1.45; color: var(--text-dim);
  padding: 7px 9px 7px 26px; position: relative;
  background: var(--field); border-radius: 5px;
  border: 1px solid rgba(224,106,79,.35);
}
.warnings li::before {
  content: "!"; position: absolute; left: 9px; top: 7px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--warn); color: #fff;
  font: 700 9px/12px var(--sans); text-align: center;
}
.warnings li.info { border-color: var(--panel-edge); }
.warnings li.info::before { content: "i"; background: var(--ink-dim); }

.sidebar-foot {
  margin-top: auto; padding-top: 6px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 10px;
}
.version { font-size: 10px; line-height: 1.5; color: var(--text-faint); text-align: right; }

/* ============================== statistiky ============================ */

.stats { display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 0 4px; min-height: 20px; }
.stat { display: flex; align-items: baseline; gap: 7px; font-size: 11.5px; color: var(--text-dim); }
.stat b { font-size: 14.5px; font-weight: 500; color: var(--text); }
.stat b small { font-size: 11px; color: var(--text-dim); font-weight: 400; }

/* ============================== výkres ================================ */

.sheet-wrap { position: relative; }
.sheet {
  position: relative;
  min-height: 480px;
  height: min(66vh, 720px);
  background: var(--paper);
  border-radius: 3px;
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#canvas.panning { cursor: grabbing; }
#canvas.shifting { cursor: move; }

.viewbar {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  display: flex; gap: 1px;
  background: var(--paper);
  border: 1px solid #C9CCC9; border-radius: 6px;
  box-shadow: 0 2px 8px rgba(28,37,48,.14);
  overflow: hidden;
}
.viewbar button {
  width: 32px; height: 30px; border: 0; background: transparent;
  font: 400 15px/1 var(--mono); color: var(--ink);
  cursor: pointer; transition: background .1s;
}
.viewbar button:hover { background: #EFEFEA; }

/* legenda na výkresu */
.legend {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 11px;
  background: rgba(252,252,250,.94);
  border: 1px solid #22323e26; border-radius: 6px;
  box-shadow: 0 2px 10px rgba(28,37,48,.12);
  backdrop-filter: blur(2px);
  max-width: 250px;
}
.legend-title {
  font-size: 9px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-dim); margin-bottom: 4px;
}
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink); padding: 2px 0; }
.legend-row .name { flex: 1 1 auto; }
.legend b { font-weight: 500; color: var(--ink-dim); font-size: 11px; white-space: nowrap; }
.legend input[type="color"] {
  width: 20px; height: 14px; padding: 0; border: 1px solid rgba(34,43,54,.3); border-radius: 3px;
  background: none; cursor: pointer; flex: none;
}
.legend input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.legend input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
.legend .swatch-dot {
  width: 20px; display: flex; justify-content: center; flex: none;
}
.legend .swatch-dot i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ink);
}

.tooltip {
  position: absolute; z-index: 10; pointer-events: none;
  padding: 5px 9px;
  font: 500 11.5px/1.4 var(--sans); color: var(--paper);
  background: rgba(28,37,48,.92); border-radius: 5px;
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
  white-space: nowrap; transform: translate(12px, 14px);
}
.tooltip small { display: block; font-family: var(--mono); font-size: 10.5px; color: #B9C2CC; }

/* ============================== výkaz ================================= */

.takeoff {
  background: var(--paper);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: var(--shadow-sheet);
  padding: 18px 22px 16px;
}
.takeoff-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.takeoff-head h2 {
  margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink);
}
.takeoff .btn-ghost { color: var(--ink-dim); border-color: #D5D6D2; }
.takeoff .btn-ghost:hover { background: #F0F0EB; color: var(--ink); }

/* horizontální scroll s okrajovými stíny, ať je posuv na užších displejích vidět */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(90deg, var(--paper) 40%, rgba(252,252,250,0)) left / 48px 100%,
    linear-gradient(270deg, var(--paper) 40%, rgba(252,252,250,0)) right / 48px 100%,
    linear-gradient(90deg, rgba(34,43,54,.16), rgba(34,43,54,0)) left / 14px 100%,
    linear-gradient(270deg, rgba(34,43,54,.16), rgba(34,43,54,0)) right / 14px 100%;
  background-repeat: no-repeat;
  background-attachment: local, local, scroll, scroll;
}
#bom-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 760px; }
#bom-table th {
  text-align: left; font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-dim); padding: 6px 10px; border-bottom: 2px solid var(--ink);
  white-space: nowrap;
}
#bom-table th.c-num { text-align: right; }
#bom-table td { padding: 8px 10px; border-bottom: 1px solid #E3E4DF; vertical-align: top; }
#bom-table td.c-num { text-align: right; white-space: nowrap; font-size: 12.5px; }
#bom-table tbody tr:hover td { background: #F6F6F2; }

td.c-name { min-width: 210px; }
.item-name { font-weight: 600; color: var(--ink); }
.item-detail { font-size: 11px; color: var(--ink-dim); margin-top: 1px; font-family: var(--mono); }
td.c-order { font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim); white-space: nowrap; }
.qty-main { font-weight: 600; }
.qty-sub { font-size: 10.5px; color: var(--ink-dim); }

input.price-input {
  width: 84px; text-align: right;
  font: 500 12.5px var(--mono); color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  padding: 3px 6px; transition: border-color .12s, background .12s;
}
input.price-input:hover { border-color: #D5D6D2; background: #fff; }
input.price-input:focus { border-color: var(--accent); background: #fff; outline: none; }
input.price-edited { color: #A5620E; }

.row-sum td {
  border-bottom: 0; border-top: 2px solid var(--ink);
  font-weight: 700; font-size: 13px; padding-top: 10px;
}
.row-sum-vat td { border-top: 0; padding-top: 2px; font-weight: 500; color: var(--ink-dim); font-size: 12px; }
.takeoff-note { margin: 12px 2px 0; font-size: 11px; color: var(--ink-dim); }

/* ============================== patička ============================== */

.site-foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 4px 0 0;
}
.site-foot #foot-year { font-family: var(--mono); }

/* ============================== responsivita ========================== */

/* --- naležato / tablet: panely vstupů vedle sebe --- */
@media (max-width: 1020px) {
  .layout { flex-direction: column; }
  .sidebar {
    flex: none; border-right: 0; border-bottom: 1px solid var(--panel-edge);
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    align-items: start;
  }
  .sidebar-foot { grid-column: 1 / -1; margin-top: 0; }
  .topbar h1 { font-size: 14px; }
  .sheet { height: 56vh; min-height: 340px; border-radius: 3px 3px 0 0; }

  /* legenda nepřekrývá výkres — je to lišta přilepená pod listem */
  .legend {
    position: static; max-width: none;
    border: 0; border-top: 1px dashed #D5D6D2; border-radius: 0 0 3px 3px;
    background: var(--paper); backdrop-filter: none;
    box-shadow: var(--shadow-sheet);
    padding: 10px 14px 12px;
  }
  .legend-row { padding: 4px 0; }
  .legend input[type="color"] { width: 28px; height: 20px; }
}

/* --- telefon --- */
@media (max-width: 640px) {
  /* hlavička ve dvou řádcích: značka + panel akcí; nepřilepená, ať nebere místo */
  .topbar { position: static; flex-wrap: wrap; gap: 10px 16px; padding: 10px 12px; }
  .brand { flex: 1 1 100%; }
  .actions { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; }
  .actions .btn { flex: 1 1 30%; justify-content: center; min-height: 40px; }
  .actions-sep { display: none; }

  .sidebar { padding: 12px 10px 14px; }
  .workspace { padding: 12px 10px calc(18px + env(safe-area-inset-bottom, 0px)); gap: 12px; }

  /* 16px = iOS nepřibližuje stránku při fokusu; zároveň větší dotykové cíle */
  input[type="number"], input[type="text"], select { font-size: 16px; padding: 9px 10px; }
  .segmented button { padding: 9px 4px; }

  .stats { gap: 6px 16px; }

  .sheet { height: 46vh; min-height: 300px; }
  .viewbar { left: 10px; bottom: 10px; }
  .viewbar button { width: 42px; height: 38px; font-size: 17px; }

  .takeoff { padding: 14px 12px 12px; }
  input.price-input { width: 96px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================== tisk ================================== */

@media print {
  .topbar, .sidebar, .viewbar, .stats { display: none !important; }
  body { background: #fff; }
  .layout { min-height: 0; }
  .sheet, .takeoff { box-shadow: none; border: 1px solid #ccc; }
}
