/* Aparatus web — same workshop look as the phone app: light steel ground, ink-black header,
   safety-yellow accent. */
:root {
  --bg: #e8eaed;
  --card: #ffffff;
  --border: #c9ced6;
  --primary: #f5b700;
  --on-primary: #12161c;
  --text: #12161c;
  --muted: #5b6572;
  --danger: #b3261e;
  --success: #17794a;
  --warning: #8a5a00;
  --header: #12161c;
  --header-text: #ffffff;
  --header-muted: #aeb6c2;
  --soft-yellow: #fff4cc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Georgian", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: 100%; max-width: 400px; }
.auth-title { font-size: 30px; font-weight: 800; margin: 0 0 6px; letter-spacing: 0.5px; }
.auth-bar { width: 56px; height: 6px; background: var(--primary); border-radius: 3px; margin-bottom: 14px; }
.auth-sub { color: var(--muted); margin: 0 0 18px; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.side { background: var(--header); color: var(--header-text); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 26px; font-weight: 800; letter-spacing: 0.5px; padding: 6px 10px 2px; }
.brand-bar { width: 44px; height: 5px; background: var(--primary); border-radius: 3px; margin: 0 10px 18px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; text-decoration: none; color: var(--header-muted); font-weight: 600; margin-bottom: 4px; }
.nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav a.active { background: var(--primary); color: var(--on-primary); }
.nav .badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 12px; border-radius: 10px; padding: 1px 8px; font-weight: 800; }
.side .me { margin-top: auto; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,0.12); color: var(--header-muted); font-size: 13px; }
.side .me b { color: #fff; display: block; word-break: break-all; }
.side .me button { margin-top: 8px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.topbar h1 { font-size: 24px; margin: 0; flex: 1; min-width: 160px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar input[type=date], .toolbar select { min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 220px; }

/* ---------- controls ---------- */
.btn { background: var(--primary); color: var(--on-primary); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 800; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary { background: var(--card); border: 1px solid var(--border); color: var(--text); font-weight: 700; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 42px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 5px; }
label.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
label.check input { width: auto; min-height: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin: -6px 0 12px; }
.err { color: var(--danger); font-weight: 600; margin: 8px 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary); color: var(--on-primary); }

/* ---------- cards & tables ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.warn .v { color: var(--warning); }
.stat.bad .v { color: var(--danger); }
.stat.good .v { color: var(--success); }
.tbl-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #e3e6eb; vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; background: #f5f6f8; position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
th.sorted::after { content: " ▲"; }
th.sorted.desc::after { content: " ▼"; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fbf7e6; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
.plate { display: inline-block; background: var(--header); color: var(--primary); font-weight: 800; padding: 2px 8px; border-radius: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: 800; }
.pill.ok { background: #e3f3ea; color: var(--success); }
.pill.soon { background: #fff1d6; color: var(--warning); }
.pill.overdue { background: #f9e1df; color: var(--danger); }
.pill.planned { background: #e3f3ea; color: var(--success); }
.pill.unplanned { background: #fff1d6; color: var(--warning); }
.pill.open { background: #f9e1df; color: var(--danger); }
.pill.resolved { background: #e3f3ea; color: var(--success); }
.muted { color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 14px; }
.kv .k { color: var(--muted); }
.detail-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-head h1 { margin: 4px 0 0; }
.bars { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; align-items: end; height: 160px; padding-top: 10px; }
.bars .b { background: var(--primary); border-radius: 6px 6px 0 0; position: relative; min-height: 2px; }
.bars .b span { position: absolute; bottom: 100%; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars-x { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }
.problem-box { border-left: 5px solid var(--danger); }
.problem-box.resolved { border-left-color: var(--success); opacity: 0.85; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--header); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.25); z-index: 50; max-width: 420px; }
.toast.bad { background: var(--danger); }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(18,22,28,0.55); }
dialog form { padding: 22px 24px; max-height: 92vh; overflow: auto; }
dialog h2 { margin: 0 0 16px; font-size: 20px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

/* ---------- small screens ---------- */
/* the phone header, tab bar and sheets exist only on narrow screens */
.m-head, .m-tabs, .m-sheet { display: none; }

@media (max-width: 860px) {
  body { -webkit-text-size-adjust: 100%; }
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 70px 14px calc(92px + env(safe-area-inset-bottom)); }
  .row2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv .k { margin-top: 8px; font-size: 13px; }

  /* header */
  .m-head { display: flex; align-items: center; justify-content: space-between; position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0; background: var(--header); color: #fff; border-bottom: 3px solid var(--primary); }
  .m-brand { font-size: 21px; font-weight: 800; letter-spacing: .4px; }
  .m-avatar { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--primary); background: transparent; color: #fff; font-weight: 800; font-size: 17px; cursor: pointer; }
  .m-avatar.big { width: 52px; height: 52px; font-size: 22px; color: var(--text); flex: none; display: grid; place-items: center; }

  /* bottom tab bar */
  .m-tabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--header);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 18px rgba(0,0,0,.18); }
  .m-tabs a, .m-tabs button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
    padding: 6px 2px; border: 0; background: none; color: var(--header-muted); text-decoration: none; font: inherit; border-radius: 12px; cursor: pointer; }
  .m-tabs .i { font-size: 21px; line-height: 1.1; }
  .m-tabs .t { font-size: 10.5px; font-weight: 700; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .m-tabs .active { color: var(--primary); background: rgba(245,183,0,.12); }
  .m-tabs .badge { position: absolute; top: 0; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; border-radius: 9px; padding: 0 6px; line-height: 17px; }

  /* sheets (more pages / account) */
  .m-sheet:not([hidden]) { display: flex; position: fixed; inset: 0; z-index: 60; background: rgba(18,22,28,.55); align-items: flex-end; }
  .m-sheet-card { width: 100%; background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; animation: m-up .18s ease-out; }
  @keyframes m-up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
  .m-sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
  .m-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 0 8px; border: 0; border-bottom: 1px solid #eceef1;
    background: none; text-align: left; font: inherit; font-size: 16px; font-weight: 600; color: var(--text); text-decoration: none; cursor: pointer; }
  .m-row .i { width: 28px; text-align: center; font-size: 20px; }
  .m-row.active { color: var(--warning); }
  .m-row.danger { color: var(--danger); }
  .m-me { display: flex; gap: 14px; align-items: center; padding: 6px 8px 14px; border-bottom: 1px solid #eceef1; }
  .m-me b { font-size: 17px; }
  .m-close { width: 100%; margin-top: 14px; min-height: 48px; }

  /* page title + its main button */
  .topbar { gap: 10px; margin-bottom: 12px; }
  .topbar h1 { font-size: 22px; min-width: 0; }
  .topbar .btn { padding: 11px 14px; }

  /* touch-friendly controls; 16px text stops iPhones from zooming into fields */
  input[type=text], input[type=search], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }
  label.check { min-height: 40px; }
  label.check input { width: 22px; height: 22px; }

  /* filters: search on its own line, the rest two per row */
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar > * { min-width: 0 !important; width: 100%; }
  .toolbar .grow, .toolbar input[type=search], .toolbar > .btn, .toolbar > span, .toolbar > .muted, .toolbar > .seg { grid-column: 1 / -1; }

  /* stat tiles: two per row, compact */
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .v { font-size: 22px; overflow-wrap: anywhere; }
  .card { padding: 14px; border-radius: 14px; }
  .detail-head { gap: 10px; }
  .detail-head h1 { font-size: 20px; flex-basis: 100%; }

  /* tables with column titles become one card per row */
  .tbl-wrap { background: none; border: 0; overflow: visible; }
  table.m-cards, table.m-cards tbody, table.m-cards tr, table.m-cards td { display: block; width: 100%; }
  table.m-cards thead, table.m-cards tr.m-headrow { display: none !important; }
  table.m-plain { display: block; overflow-x: auto; }
  .bars, .bars-x { gap: 2px !important; }
  .bars-x { font-size: 9px; letter-spacing: -.3px; }
  .bars .b span { font-size: 8px; }
  table.m-cards tr { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 8px 14px; margin-bottom: 10px; }
  table.m-cards tr.click:active { background: #fbf7e6; }
  /* label in a fixed left column, the value flows normally to its right */
  table.m-cards td { display: block; position: relative; min-height: 34px; padding: 7px 0 7px 36%; border: 0; border-bottom: 1px dashed #e3e6eb; text-align: left; overflow-wrap: anywhere; }
  table.m-cards td:last-child { border-bottom: 0; }
  table.m-cards td::before { content: attr(data-label); position: absolute; left: 0; top: 9px; width: calc(36% - 12px); color: var(--muted); font-size: 12.5px; font-weight: 600; line-height: 1.3; }
  table.m-cards td.m-nolabel, table.m-cards td[data-label=""] { padding-left: 0; }
  table.m-cards td.m-nolabel::before, table.m-cards td[data-label=""]::before { content: none; }
  table.m-cards td.m-dash { display: none; }
  /* the first field is the card's title */
  table.m-cards td:first-child { padding-left: 0; font-weight: 800; font-size: 15.5px; padding-top: 4px; }
  table.m-cards td:first-child::before { content: none; }
  table.m-cards td.num { text-align: left; }
  table.m-cards td.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 10px 0 4px; }
  table.m-cards td.actions::before { content: none; }
  table.m-cards td.actions:empty { display: none; }
  table.m-cards tr.m-empty { text-align: center; }
  table.m-cards tr.m-empty td { padding-left: 0; text-align: center; font-weight: 400; }
  table.m-cards tr.m-empty td::before { content: none; }
  table.m-plain td { padding: 10px 6px; }

  /* forms open full-screen with the buttons always visible */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog form { max-height: 100dvh; height: 100%; padding: calc(16px + env(safe-area-inset-top)) 16px 0; display: flex; flex-direction: column; }
  dialog form > :not(.dlg-buttons) { flex: none; }
  dialog h2 { font-size: 19px; }
  .dlg-buttons { position: sticky; bottom: 0; margin-top: auto; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid #eceef1; }
  .dlg-buttons .btn { flex: 1; min-height: 48px; }

  .toast { left: 14px; right: 14px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: none; }
  .idle-warning { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .qr-preview > div { zoom: 1 !important; }
}
@media print {
  .side, .toolbar, .btn, .topbar .btn { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
}

/* ---------- QR sticker (machine page → 🔳 QR სტიკერი) ---------- */
.qr-preview { display: flex; justify-content: center; padding: 14px; background: #e5e7eb; border-radius: 12px; margin: 10px 0 4px; overflow: auto; }
.qr-label { background: #fff; color: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; box-sizing: border-box; padding: 2mm; }
.qr-label.cut { outline: 0.2mm dashed #9a9a9a; outline-offset: -0.1mm; }
.qr-label.v { flex-direction: column; text-align: center; }
.qr-label.h { flex-direction: row; text-align: left; }
.qr-label .qr { flex: none; }
.qr-label .qr svg { width: 100%; height: 100%; display: block; }
.qr-label .txt { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.qr-label.v .txt { align-items: center; max-width: 100%; }
.qr-label .code { font-family: Consolas, "Courier New", monospace; font-weight: 700; letter-spacing: .2mm; white-space: nowrap; line-height: 1.1; }
.qr-label .name { line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.qr-label .loc { color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#qr-print { display: none; }
@media print {
  html:has(body.printing-qr), body.printing-qr { background: #fff !important; }
  body.printing-qr > *:not(#qr-print) { display: none !important; }
  body.printing-qr #qr-print { display: block; }
  #qr-print .qr-sheet { display: grid; break-after: page; page-break-after: always; }
  #qr-print .qr-sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ---------- automatic sign-out warning ---------- */
.idle-warning { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10000; max-width: min(560px, 92vw);
  background: #12161C; color: #fff; border-left: 6px solid #F5B700; border-radius: 12px; padding: 14px 18px; font-size: 15px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
.idle-warning[hidden] { display: none; }
@media print { .idle-warning { display: none !important; } }

@media print { .m-head, .m-tabs, .m-sheet { display: none !important; } .main { padding: 0 !important; } }
