:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d1f25;
  --ink-2: #4a4f5c;
  --ink-3: #7b8190;
  --line: #e2e5ea;
  --line-2: #eef0f3;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --danger: #b4232f;
  --ok: #217a3c;
  --sel: #2d7ff9;
  --row-hover: #f5f8fe;
  --group: #f1f3f6;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(20, 28, 45, 0.16), 0 2px 6px rgba(20, 28, 45, 0.08);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { font: 13px/1.4 var(--font); color: var(--ink); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- přihlášení ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto; height: 100%; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--ink-3); margin: 0 0 20px; }
.login-card label { display: block; font-weight: 600; margin: 14px 0 6px; }
.login-card select, .login-card input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; background: #fff; font-size: 15px; }
.login-card input { letter-spacing: 0.3em; }
.login-card .primary { width: 100%; margin-top: 20px; height: 44px; font-size: 15px; }
.msg-error { color: var(--danger); min-height: 1.4em; margin-top: 10px; }

/* ---------- rozvržení ---------- */
.app { display: grid; grid-template-rows: 48px minmax(0, 1fr); height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px; background: #16233b; color: #fff; min-width: 0; }
.topbar .brand { font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.topbar select { background: rgba(255, 255, 255, 0.1); color: #fff; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 6px; height: 30px; padding: 0 8px; max-width: 200px; }
.topbar select option { color: var(--ink); }
.topbar .search { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.topbar .search input { width: 100%; height: 30px; border-radius: 6px; border: 0; padding: 0 10px 0 30px; background: rgba(255, 255, 255, 0.14); color: #fff; }
.topbar .search input::placeholder { color: rgba(255, 255, 255, 0.6); }
.topbar .search::before { content: '⌕'; position: absolute; left: 10px; top: 5px; opacity: 0.7; }
.topbar .user { white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.topbar .user button { background: transparent; border: 1px solid rgba(255, 255, 255, 0.25); color: #fff; border-radius: 6px; height: 28px; padding: 0 10px; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 32px; height: 32px; border-radius: 6px; font-size: 18px; display: inline-grid; place-items: center; }
.menu-btn { display: none; }

.body { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 0; overflow: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.sidebar .sec { padding: 10px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.sidebar input.filter { margin: 0 10px 6px; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; }
.sidebar .list { overflow: auto; padding: 0 6px 6px; }
.sidebar .tables { flex: 1 1 55%; min-height: 80px; }
.sidebar .views { flex: 1 1 45%; min-height: 80px; border-top: 1px solid var(--line); }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; color: var(--ink-2); }
.nav-item:hover { background: var(--line-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; color: var(--ink-3); font-size: 11px; font-weight: 400; }
.nav-item .badge { margin-left: auto; font-size: 10px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 1px 6px; white-space: nowrap; }
.nav-item .vicon { width: 16px; text-align: center; opacity: 0.8; }
.nav-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--ink-2); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.toolbar h2 { font-size: 15px; margin: 0 8px 0 0; white-space: nowrap; }
.toolbar .tb { border: 0; background: transparent; padding: 5px 9px; border-radius: 6px; color: var(--ink-2); white-space: nowrap; }
.toolbar .tb:hover { background: var(--line-2); }
.toolbar .tb.on { background: var(--accent-soft); color: var(--accent); }
.toolbar .sp { flex: 1; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; font-weight: 600; white-space: nowrap; }
.primary:disabled { opacity: 0.5; cursor: default; }
.ghost { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
.danger { background: #fff; border: 1px solid #f1c3c7; color: var(--danger); border-radius: 6px; padding: 5px 10px; }
.banner { padding: 7px 12px; font-size: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: #eef4ff; color: #28427a; }
.banner button { font-size: 12px; }

/* ---------- mřížka ---------- */
.grid-wrap { position: relative; flex: 1; min-height: 0; }
.grid { position: absolute; inset: 0; overflow: auto; outline: none; }
.g-head { position: sticky; top: 0; z-index: 4; display: flex; height: 34px; background: #f8f9fb; border-bottom: 1px solid var(--line); }
.g-body { position: relative; }
.g-row { position: absolute; left: 0; display: flex; border-bottom: 1px solid var(--line-2); background: #fff; }
.g-row:hover, .g-row:hover .g-sticky { background: var(--row-hover); }
.g-sticky { position: sticky; left: 0; z-index: 2; display: flex; background: inherit; box-shadow: 1px 0 0 var(--line); }
.g-head .g-sticky { background: #f8f9fb; z-index: 5; }
.g-cell { flex: none; padding: 6px 8px; border-right: 1px solid var(--line-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; position: relative; }
.g-row .g-cell { background: inherit; }
.g-rownum { flex: none; width: 52px; color: var(--ink-3); font-size: 11px; padding: 8px 4px 0 10px; display: flex; gap: 4px; }
.g-rownum .exp { visibility: hidden; border: 0; background: transparent; color: var(--accent); padding: 0 2px; font-size: 13px; line-height: 1; }
.g-row:hover .g-rownum .exp { visibility: visible; }
.g-head .g-cell { font-weight: 600; color: var(--ink-2); padding: 8px 8px; cursor: pointer; user-select: none; display: flex; gap: 6px; align-items: center; }
.g-head .g-cell .fi { color: var(--ink-3); font-size: 11px; width: 16px; text-align: center; flex: none; }
.g-head .g-cell .fn { overflow: hidden; text-overflow: ellipsis; }
.g-head .g-cell.sorted .fn::after { content: ' ↕'; color: var(--accent); }
.g-head .g-cell .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 3; }
.g-head .g-cell.drag-over { box-shadow: inset 3px 0 0 var(--sel); }
.g-cell.active { box-shadow: inset 0 0 0 2px var(--sel); z-index: 1; }
.g-cell.ro { color: var(--ink-2); }
.g-cell.editing { overflow: visible; padding: 0; z-index: 6; }
.g-cell.editing input, .g-cell.editing textarea { width: 100%; height: 100%; border: 2px solid var(--sel); padding: 5px 7px; outline: none; background: #fff; }
.g-group { position: absolute; left: 0; display: flex; align-items: center; background: var(--group); border-bottom: 1px solid var(--line); font-weight: 600; }
.g-group .gl { position: sticky; left: 0; padding: 0 12px; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.g-group .gl button { border: 0; background: transparent; width: 20px; }
.g-group .gl .gc { color: var(--ink-3); font-weight: 400; }
.g-group .gl .gs { color: var(--ink-2); font-weight: 400; font-size: 12px; }
.g-foot { position: sticky; bottom: 0; z-index: 4; display: flex; height: 30px; background: #f8f9fb; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); }
.g-foot .g-cell { padding: 6px 8px; cursor: pointer; }
.g-foot .g-cell:hover { background: var(--line-2); }
.g-foot .sumv { font-weight: 600; color: var(--ink); }
.g-empty { padding: 40px; text-align: center; color: var(--ink-3); }
.h-short .g-cell { white-space: nowrap; }
.h-medium .g-row .g-cell, .h-tall .g-row .g-cell, .h-extra .g-row .g-cell { white-space: normal; }
.g-row .g-cell .ml { white-space: pre-wrap; }
.h-short .g-row .g-cell .ml { white-space: nowrap; }

.chip { display: inline-block; border-radius: 10px; padding: 0 8px; margin: 0 4px 2px 0; font-size: 12px; line-height: 19px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.lchip { display: inline-block; background: #e9eefb; color: #1f3f7f; border-radius: 4px; padding: 0 6px; margin: 0 4px 2px 0; font-size: 12px; line-height: 19px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.lchip.ro { cursor: default; background: #eef0f3; color: var(--ink-2); }
.lchip .x { margin-left: 4px; border: 0; background: transparent; color: inherit; padding: 0; }
.cb { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 4px; font-size: 12px; }
.cb.on { background: #20c933; color: #fff; }
.cbx { width: 17px; height: 17px; border: 1.5px solid #b8bec9; border-radius: 4px; display: inline-grid; place-items: center; cursor: pointer; background: #fff; font-size: 12px; }
.cbx.on { background: #20c933; border-color: #20c933; color: #fff; }
.thumb { height: 22px; width: 22px; object-fit: cover; border-radius: 3px; margin-right: 3px; vertical-align: middle; border: 1px solid var(--line); background: #f0f0f0; }
.h-medium .thumb { height: 40px; width: 40px; }
.h-tall .thumb, .h-extra .thumb { height: 72px; width: 72px; }
.file { display: inline-block; font-size: 10px; font-weight: 700; background: #eef0f3; color: var(--ink-2); padding: 2px 5px; border-radius: 3px; margin-right: 3px; }
.num { display: block; text-align: right; font-variant-numeric: tabular-nums; }
.stars { color: #fcb400; letter-spacing: 1px; }
.stars .off { color: #d9dce2; }
.err { color: var(--danger); font-size: 12px; }

/* ---------- vyskakovací okna ---------- */
.pop { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: min(520px, 80vh); overflow: auto; min-width: 240px; }
.pop .ph { padding: 10px 12px 6px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pop .pb { padding: 6px 12px 12px; }
.pop input[type=text], .pop input[type=search], .pop input[type=number], .pop input[type=date], .pop input[type=datetime-local], .pop select {
  height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: #fff; max-width: 100%;
}
.opt { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.opt:hover, .opt.hl { background: var(--line-2); }
.opt .sub { color: var(--ink-3); font-size: 11px; margin-left: auto; }
.cond { display: grid; grid-template-columns: 60px minmax(120px, 1fr) minmax(110px, 150px) minmax(120px, 1.2fr) 28px; gap: 6px; align-items: center; margin-bottom: 6px; }
.cond > * { min-width: 0; width: 100%; }
.cond .conj { color: var(--ink-3); font-size: 12px; }
.cgroup { border: 1px dashed var(--line); border-radius: 8px; padding: 8px; margin: 4px 0 8px 66px; background: #fafbfc; }
.pop .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.multi-pick { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.menu .opt { padding: 7px 10px; }
.sepl { height: 1px; background: var(--line); margin: 4px 0; }

/* ---------- detail záznamu ---------- */
.drawer-back { position: fixed; inset: 0; background: rgba(20, 28, 45, 0.28); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: #fff; z-index: 31; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer .dh { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer .dh h3 { margin: 0; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer .db { overflow: auto; padding: 8px 16px 24px; flex: 1; }
.drawer .df { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.fld { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.fld label { display: flex; gap: 6px; align-items: center; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.fld label .fi { color: var(--ink-3); width: 16px; text-align: center; }
.fld label .ro { font-weight: 400; color: var(--ink-3); margin-left: auto; font-size: 11px; }
.fld .val { min-height: 30px; }
.fld .val.ro { color: var(--ink-2); padding: 5px 0; white-space: pre-wrap; word-break: break-word; }
.fld input[type=text], .fld input[type=number], .fld input[type=email], .fld input[type=url], .fld input[type=tel], .fld input[type=date], .fld input[type=datetime-local], .fld textarea, .fld select {
  width: 100%; min-height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff;
}
.fld textarea { min-height: 80px; resize: vertical; }
.fld input:focus, .fld textarea:focus, .fld select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.fld .desc { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.fld .saving { font-size: 11px; color: var(--ink-3); margin-left: 6px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; }
.atts a.att { display: block; width: 96px; text-decoration: none; color: var(--ink-2); font-size: 11px; }
.atts a.att img, .atts a.att .noimg { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: grid; place-items: center; background: #f3f4f6; }
.atts a.att span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist { margin-top: 18px; }
.hist h4 { margin: 0 0 8px; font-size: 13px; }
.hist .h { font-size: 12px; color: var(--ink-2); padding: 6px 0; border-bottom: 1px solid var(--line-2); }
.hist .h b { color: var(--ink); }

/* ---------- galerie a kalendář ---------- */
.gallery { flex: 1; overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; align-content: start; }
.card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: pointer; display: flex; flex-direction: column; }
.card:hover { box-shadow: var(--shadow); }
.card .cover { height: 150px; background: #eef0f3 center/cover no-repeat; display: grid; place-items: center; color: var(--ink-3); }
.card .cb2 { padding: 10px 12px; }
.card .ct { font-weight: 700; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .cf { font-size: 12px; color: var(--ink-2); margin: 3px 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card .cf small { color: var(--ink-3); display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.cal { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cal .calh { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.cal .calh h3 { margin: 0; font-size: 15px; min-width: 150px; }
.cal .calg { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(90px, 1fr); border-top: 1px solid var(--line); overflow: auto; }
.cal .dow { font-size: 11px; color: var(--ink-3); padding: 4px 8px; border-bottom: 1px solid var(--line); text-transform: uppercase; }
.cal .day { border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 4px; min-width: 0; overflow: hidden; }
.cal .day.out { background: #fafbfc; color: var(--ink-3); }
.cal .day.today .dn { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 6px; }
.cal .dn { font-size: 11px; font-weight: 600; margin-bottom: 3px; display: inline-block; }
.cal .ev { display: block; font-size: 11px; background: var(--accent-soft); color: #1f3f7f; border-radius: 4px; padding: 1px 5px; margin-bottom: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; border: 0; width: 100%; text-align: left; }
.cal .more { font-size: 11px; color: var(--ink-3); }

/* ---------- toast ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }
.toast button { background: transparent; border: 1px solid rgba(255, 255, 255, 0.5); color: #fff; border-radius: 6px; padding: 2px 10px; }
.modal-back { position: fixed; inset: 0; background: rgba(20, 28, 45, 0.35); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow); max-width: 480px; width: 100%; padding: 18px 20px; }
.modal h3 { margin: 0 0 8px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal pre { background: var(--bg); padding: 8px; border-radius: 6px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.loading { padding: 24px; color: var(--ink-3); }

/* ---------- telefon ---------- */
@media (max-width: 760px) {
  .menu-btn { display: inline-grid; }
  .topbar .brand { display: none; }
  .topbar .user .nm { display: none; }
  .topbar select { max-width: 120px; }
  .body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .main { grid-row: 1; grid-column: 1; }
  .sidebar { position: fixed; top: 48px; left: 0; bottom: 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform 0.18s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .toolbar { padding: 6px 8px; flex-wrap: wrap; row-gap: 2px; }
  .toolbar .sp { display: none; }
  .toolbar h2 { font-size: 14px; flex: 1 1 60%; min-width: 0; overflow: hidden; text-overflow: ellipsis; order: -2; }
  .toolbar .primary { order: -1; }
  .g-rownum { width: 36px; padding-left: 6px; }
  .g-rownum .exp { visibility: visible; }
  .drawer { width: 100%; }
  .cond { grid-template-columns: 1fr 1fr; }
  .cond .conj { grid-column: 1 / -1; }
  .cgroup { margin-left: 0; }
  .pop { left: 8px !important; right: 8px; max-width: none; min-width: 0; }
  .cal .calg { grid-auto-rows: minmax(64px, 1fr); }
  .cal .ev { font-size: 10px; }
}
