/* Kochy UI — design language adapted from ProtokolOnline/design.md.
   Light "application" mode only (no marketing surface).
   All custom properties are tokens; no Tailwind, no bundler.
   CSP-strict: no inline styles, no fonts loaded from third parties. */

:root {
  /* Slate scale — text, surfaces, borders */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* Emerald — primary brand & "vyhovuje" / "hotovo" */
  --emerald-50:  #ecfdf5;
  --emerald-200: #a7f3d0;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --emerald-800: #065f46;

  /* Blue — secondary action */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  /* Amber — blíží se termín */
  --amber-50:  #fffbeb;
  --amber-200: #fde68a;
  --amber-500: #f59e0b;
  --amber-700: #b45309;

  /* Red — chyba, po termínu */
  --red-50:  #fef2f2;
  --red-200: #fecaca;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  /* Tokens */
  --bg:           var(--slate-50);
  --surface:      #ffffff;
  --text:         var(--slate-900);
  --text-muted:   var(--slate-600);
  --text-hint:    var(--slate-500);
  --border:       var(--slate-200);
  --border-strong: var(--slate-300);
  --accent:       var(--emerald-700);
  --accent-soft:  var(--emerald-50);
  --link:         var(--blue-600);

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.08), 0 4px 6px rgba(15, 23, 42, 0.05);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
               Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --tap: 44px; /* min touch target */
}

/* ------------- reset ------------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 18px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.3; }
p  { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

::selection { background: var(--emerald-200); color: var(--slate-900); }

/* ------------- layout ------------- */

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.sidebar-brand-sub {
  font-size: 12px;
  color: var(--text-hint);
  margin-top: 2px;
}
.sidebar-nav {
  flex: 1;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  min-height: var(--tap);
}
.sidebar-nav a:hover { background: var(--slate-100); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--accent-soft);
  color: var(--emerald-800);
}
.sidebar-nav a .icon { color: var(--text-hint); }
.sidebar-nav a.active .icon { color: var(--emerald-700); }
.sidebar-foot {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}
.sidebar-foot .user {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px var(--space-2);
}
.sidebar-foot button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
}
.sidebar-foot button:hover { background: var(--slate-100); }

main.content {
  padding: var(--space-8) var(--space-8) var(--space-12);
  max-width: 1120px;
  width: 100%;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-head .title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.page-head .crumb {
  font-size: 13px;
  color: var(--text-hint);
}
.page-head .crumb a { color: var(--text-muted); }

/* mobile */
.menu-button {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  align-items: center;
  justify-content: center;
}
.sidebar-overlay { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  main.content { padding: 64px var(--space-4) var(--space-10); }
  .menu-button { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 70;
    box-shadow: var(--shadow-lg);
  }
  .app.menu-open .sidebar { transform: translateX(0); }
  .app.menu-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 65;
  }
}

/* ------------- cards ------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-4); }
.card-head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.card-head h2 { font-size: 16px; }
.card-body { padding: var(--space-5); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.kpi .label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.kpi .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ------------- forms ------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.field .hint { font-size: 12px; color: var(--text-hint); }
.field .err {
  font-size: 13px;
  color: var(--red-700);
  background: var(--red-50);
  border: 1px solid var(--red-200);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--tap);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: var(--emerald-600);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}
input::placeholder, textarea::placeholder { color: var(--text-hint); }

/* ------------- buttons ------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--tap);
  padding: 0 var(--space-5);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--emerald-700);
  color: #fff;
}
.btn-primary:hover { background: var(--emerald-800); text-decoration: none; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--slate-50); text-decoration: none; }
.btn-danger {
  background: var(--surface);
  color: var(--red-700);
  border-color: var(--red-200);
}
.btn-danger:hover { background: var(--red-50); text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  height: 36px;
  padding: 0 var(--space-3);
}
.btn-ghost:hover { background: var(--slate-100); text-decoration: none; }
.btn-block { width: 100%; }

/* ------------- tables ------------- */

.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--slate-50);
}
table.table tbody td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--slate-100);
}
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr:hover { background: var(--slate-50); }
table.table .num { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  table.table thead { display: none; }
  table.table, table.table tbody, table.table tr, table.table td { display: block; width: 100%; }
  table.table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    background: var(--surface);
  }
  table.table tbody td {
    border-bottom: 1px solid var(--slate-100);
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
  }
  table.table tbody td::before {
    content: attr(data-label);
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    align-self: center;
  }
}

/* ------------- badges & pills ------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  letter-spacing: 0.01em;
}
.badge-emerald { background: var(--emerald-50); color: var(--emerald-800); border-color: var(--emerald-200); }
.badge-amber   { background: var(--amber-50);   color: var(--amber-700);   border-color: var(--amber-200); }
.badge-red     { background: var(--red-50);     color: var(--red-700);     border-color: var(--red-200); }
.badge-blue    { background: var(--blue-50);    color: var(--blue-700);    border-color: var(--blue-100); }
.badge-slate   { background: var(--slate-100);  color: var(--slate-700);   border-color: var(--border); }

/* ------------- tabs ------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
}
.tab {
  background: transparent;
  border: 0;
  padding: 12px var(--space-4);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  min-height: var(--tap);
}
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--emerald-700);
}
.tab:hover { color: var(--text); }

/* ------------- toast ------------- */

