/* Shared subapp chrome (docs/ui-styleguide.md, applied to the whitelabel surfaces).
 *
 * Every subapp template — the ones under app/views/subapp/ — is written against this
 * vocabulary, so a new customer needs a skin and a layout choice, not a stylesheet.
 * Structure only: every colour, font and radius comes from the skin the layout loads
 * after this sheet (public/themes/skins/, contract in skins/ui-default.css). A subapp
 * adds its own components in public/themes/<key>/components.css.
 *
 * `data-chrome="bottom"` puts navigation in a bottom bar (phone-first surfaces);
 * `data-chrome="rail"` puts it in a left rail (desktop operations surfaces).
 */

:root {
  --rail: 232px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--fs-base)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---------- shell ---------- */

.screen { min-height: 100vh; }
.content { padding: 20px; max-width: 1320px; margin: 0 auto; }

.screen[data-nav] { padding-bottom: 76px; }

.nav {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav__brand { display: flex; align-items: center; gap: 8px; margin-right: 12px; }
.nav__logo { width: 26px; height: 26px; border-radius: 6px; }
.nav__wordmark { display: none; font-weight: 700; letter-spacing: -0.01em; }

.nav__tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  padding: 6px 4px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--fs-small);
}
.nav__tab--active { color: var(--accent); background: var(--accent-soft); }
.nav__label { font-size: var(--fs-small); }
.nav__icon {
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: var(--icon) center / contain no-repeat;
  -webkit-mask: var(--icon) center / contain no-repeat;
}

/* Desktop operations surfaces move the same nav into a left rail. */
@media (min-width: 900px) {
  .screen[data-chrome="rail"][data-nav] { padding: 0 0 0 var(--rail); }
  .screen[data-chrome="rail"] .nav {
    inset: 0 auto 0 0;
    width: var(--rail);
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 16px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .screen[data-chrome="rail"] .nav__brand { margin: 0 0 16px; padding: 0 8px; }
  .screen[data-chrome="rail"] .nav__wordmark { display: inline; }
  .screen[data-chrome="rail"] .nav__tab {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 9px 10px;
  }
  .screen[data-chrome="rail"] .content { padding: 24px 28px; }
}

/* ---------- header ---------- */

.header { margin-bottom: 18px; }
.header--nav, .header--detail, .header--profile { margin-bottom: 14px; }
.header__row { display: flex; align-items: center; gap: 12px; }
.header__title { margin: 0; font-size: var(--fs-title); font-weight: 650; letter-spacing: -0.01em; }
.header__title-group { display: flex; align-items: center; gap: 10px; }
.header__subtitle { margin: 4px 0 0; color: var(--muted); font-size: var(--fs-small); }
.header__row .btn-primary,
.header__row .icon-btn { margin-left: auto; }

/* ---------- surfaces ---------- */

.section { margin-bottom: 20px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel__head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel__head--start { justify-content: flex-start; border-bottom: 0; }
.panel__title { margin: 0; font-size: var(--fs-small); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.panel__body { padding: 14px; }
.panel--row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.metric {
  display: block;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.metric__label { display: block; color: var(--muted); font-size: var(--fs-small); }
.metric__value { display: block; margin-top: 6px; font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric__value--danger { color: var(--down); }
.metric__unit { margin-left: 4px; font-size: var(--fs-small); color: var(--muted); }

.list { margin: 0; padding: 0; list-style: none; }

.kv__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv__row:last-child { border-bottom: 0; }
.kv__key { color: var(--muted); font-size: var(--fs-small); }
.kv__val { font-variant-numeric: tabular-nums; }

.empty { padding: 32px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty__msg { margin: 0; }
.empty__msg + .empty__msg { margin-top: 10px; }
.empty-inline { color: var(--muted); font-size: var(--fs-small); }

/* ---------- status ---------- */

.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.badge--ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge--warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge--danger { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); vertical-align: middle; margin-right: 6px; }
.dot--warn { background: var(--warn); }
.dot--danger { background: var(--down); }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar__fill { display: block; height: 100%; width: var(--pct, 0%); background: var(--accent); }
.bar--warn .bar__fill { background: var(--warn); }
.bar--danger .bar__fill { background: var(--down); }

.banner { padding: 10px 12px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); background: var(--surface); margin-bottom: 14px; }
.banner--danger { border-left-color: var(--down); }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); display: flex; gap: 8px; padding: 10px 14px; background: var(--ink); color: var(--bg); border-radius: 999px; opacity: 0; transition: opacity .2s; }
.toast--on { opacity: 1; }
.toast__check { font-weight: 700; }
.toast__text { font-size: var(--fs-small); }

/* ---------- controls ---------- */

.btn-primary, .btn-cta, .btn-secondary, .btn-danger-outline, .btn-link, .chip, .pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  cursor: pointer;
}
.btn-primary, .btn-cta { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-danger-outline { background: transparent; border-color: var(--down); color: var(--down); }
.btn-link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 0; }

.chip, .pill { background: var(--surface); border-color: var(--line); color: var(--muted); }
.chip--active, .pill--active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: var(--radius); background: none; cursor: pointer; }
.icon-btn--outlined { border-color: var(--line); background: var(--surface); }

