:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #646b75;
  --border: #dde0e5;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --error-bg: #fdecec;
  --error-text: #a12020;
  --ok-bg: #e8f5ec;
  --ok-text: #1d6b36;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #e7e9ec;
    --muted: #9aa1ab;
    --border: #2f343c;
    --accent: #4d8ce8;
    --error-bg: #3a1c1c;
    --error-text: #f2a3a3;
    --ok-bg: #18321f;
    --ok-text: #93d6a8;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
body.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }

h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1.2rem; }
.brand { font-weight: 700; letter-spacing: .02em; }
h1.brand { font-size: 1.6rem; margin-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 12px; }
.row h2 { margin: 0; }
[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.login { width: 100%; max-width: 380px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.wrap { max-width: 1000px; margin: 0 auto; padding: 16px; display: grid; gap: 24px; }
/* Let wide tables scroll inside their card instead of stretching the page on phones. */
.wrap > *, .stack > * { min-width: 0; }

form { display: grid; gap: 14px; margin-top: 16px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
input[type=email], input[type=password], input[type=text], input[type=number] {
  font: inherit; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button { font: inherit; cursor: pointer; border-radius: 8px; padding: 10px 16px; border: 1px solid transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.secondary { background: transparent; color: var(--text); border-color: var(--border); justify-self: center; margin-top: 16px; }
#load-more { display: block; margin: 16px auto 0; }
.link { background: none; color: var(--accent); padding: 4px 6px; text-decoration: none; }

.alert { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: .9rem; }
.alert.error { background: var(--error-bg); color: var(--error-text); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }

.dropzone {
  display: grid; place-items: center; gap: 4px; text-align: center;
  padding: 28px 16px; border: 2px dashed var(--border); border-radius: var(--radius);
  cursor: pointer; font-weight: 400;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-title { font-weight: 600; color: var(--accent); }

.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.previews:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--border); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; top: 4px; left: 4px; padding: 0 5px; border-radius: 4px;
  font-size: .65rem; background: rgba(0,0,0,.6); color: #fff;
}
.placeholder {
  width: 100%; height: 100%; display: grid; place-items: center; padding: 6px;
  text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted);
}
.thumb .state {
  position: absolute; inset: auto 0 0 0; padding: 2px 4px;
  font-size: .7rem; text-align: center; background: rgba(0,0,0,.6); color: #fff;
}
.thumb .remove {
  position: absolute; top: 4px; right: 4px; padding: 0 7px; line-height: 1.5;
  background: rgba(0,0,0,.6); color: #fff; border-radius: 50%;
}

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.photo { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.photo .frame { aspect-ratio: 4 / 3; background: var(--border); }
.photo .frame a { display: block; width: 100%; height: 100%; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.photo .meta { padding: 8px 10px; font-size: .8rem; display: grid; gap: 2px; }
.photo .note { font-weight: 600; font-size: .85rem; overflow-wrap: anywhere; }
.photo .actions { display: flex; gap: 4px; padding: 0 6px 6px; }
.photo .actions button { font-size: .8rem; padding: 2px 6px; }
.photo .delete, .link.delete { color: var(--error-text); }

/* ---------- Layout helpers ---------- */
.stack { display: grid; gap: 16px; }
.grow { flex: 1; min-width: 0; }
.wrap-row { flex-wrap: wrap; }
.grow h2 { margin-bottom: 2px; }
.grow p { margin: 0; }

select, input[type=date], input[type=datetime-local] {
  font: inherit; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.slim { padding: 7px 12px; margin: 0; font-size: .9rem; }
.inline-form { display: flex; gap: 8px; margin: 0; }
.inline-form input { width: 200px; max-width: 100%; }
.range { margin-top: 14px; }
.qty-row { align-items: flex-end; }

/* Materials: category tabs + item lines */
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.subtabs button {
  padding: 7px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.subtabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.mat-group { display: grid; gap: 8px; }
.mat-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 90px 44px 36px; gap: 6px; align-items: center;
}
.mat-row select, .mat-row input[type=number] { width: 100%; min-width: 0; }
.mat-row .mat-other { grid-column: 1 / -1; }
.mat-unit { text-align: left; overflow: hidden; text-overflow: ellipsis; }
.remove-row {
  padding: 6px 0; background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 1.1rem; line-height: 1;
}
.remove-row:hover { color: var(--error-text); border-color: var(--error-text); }
.add-more { justify-self: start; margin-top: 0; }
@media (max-width: 480px) {
  .mat-row { grid-template-columns: minmax(0, 1fr) 70px 34px 32px; }
}
.qty-row span { padding-bottom: 10px; min-width: 40px; }
.pill.low { background: var(--error-bg); color: var(--error-text); border-color: transparent; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 49px; z-index: 4;
}
.tabs.inset { position: static; background: none; padding: 0; }
.tabs button {
  background: none; border: none; border-bottom: 3px solid transparent; border-radius: 0;
  padding: 12px 14px; color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Time clock ---------- */
.clock { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 28px 20px; }
.clock.on { border-color: var(--ok-text); box-shadow: inset 0 4px 0 var(--ok-text); }
.clock-now { margin: 0; font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock-status { margin: 0; color: var(--muted); }
.clock.on .clock-status { color: var(--ok-text); font-weight: 600; }
.clock-note { width: 100%; max-width: 360px; text-align: left; }
.big { font-size: 1.2rem; padding: 16px 40px; min-width: 220px; border-radius: 999px; }
.primary.danger { background: var(--error-text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 12px -4px 8px; }
table.entries { width: 100%; border-collapse: collapse; font-size: .9rem; }
.entries th, .entries td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.entries td.muted, .entries td.addr { white-space: normal; }
.entries td.addr { min-width: 140px; overflow-wrap: anywhere; }
.entries th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.entries .num { text-align: right; font-variant-numeric: tabular-nums; }
.entries.clickable tbody tr { cursor: pointer; }
.entries tr.group-row td { background: var(--bg); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; }
.entries.clickable tbody tr.group-row { cursor: default; }
.entries.clickable tbody tr:hover, .entries.clickable tbody tr:focus { background: var(--bg); outline: none; }
.live { color: var(--ok-text); font-weight: 600; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.pill.on { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; font-weight: 600; }
.pill.tiny { font-size: .65rem; padding: 0 6px; margin-left: 6px; vertical-align: middle; }

/* ---------- Admin ---------- */
.card.attention { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { display: grid; gap: 4px; padding: 14px 16px; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.big-num { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-form { margin: 0; }
.dialog-form .row { margin-top: 4px; }

@media (max-width: 600px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .inline-form { width: 100%; }
  .inline-form input { flex: 1; width: auto; }
}

@media (max-width: 480px) {
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  #user-email { display: none; }
}
