:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e4e9;
  --color-text: #1c1f26;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--color-primary);
}

header.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

header.app-header h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

nav.app-nav {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
}

nav.app-nav a {
  text-decoration: none;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
}

nav.app-nav a.active,
nav.app-nav a:hover {
  color: var(--color-primary);
  background: #eef2ff;
}

/* Drop-down groups in the top navigation */
.nav-group {
  position: relative;
}

.nav-group-btn {
  background: none;
  border: 0;
  color: var(--color-text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.5;
  min-height: 0;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
}

.nav-group-btn.active,
.nav-group-btn:hover,
.nav-group.open .nav-group-btn {
  color: var(--color-primary);
  background: #eef2ff;
}

.nav-group-btn:focus-visible,
nav.app-nav a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.nav-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  min-width: 180px;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.nav-menu a {
  display: block;
  white-space: nowrap;
}

.nav-group.open .nav-menu {
  display: block;
}

@media (hover: hover) {
  .nav-group:hover .nav-menu {
    display: block;
  }
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

select, input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="password"], input[type="search"], textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

textarea {
  width: 100%;
  resize: vertical;
}

label {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

.field {
  margin-bottom: var(--space-3);
}

.field-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.field-row > .field {
  flex: 1;
  min-width: 160px;
}

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 14px;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .btn:hover { background: var(--color-primary-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: #f0f1f3; }

.btn-danger { background: var(--color-danger); }
.btn-warning { background: var(--color-warning); }
.btn-success { background: var(--color-success); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* the line deducting a paid advance invoice — filled in by the server */
.advance-row input { background: #f4f5f7; color: var(--color-text); }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
th { color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafafa; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge-unpaid { background: #eef0f3; color: #475569; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-overdue { background: #fee2e2; color: #991b1b; }

.brand-tag {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e0e7ff;
  color: #3730a3;
}

.muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.right { text-align: right; }
.flex-end { display:flex; justify-content:flex-end; gap: var(--space-2); }

.items-table input { width: 100%; }
.items-table td { vertical-align: top; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--color-text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 100;
}
.toast.error { background: var(--color-danger); }

.empty-state {
  text-align: center;
  padding: var(--space-5);
  color: var(--color-text-muted);
}

.autocomplete {
  position: relative;
}
.autocomplete-list {
  position: absolute;
  z-index: 20;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0,0,0,.08);
}
.autocomplete-list div {
  padding: 8px 10px;
  cursor: pointer;
}
.autocomplete-list div:hover { background: #eef2ff; }

.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--color-primary);
  background: #eef2ff;
}
.dropzone.has-file {
  border-style: solid;
  border-color: var(--color-success);
  color: var(--color-text);
}
.scan-status {
  margin-top: var(--space-2);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}
.scan-status.scanning { background: #eef2ff; color: var(--color-primary); }
.scan-status.ok { background: #dcfce7; color: #166534; }
.scan-status.fail { background: #fef3c7; color: #92400e; }

.internal-note-card {
  background: #fffbea;
  border-color: #fde68a;
}

.attachment-preview {
  max-width: 100%;
  max-height: 420px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

/* Invoice list: filterable list on the left, PDF preview on the right */
.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}
.split-list,
.split-preview {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  min-width: 0;
}
.split-preview { display: none; }

.filter-panel {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.filter-panel input[type="search"] {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.filter-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
#filterToggle.is-active,
#itemsLaterBtn.is-active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #eef2ff;
}
.filter-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}
.filter-row > select,
.filter-row > input {
  flex: 1;
  min-width: 0;
}
.filter-row > span { color: var(--color-text-muted); }

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
}
.chip:hover { background: #f0f1f3; }
.chip[aria-pressed="true"] {
  background: #eef2ff;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.list-summary {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.invoice-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.invoice-list a {
  display: block;
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--color-border);
  border-left: 3px solid transparent;
  color: inherit;
  text-decoration: none;
}
.invoice-list a:hover { background: #fafafa; }
.invoice-list a[aria-current="true"] {
  background: #eef2ff;
  border-left-color: var(--color-primary);
}
.invoice-list .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}
.invoice-list .number { font-weight: 700; }
.invoice-list .total { font-weight: 700; white-space: nowrap; }
.invoice-list .customer {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invoice-list .meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* Role-aware UI — mirrors the server's rules in middleware/auth.js.
   Accountant (read-only): every button is hidden unless marked .ro (filters,
   menus, "show details" — things that change nothing), plus links into the
   edit forms. Whitelisting means a forgotten mark hides a harmless control
   rather than showing one that would only answer "no permission". */
html[data-role="uctovnicka"] button:not(.ro),
html[data-role="uctovnicka"] a[href^="faktura-nova.html"],
html[data-role="uctovnicka"] a[href^="vydavok-novy.html"],
html[data-role="uctovnicka"] .write-only,
html[data-role="uctovnicka"] .dropzone {
  display: none !important;
}
/* Settings, backups and accounts belong to the owner. */
html[data-role="fakturant"] .owner-only,
html[data-role="uctovnicka"] .owner-only {
  display: none !important;
}

/* Incoming-document line that still needs a stock decision */
tr.needs-decision td:first-child { box-shadow: inset 3px 0 0 var(--color-warning); }
tr.needs-decision select { border-color: var(--color-warning); }
.candidate-btn {
  background: #fef3c7;
  color: #92400e;
  border-color: transparent;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  margin: 2px 4px 0 0;
}
.candidate-btn:hover { background: #fde68a; }

/* Per-row "⋯" actions menu */
.invoice-list li { position: relative; }
/* Selecting several documents at once (bulk actions) */
.invoice-list .pick { display: none; position: absolute; left: 12px; top: 13px; width: 18px; height: 18px; margin: 0; }
.invoice-list.selecting .pick { display: block; }
.invoice-list.selecting a { padding-left: 40px; }
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: #eef2ff;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}
.bulk-bar[hidden] { display: none; }
.row-menu-btn {
  position: absolute;
  right: var(--space-2);
  bottom: 6px;
  padding: 0 8px;
  font-size: 18px;
  line-height: 22px;
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
.row-menu-btn:hover,
.row-menu-btn[aria-expanded="true"] {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

.menu {
  position: fixed;
  z-index: 50;
  min-width: 220px;
  padding: var(--space-1) 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 16px rgba(0,0,0,.12);
}
.menu [role="menuitem"] {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu [role="menuitem"]:hover,
.menu [role="menuitem"]:focus-visible {
  background: #eef2ff;
  outline: none;
}
.menu [role="menuitem"].danger { color: var(--color-danger); }
.menu hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-1) 0;
}

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  box-shadow: 0 12px 32px rgba(0,0,0,.2);
}
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog h2 { margin: 0 0 var(--space-3); font-size: 17px; }
.dialog input,
.dialog textarea { width: 100%; }

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.preview-header h2 { margin: 0; font-size: 16px; }
.preview-frame {
  flex: 1;
  width: 100%;
  border: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #e5e7eb;
}

@media (min-width: 900px) {
  /* Both panes fill the viewport and scroll on their own */
  body.page-split {
    height: 100vh;
    display: flex;
    flex-direction: column;
  }
  body.page-split main {
    flex: 1;
    min-height: 0;
    max-width: none;
    width: 100%;
    display: flex;
    flex-direction: column;
  }
  .split {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(340px, 420px) 1fr;
  }
  .split-list {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .invoice-list { overflow-y: auto; flex: 1; }
  .split-preview {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
}

@media (max-width: 640px) {
  /* Incoming-document items: one card per item instead of a six-column row */
  .items-stack thead { display: none; }
  .items-stack tr {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 6px;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
  }
  .items-stack td { padding: 0; border: 0; }
  .items-stack td:nth-child(1) { grid-column: 1 / 4; }
  .items-stack td:nth-child(6) { grid-column: 4; grid-row: 1; }
  .items-stack td:nth-child(5) { grid-column: 1 / -1; }
  .items-stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--color-text-muted);
  }
  .items-stack tr.needs-decision td:first-child { box-shadow: none; }
  .items-stack tr.needs-decision { box-shadow: inset 3px 0 0 var(--color-warning); padding-left: 8px; }
  button, .btn { min-height: 40px; }
  .btn-sm, .chip, .candidate-btn, .row-menu-btn { min-height: 0; }

  main { padding: var(--space-3); }
  header.app-header { flex-direction: column; align-items: flex-start; }
}

/* "Vaše údaje sú vaše" — the data promise on the public pages */
.data-promise { border: 1px solid var(--color-border); border-left: 4px solid var(--color-success); border-radius: var(--radius); padding: 12px 14px; margin: 16px 0; background: var(--color-surface); }
.data-promise h2 { font-size: 15px; margin: 0 0 8px; }
.data-promise ul { margin: 0 0 6px; padding-left: 18px; font-size: 14px; }
.data-promise li { margin-bottom: 4px; }
.data-promise a { font-size: 13px; }

/* Labels (štítky): coloured chips; --label is the label's colour */
.label-chip{display:inline-block;border:1px solid var(--label,#2563eb);background:color-mix(in srgb,var(--label,#2563eb) 14%,transparent);color:var(--color-text);border-radius:999px;padding:0 8px;font-size:12px;line-height:1.6;margin:2px 4px 0 0;white-space:nowrap}
.label-group{display:flex;flex-wrap:wrap;align-items:center;gap:2px 4px;margin:2px 0}
.label-pick{display:inline-flex;align-items:center;gap:2px;font-weight:400;cursor:pointer;margin:0 6px 0 0}
.label-pick input{margin:0}
.label-pick input:not(:checked)+.label-chip{background:transparent;opacity:.7}