.form { display: block; }
.form__row { margin-bottom: 14px; }
.field__label, .setting__label { display: block; margin-bottom: 6px; font-size: var(--fs-small); font-weight: 600; }
.input, .select > select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
}
.select { display: block; }

.settings { display: block; }
.settings__group { margin-bottom: 18px; }
.settings__card--prefs { padding-top: 4px; }
.field { display: block; }
.photo-upload .panel__body { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.photo-upload img { width: 96px; height: 96px; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); }
.settings__card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.settings__group-title { margin: 0 0 12px; font-size: var(--fs-small); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.setting__row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.setting__row:last-child { border-bottom: 0; }
.setting__hint { color: var(--muted); font-size: var(--fs-small); }
.setting__text { flex: 1; }
.logout-section { margin: 24px 0 8px; }

/* ---------- alerts ---------- */

.alert { display: block; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: var(--radius); margin-bottom: 10px; }
.alert__head { display: flex; align-items: center; gap: 8px; }
.alert__name { font-weight: 650; }
.alert__body { margin: 6px 0 0; color: var(--muted); font-size: var(--fs-small); }
.alert__foot { margin-top: 8px; }
.alert__time { color: var(--muted); font-size: 12px; }
.alert__glyph { width: 10px; height: 10px; border-radius: 2px; background: var(--muted); }
.alert__glyph--warn { background: var(--warn); }
.alert__glyph--danger { background: var(--down); }
.panel--guidance { border-left: 3px solid var(--accent); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; padding: 9px 12px; font-size: var(--fs-small); font-weight: 650; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }

/* ---------- auth ---------- */

.screen--auth { display: grid; place-items: center; padding: 24px; }
.screen--surface { background: var(--surface-2); }
.auth--login { width: min(380px, 100%); }
.auth { width: min(380px, 100%); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand--lg .brand__logo img { width: 56px; height: 56px; }
.brand__titles { display: flex; flex-direction: column; }
.brand__logo img { width: 44px; height: 44px; border-radius: 10px; }
.brand__wordmark { font-size: var(--fs-title); font-weight: 700; }
.brand__tagline { margin: 2px 0 0; color: var(--muted); font-size: var(--fs-small); }
.auth__form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.auth__field { margin-bottom: 14px; }
.auth__label { display: block; margin-bottom: 6px; font-size: var(--fs-small); font-weight: 600; }
.auth__input { width: 100%; min-height: 40px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); font: inherit; }
.auth__input-wrap { position: relative; }
.auth__input-wrap .auth__input { padding-right: 58px; }
.auth__input-eye { position: absolute; right: 10px; top: 10px; cursor: pointer; color: var(--muted); font-size: var(--fs-small); font-weight: 600; }
.auth__submit { width: 100%; min-height: 42px; margin-top: 6px; border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; font: inherit; font-weight: 650; cursor: pointer; }
.auth__link { color: var(--accent); }

/* Turbo Drive visit progress (the bar appears after 500 ms of a pending visit) */
.turbo-progress-bar { height: 2px; background: var(--accent); }
