/*
 * Vzhled podle aplikace Doklady (doklady.dsm.cz): teplé béžové pozadí, bílé karty,
 * oranžová a téměř černá z loga DSM.
 */
:root {
  --bg: #f6f4f2;
  --card: #fff;
  --text: #172033;
  --muted: #5d6675;
  --line: #e1e5ec;
  --field-line: #c9cfd8;
  --navy: #1a1919;
  --primary: #d0623c;
  --primary-dark: #a9482a;
  --primary-bg: #fbece6;
  --ok: #1d7a3e; --ok-bg: #e3f4e8;
  --warn: #8a5a00; --warn-bg: #fff2d6;
  --danger: #a32020; --danger-bg: #fde4e4;
  --grey-bg: #eef0f3;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(26, 25, 25, .06);

  /* hlavička */
  --hdr-bg: #fff;
  --hdr-text: var(--text);
  --hdr-muted: var(--muted);
  --hdr-border: 1px solid var(--line);
  --hdr-radius: var(--radius);
  --hdr-gap: 10px;              /* odsazení plovoucí hlavičky od okraje */
  --hdr-shadow: var(--shadow);
  --chip-bg: var(--primary-bg);
  --chip-text: var(--primary-dark);
  --chip-border: transparent;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45;
  -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- hlavička ---------- */
.topbar { position: sticky; top: var(--hdr-gap); z-index: 10; display: flex; align-items: center; gap: .6rem;
  width: calc(100% - 2 * var(--hdr-gap)); max-width: 1200px; margin: var(--hdr-gap) auto 0;
  padding: .55rem .8rem; padding-top: max(.55rem, env(safe-area-inset-top));
  background: var(--hdr-bg); color: var(--hdr-text); border: var(--hdr-border); border-radius: var(--hdr-radius);
  box-shadow: var(--hdr-shadow); }
.screen > .topbar { top: var(--hdr-gap); }
.topbar .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; flex: 1; color: inherit; text-decoration: none; }
.brand .logo { height: 28px; width: auto; flex: none; }
.brand .sep { width: 1px; align-self: stretch; background: var(--line); }
.brand .title { min-width: 0; }
.brand b { display: block; font-size: 1.1rem; color: var(--hdr-text); letter-spacing: -.01em; line-height: 1.2; }
.brand small { display: block; color: var(--hdr-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { border: 1px solid var(--chip-border); background: var(--chip-bg); color: var(--chip-text);
  border-radius: 999px; padding: .4rem .8rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.chip::before { content: "📍 "; }
.topbar .link { background: none; border: 0; color: var(--hdr-text); padding: .45rem .5rem; cursor: pointer;
  font-weight: 600; text-decoration: none; border-radius: 10px; white-space: nowrap; }
.topbar .link:hover { background: var(--grey-bg); }
.topbar strong { color: var(--hdr-text); }

main { max-width: 720px; margin: 0 auto; padding: .9rem .75rem 5rem; }
.wide main { max-width: 1200px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
  margin-bottom: .9rem; box-shadow: var(--shadow); }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; color: var(--navy); }
h2 { font-size: 1.1rem; margin: 0 0 .7rem; color: var(--navy); }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .8rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- formuláře ---------- */
label { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=file], select, textarea, input:not([type]) {
  width: 100%; padding: .7rem .8rem; border: 1px solid var(--field-line); border-radius: 10px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input.big { font-size: 1.6rem; padding: .65rem .8rem; font-weight: 700; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid var(--field-line);
  border-radius: 10px; padding: .75rem 1.1rem; font-weight: 600; cursor: pointer; background: #fff; color: var(--text);
  text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.huge { font-size: 1.15rem; padding: 1rem 1.2rem; }
.btn.sm { padding: .35rem .7rem; font-size: .88rem; }
.btn .ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.error { color: var(--danger); font-weight: 600; }
.error:empty { display: none; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: .75rem .9rem; }
.notice.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }

/* ---------- skladník ---------- */
.searchbar { display: flex; gap: .5rem; position: sticky; top: calc(var(--hdr-gap) + 4.1rem); z-index: 5;
  background: var(--bg); padding: .2rem 0 .6rem; }
.searchbar input { font-size: 1.1rem; }
.searchbar .btn { flex: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: .5rem;
  padding: .75rem .9rem; cursor: pointer; box-shadow: var(--shadow); display: flex; gap: .6rem; align-items: center; }
.list li:hover { border-color: var(--primary); }
.list li:active { background: var(--primary-bg); }
.list .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: .92rem; color: var(--navy); }
.list .name { line-height: 1.25; }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--grey-bg); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.blue { background: var(--primary-bg); color: var(--primary-dark); }

.tabs { display: flex; gap: .4rem; margin-bottom: .8rem; padding: .3rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.tabs button { flex: 1; padding: .6rem; border: 0; border-radius: 10px; background: transparent; color: var(--text);
  font-weight: 600; cursor: pointer; }
.tabs button.active { background: var(--primary-bg); color: var(--primary-dark); }

.grid-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.grid-buttons .btn { min-height: 4rem; font-size: 1.1rem; }
.grid-buttons .btn.current { border: 2px solid var(--primary); background: var(--primary-bg); color: var(--primary-dark); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.bigstat { display: flex; gap: .6rem; margin: .8rem 0; }
.bigstat > div { flex: 1; background: var(--bg); border-radius: 12px; padding: .6rem .75rem; }
.bigstat .v { font-size: 1.45rem; font-weight: 800; color: var(--navy); }
.bigstat .l { font-size: .8rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f6f8fb; color: var(--muted); font-size: .82rem; font-weight: 600; position: sticky; top: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--primary-bg); }
.table-wrap { overflow-x: auto; }

/* ---------- překryvné obrazovky ---------- */
.screen { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; }
.toast { position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: .8rem 1.2rem; border-radius: 14px; font-weight: 700; z-index: 100;
  box-shadow: 0 8px 30px rgba(26, 25, 25, .25); max-width: 92vw; text-align: center; border-left: 5px solid var(--ok); }
.toast.err { border-left-color: var(--danger); background: var(--danger); }

.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; height: 100%; object-fit: cover; min-height: 0; }
.scanner .frame { position: absolute; left: 8%; right: 8%; top: 35%; height: 22%; border: 3px solid var(--primary);
  border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.4); pointer-events: none; }