.toast-host {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  background: var(--slate-900);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  pointer-events: auto;
  max-width: 320px;
}
.toast.error { background: var(--red-700); }
.toast.success { background: var(--emerald-800); }

/* ------------- auth surface (login.html) ------------- */

.auth-shell {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-8);
  width: 100%;
  max-width: 420px;
}
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-card .lede {
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-size: 14px;
}
.auth-card .brand {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--emerald-700);
  margin-bottom: var(--space-3);
}
.auth-card .switch {
  margin-top: var(--space-5);
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* sticky form header (PLAN §10.2) */
.sticky-protocol-head {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  font-size: 14px;
}
.sticky-protocol-head .head-group { display: flex; gap: var(--space-3); align-items: center; }
.sticky-protocol-head .ev-placeholder {
  margin-left: auto;
  font-family: var(--font-mono);
  color: var(--text-hint);
  font-size: 13px;
}

/* small utilities */
.row { display: flex; gap: var(--space-3); align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.muted { color: var(--text-muted); }
.hint  { color: var(--text-hint); font-size: 13px; }
.mono  { font-family: var(--font-mono); font-size: 13px; }
.right { text-align: right; }
.empty {
  text-align: center;
  padding: var(--space-10) var(--space-6);
  color: var(--text-muted);
  font-size: 14px;
}
.empty .small { font-size: 13px; color: var(--text-hint); margin-top: 6px; }

/* recovery code list */
.recovery-codes {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--slate-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  letter-spacing: 0.04em;
}

/* spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--slate-300);
  border-top-color: var(--emerald-700);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* TOTP enrollment QR — server-rendered SVG injected into #enroll-qr. */
.qr-host {
  display: inline-block;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 0;
}
.qr-host svg {
  display: block;
  width: 220px;
  height: 220px;
}

/* Inline-style replacements (CSP style-src 'self' forbids `style="…"`). */
.field-center {
  text-align: center;
}
.secret-block {
  display: block;
  word-break: break-all;
  padding: 10px 12px;
  background: var(--slate-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ============================================================
   Utility classes — added 2026-05-25 to replace inline style="…"
   attributes (CSP style-src 'self' compliance, removes the need
   for 'unsafe-inline'). Names intentionally short + composable.
   ============================================================ */

.text-bold       { font-weight: 600; }
.title-sm        { font-weight: 600; font-size: 14px; }
.text-xs         { font-size: 12px; }
.text-2xs        { font-size: 11px; }
.min-w-0         { min-width: 0; }
.break-all       { word-break: break-all; }
.pre-wrap        { margin: 0; white-space: pre-wrap; }
.mb-sm           { margin-bottom: 8px; }
.mr-sm           { margin-right: 8px; }
.gap-xs          { gap: 6px; }
.gap-sm          { gap: 8px; }
.row-actions     { gap: 6px; justify-content: flex-end; }
.cursor-pointer  { cursor: pointer; }

/* Truncate a single line inside a fixed-width table cell. */
.truncate-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Repeating "card row" pattern used by archive-detail, customer attachments,
   customers list, dashboard recent-customers. */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.list-row--padded   { padding: 14px; }
.list-row--link     { text-decoration: none; color: inherit; }
.list-row--wrap     { gap: 12px; flex-wrap: wrap; }

/* Sidebar role badge under the user name. */
.user-role-badge {
  font-size: 11px;
  color: var(--text-hint);
  padding: 0 0 8px 0;
}

/* Preset / recent-customer card button on /new.html. */
.preset-btn {
  justify-content: flex-start;
  text-align: left;
  height: auto;
  padding: 10px 12px;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* HTML-side utility classes for the inline-style refactor.
   Names favor shorthand: mw = min-width, m = margin, mt/mb/my = margin-top/bottom/y,
   items-end = align-items:flex-end. CSS variables `--space-*` are kept in places
   that already use them; literal-pixel utilities for the rest. */
.mw-120 { min-width: 120px; }
.mw-140 { min-width: 140px; }
.mw-160 { min-width: 160px; }
.mw-200 { min-width: 200px; }
.mw-220 { min-width: 220px; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.m-0   { margin: 0; }
.mt-xs { margin-top: 6px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.my-xs { margin: 6px 0; }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.items-end { align-items: flex-end; }

/* Composite reused on archive-detail.html iframe — see frame-src 'self' in CSP. */
.pdf-frame {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Invitation result card on /users.html. */
.invite-success {
  margin-top: var(--space-4);
  background: var(--accent-soft);
  border-color: var(--emerald-200);
}

/* Additional utilities for round-2 HTML refactor. */
.gap-8       { gap: 8px; }
.gap-12-wrap { gap: 12px; flex-wrap: wrap; }
.row-between { gap: var(--space-3); justify-content: space-between; }
.fakturoid-note {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.fakturoid-note--narrow {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.mw-240 { min-width: 240px; }
