:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2456c9; --accent-soft: #e8eefb;
  --red: #c62828; --red-bg: #fdecec; --green: #1e7d34; --green-bg: #e6f4ea;
  --orange: #c25e00; --orange-bg: #fff1e0; --blue: #2456c9; --blue-bg: #e8eefb;
  font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: #b9c0cc; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ok { background: var(--green); border-color: var(--green); color: #fff; }
button.warn { background: var(--orange); border-color: var(--orange); color: #fff; }
button:disabled { opacity: .45; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
textarea { width: 100%; resize: vertical; min-height: 60px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Prihlásenie */
.login { max-width: 340px; margin: 12vh auto; background: var(--panel); padding: 28px; border-radius: 10px; box-shadow: 0 2px 10px #0001; }
.login h1 { font-size: 20px; margin: 0 0 18px; }
.login label { display: block; margin: 10px 0 4px; color: var(--muted); }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 18px; }
.error { color: var(--red); margin-top: 10px; }

/* Hlavička */
header { display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header .brand { font-weight: 600; }
header select { font-weight: 600; }
header nav { display: flex; gap: 4px; }
header nav button { border: 0; }
header nav button.active { background: var(--accent-soft); color: var(--accent); }
header .spacer { flex: 1; }
header .sync { color: var(--muted); font-size: 12px; }
header .sync.bad { color: var(--red); }
main { padding: 16px 18px; }

/* Súhrn */
.cards { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-width: 130px; cursor: pointer; }
.card .n { font-size: 22px; font-weight: 600; }
.card .l { color: var(--muted); font-size: 12px; }
.card.red .n { color: var(--red); } .card.green .n { color: var(--green); } .card.orange .n { color: var(--orange); } .card.blue .n { color: var(--blue); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input[type=search] { min-width: 220px; }
.toolbar .spacer { flex: 1; }

/* Tabuľka */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 12px; background: #fafbfc; position: sticky; top: 0; }
tr:hover td { background: #fafbff; }
tr.sel td { background: var(--accent-soft); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.sup { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.more { padding: 10px; text-align: center; }
.muted { color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.b-pending, .b-received { background: var(--red-bg); color: var(--red); }
.b-approved, .b-sent { background: var(--green-bg); color: var(--green); }
.b-rejected { background: var(--orange-bg); color: var(--orange); }
.b-queued { background: var(--blue-bg); color: var(--blue); }

.vatbtn { min-width: 46px; font-weight: 600; padding: 3px 8px; }
.popover { position: absolute; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px #0002; max-height: 360px; overflow-y: auto; min-width: 360px; }
.popover div { padding: 6px 12px; cursor: pointer; }
.popover div:hover { background: var(--accent-soft); }
.popover div.cur { font-weight: 600; }
.popover b { display: inline-block; width: 30px; }

/* Detail (Ján) */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(900px, 100%); background: var(--panel); box-shadow: -4px 0 24px #0002; display: flex; flex-direction: column; z-index: 40; }
.drawer .dhead { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.drawer .dbody { flex: 1; display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.drawer .dside { padding: 14px; border-left: 1px solid var(--line); overflow-y: auto; }
.drawer .dside h4 { margin: 14px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.drawer .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.events { font-size: 12px; }
.events div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.preview { width: 100%; height: 100%; border: 0; background: #f0f0f0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 8px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }

/* Stožok */
.stozok { display: grid; grid-template-columns: 430px 1fr; gap: 14px; height: calc(100vh - 80px); }
.stozok .left { display: flex; flex-direction: column; min-height: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: 0; border-radius: 0; padding: 8px 16px; }
.seg button.active { background: var(--accent); color: #fff; }
.stozok .filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.stozok .filters select { flex: 1; min-width: 160px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-y: auto; flex: 1; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: #fafbff; }
.item.sel { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
.item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .am { text-align: right; font-variant-numeric: tabular-nums; }
.item .sub { font-size: 12px; color: var(--muted); }
.stozok .right { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 0; overflow: hidden; }
.stozok .right .pv { flex: 1; min-height: 0; }
.stozok .right .bottom { padding: 12px; border-top: 1px solid var(--line); }
.stozok .right .bottom .row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Nastavenia */
.settings { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.box h3 { margin: 0 0 10px; font-size: 15px; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5de; border-radius: 22px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(16px); }
.prefixes div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; max-width: 90vw; }
.toast.err { background: var(--red); }

.modal-bg { position: fixed; inset: 0; background: #0005; z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 10px; padding: 20px; width: min(460px, 92vw); }
.modal h3 { margin: 0 0 10px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 900px) {
  .stozok, .settings, .drawer .dbody { grid-template-columns: 1fr; height: auto; }
  .stozok .right { height: 80vh; }
  .drawer .dbody { overflow-y: auto; }
  #dPrev { height: 65vh; }
  .stozok .left .list { max-height: 50vh; }
}