.scanner .bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; gap: .6rem; }
.scanner .msg { position: absolute; top: calc(1rem + env(safe-area-inset-top)); left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }

dialog { border: 0; border-radius: var(--radius); padding: 1.1rem; max-width: 94vw; width: 520px; box-shadow: 0 8px 30px rgba(26, 25, 25, .2); }
#item-dialog { width: 960px; }
dialog::backdrop { background: rgba(26, 25, 25, .45); }

/* ---------- admin ---------- */
.admin-nav { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .9rem; padding: .3rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.admin-nav a { padding: .5rem .9rem; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.admin-nav a.active { background: var(--primary-bg); color: var(--primary-dark); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: .9rem; }
.stats .card { margin: 0; }
.stats .v { font-size: 1.8rem; font-weight: 800; color: var(--navy); }
.progress { height: 14px; background: var(--grey-bg); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .7rem; }
.filters input { flex: 1; min-width: 200px; }
.filters select { width: auto; }
.pos { color: var(--ok); } .neg { color: var(--danger); }

@media (max-width: 520px) {
  .brand .sep { display: none; }
  .brand .logo { height: 24px; }
  .topbar .link { padding: .45rem .35rem; }
}

/* ---------- menu ☰ v hlavičce (jako v Dokladech) ---------- */
.menu { position: relative; flex: none; }
.menu summary { list-style: none; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; color: var(--hdr-text); }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { background: var(--grey-bg); }
.menu-pop { position: absolute; right: 0; top: 50px; z-index: 30; min-width: 220px; padding: 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(26, 25, 25, .15); }
.menu-pop p { margin: 4px 8px 10px; color: var(--text); }
.menu-pop small { color: var(--muted); }
.menu-pop a, .menu-pop .menu-item { display: block; width: 100%; padding: 10px 8px; border: 0; border-radius: 8px; background: none;
  text-align: left; color: var(--text); text-decoration: none; font-weight: 600; cursor: pointer; }
.menu-pop a:hover, .menu-pop .menu-item:hover { background: var(--grey-bg); }
.menu-pop .menu-item { color: var(--danger); }
.topbar .badge { flex: none; }

@media (max-width: 520px) {
  .topbar { gap: .45rem; padding-left: .6rem; padding-right: .5rem; }
  .brand { gap: .45rem; }
  .brand b { font-size: 1rem; }
  .chip { padding: .4rem .65rem; max-width: 9.5rem; overflow: hidden; text-overflow: ellipsis; }
  .topbar .badge { display: none; }
}
@media (max-width: 520px) {
  /* na telefonu: logo | Inventura (bez jména – to je v menu ☰), koridor zkrácený, aby nápis zůstal vidět */
  #view-app .brand .sep { display: block; }
  #view-app .brand small { display: none; }
  #view-app .brand { flex: 1 0 auto; }
  #view-app .brand b { white-space: nowrap; }
  #view-app .chip { flex: 0 1 auto; min-width: 0; max-width: none; }
}
@media (max-width: 520px) {
  .wide .card.row > .grow { flex: 1 1 100%; }
  .wide .card.row > .btn { flex: 1 1 auto; }
}
