:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --accent: #337ab7;
  --accent-ink: #ffffff;
  --st-var-bg: #fde4e4;         --st-var: #a3261f;
  --st-megrendelve-bg: #fff3d6; --st-megrendelve: #8a5a00;
  --st-itt-bg: #dcf5e3;         --st-itt: #13632f;
  --st-kesz-bg: #ececea;        --st-kesz: #5c5c58;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #bbb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.link { border: none; background: none; padding: 4px 6px; color: var(--muted); text-decoration: underline; }

input, select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
label.check input { width: auto; }
.error { color: #b3261e; margin: 8px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--ink); color: #fff; padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { font: inherit; background: none; border: none; color: #bbb; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.tab.active { background: #ffffff1f; color: #fff; }
.me { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.me .btn { color: #ddd; border-color: #ffffff33; }

.page { padding: 16px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.toolbar select, .toolbar input[type=number] { width: auto; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--panel);
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.chip span { color: var(--muted); font-size: 12px; margin-left: 2px; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip.active span { color: #ccc; }

/* Tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafaf8; }
td.num, td.date { color: var(--muted); white-space: nowrap; font-size: 13px; }
td.product { font-weight: 600; }
td.comment { color: var(--muted); max-width: 280px; white-space: pre-wrap; font-size: 14px; }
td.actions { white-space: nowrap; text-align: right; }
tr.is-kesz td { color: var(--muted); }
tr.is-kesz td.product { font-weight: 500; }
a.phone { color: inherit; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px; margin: 0; }
.more { text-align: center; padding: 12px; }

.status {
  font: inherit; font-size: 13px; font-weight: 600; border: none; border-radius: 999px;
  padding: 4px 26px 4px 10px; width: auto; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.status.st-var { background-color: var(--st-var-bg); color: var(--st-var); }
.status.st-megrendelve { background-color: var(--st-megrendelve-bg); color: var(--st-megrendelve); }
.status.st-itt { background-color: var(--st-itt-bg); color: var(--st-itt); }
.status.st-kesz { background-color: var(--st-kesz-bg); color: var(--st-kesz); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--st-kesz-bg); color: var(--st-kesz); }
.badge.on { background: var(--st-itt-bg); color: var(--st-itt); }

table.log td { font-size: 14px; }
.change { display: block; }
.change b { font-weight: 600; }
.old { color: #a33; text-decoration: line-through; }
.new { color: #13632f; }

/* Dialogs */
dialog { border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); box-shadow: 0 20px 60px #0004; }
dialog::backdrop { background: #0006; }
.dialog-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog-form h2 { margin: 0 0 4px; font-size: 19px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.meta { color: var(--muted); font-size: 13px; margin: 0; }
.history { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.history li:last-child { border-bottom: none; }
.history .when { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 10;
}

/* Phones: rows become cards */
@media (max-width: 760px) {
  .page { padding: 10px; }
  .topbar { gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .me #me-name { display: none; }
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  table.orders thead, table.log thead, table.users thead { display: none; }
  table.orders, table.orders tbody, table.orders tr, table.orders td,
  table.log, table.log tbody, table.log tr, table.log td,
  table.users, table.users tbody, table.users tr, table.users td { display: block; width: 100%; }
  table tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table td { border: none; padding: 3px 10px; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
  td.product::before, td.num::before { content: none; }
  td.actions { text-align: left; }
  td.comment { max-width: none; }
  td:empty { display: none; }
}
