/* Hand-written stylesheet for v1.
 * TODO(v1): replace with a real Tailwind build (docs/architecture.md section 7).
 * For now this is a small utility set covering the templates that exist. */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 1.3rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; }

.app-header {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .6rem 1rem;
}
.app-header .sep { color: var(--muted); }
.app-header .spacer { margin-left: auto; }
/* Scoped to the kiosk's bare <main> (a direct child of <body> there) so it
 * doesn't leak into the app shell's <main>, which lives inside .content and
 * must stretch to fill the sidebar's remaining width instead of centering. */
body > main { padding: 1rem; max-width: 1100px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.stack > * + * { margin-top: .75rem; }
.muted { color: var(--muted); }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: .75rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: .4rem .5rem; }
td { padding: .4rem .5rem; border-top: 1px solid var(--border); }

.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  font-size: 1rem; text-decoration: none;
}
.btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #1e40af; border-color: #1e40af; color: var(--primary-ink); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; color: #fff; }
.btn-lg { padding: .9rem 1.4rem; font-size: 1.15rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input.pin { width: 8rem; text-align: center; letter-spacing: .3em; font-size: 1.6rem; }

.pill { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; background: #e2e8f0; }
.pill.good { background: #dcfce7; color: var(--good); }
.pill.warn { background: #fef3c7; color: var(--warn); }
.pill.bad { background: #fee2e2; color: var(--bad); }

.kiosk { max-width: 720px; margin: 0 auto; }
.kiosk .card { padding: 1.5rem; }
.big-num { font-size: 2rem; font-weight: 700; }
.error { color: var(--bad); }
.param-ok { color: var(--good); }
.param-bad { color: var(--bad); font-weight: 700; }

/* --- App shell (staff) --- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: #0f172a; color: #cbd5e1;
  display: flex; flex-direction: column; padding: 1rem .75rem;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; padding: .25rem .5rem 1rem; display: block; }
.sidebar nav { flex: 1; overflow-y: auto; }
.nav-group { margin-bottom: 1rem; }
.nav-group-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: .25rem .5rem; }
.nav-item { display: block; padding: .45rem .5rem; border-radius: 6px; color: #cbd5e1; text-decoration: none; font-size: .92rem; }
.nav-item:hover { background: #1e293b; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-top { font-weight: 600; margin-bottom: 1rem; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: grid; grid-template-columns: 1fr minmax(220px, 460px) 1fr;
  align-items: center; gap: 1rem;
  background: var(--surface); padding: .55rem 1.25rem;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px -2px rgba(15, 23, 42, .12);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 1.15rem; font-weight: 600; }
.topbar-search { justify-self: stretch; }
.topbar-search input {
  width: 100%; padding: .4rem .7rem; font-size: .9rem;
  border: 1px solid var(--border); border-radius: 7px; background: var(--bg);
}
.topbar-user {
  justify-self: end;
  display: flex; align-items: center; gap: .8rem; font-size: .85rem; white-space: nowrap;
}
.topbar-user form { margin: 0; }
.content main { padding: 1.5rem 1.25rem; max-width: 1440px; margin: 0; width: 100%; }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; grid-auto-rows: auto; row-gap: .5rem; }
  .topbar-search { grid-column: 1 / -1; order: 3; }
  .topbar-user { grid-column: 2; }
}

.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 1rem; }
.stat-row { display: flex; gap: 1.5rem; margin: .5rem 0; }
.stat-row .big-num { font-size: 1.6rem; }
h3 { font-size: .95rem; margin: .75rem 0 .25rem; }

/* --- dashboard visualizations --- */
.stack-bar { display: flex; height: .6rem; border-radius: 999px; overflow: hidden; background: var(--border); margin-top: .6rem; }
.stack-seg { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: .1rem .9rem; margin-top: .5rem; font-size: .82rem; color: var(--muted); }
.legend-col { flex-direction: column; gap: .35rem; }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.legend-dot { width: .55rem; height: .55rem; border-radius: 999px; display: inline-block; flex: none; }

.donut-row { display: flex; align-items: center; gap: 1.25rem; margin: .5rem 0 .75rem; }
.donut { width: 92px; height: 92px; border-radius: 50%; flex: none; display: grid; place-items: center; }
.donut-hole {
  width: 62px; height: 62px; border-radius: 50%; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-hole .big-num { font-size: 1.3rem; line-height: 1; }

.bar-rows { display: flex; flex-direction: column; gap: .4rem; margin: .4rem 0; }
.bar-row { display: grid; grid-template-columns: 5.5rem 1fr 3rem; align-items: center; gap: .6rem; font-size: .85rem; }
.bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--border); border-radius: 999px; height: .55rem; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--primary); }
.bar-fill.good { background: var(--good); }
.bar-fill.bad { background: var(--bad); }
.bar-fill.warn { background: var(--warn); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.flash {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem; border-radius: 8px; margin-bottom: .85rem;
  font-weight: 600; color: var(--text);
  background: #eff6ff; border: 1px solid #bfdbfe; border-left: 4px solid var(--primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
  animation: flash-in .22s ease-out;
}
.flash::before {
  content: "i"; flex: none;
  display: grid; place-items: center;
  width: 1.35rem; height: 1.35rem; border-radius: 999px;
  font-size: .8rem; font-weight: 700; color: #fff; background: var(--primary);
}
.flash.success { background: #f0fdf4; border-color: #bbf7d0; border-left-color: var(--good); }
.flash.success::before { content: "\2713"; background: var(--good); }
.flash.error { background: #fef2f2; border-color: #fecaca; border-left-color: var(--bad); }
.flash.error::before { content: "\2715"; background: var(--bad); }
.flash.warning { background: #fffbeb; border-color: #fde68a; border-left-color: var(--warn); }
.flash.warning::before { content: "!"; background: var(--warn); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
.row-bad td { background: #fef2f2; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.login-wrap { max-width: 360px; margin: 12vh auto; }

/* --- mobile nav (off-canvas) --- */
.nav-toggle-cb { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.nav-burger { display: none; }
.nav-scrim { display: none; }

@media (max-width: 900px) {
  .shell { position: relative; }

  .nav-burger {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    flex: none; width: 38px; height: 38px; padding: 8px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer;
  }
  .nav-burger span { display: block; height: 2px; border-radius: 2px; background: var(--text); }
  .nav-toggle-cb:focus-visible ~ .content .nav-burger { outline: 2px solid var(--primary); outline-offset: 2px; }

  .sidebar {
    position: fixed; z-index: 40; inset: 0 auto 0 0;
    width: 250px; flex-basis: 250px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    will-change: transform;
  }
  .nav-toggle-cb:checked ~ .sidebar { transform: translateX(0); box-shadow: 0 0 24px rgba(0, 0, 0, .35); }

  .nav-toggle-cb:checked ~ .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(15, 23, 42, .5);
  }

  .content { width: 100%; min-width: 0; }
  .content main { padding: .85rem; }
  .topbar { padding: .6rem .85rem; gap: .6rem; }
  body > main { padding: .85rem; }
}

@media (max-width: 700px) {
  .grid.cols-2 { grid-template-columns: 1fr; }
  .tile-grid { grid-template-columns: 1fr; }
  .stat-row { flex-wrap: wrap; gap: .6rem 1.5rem; }
  .app-header { flex-wrap: wrap; row-gap: .1rem; }
  /* Wide tables scroll inside their card instead of the whole page. */
  .card { overflow-x: auto; }
}

/* --- settings form --- */
.stack label:not(.row) { display: block; font-size: .85rem; }
.stack label:not(.row) input, .stack label:not(.row) select {
  display: block; width: 100%; margin-top: .25rem; margin-bottom: .1rem;
}
.stack label.row input[type="checkbox"] { width: auto; }
