/* Honewell base styles. Mobile first: everything is designed at 390px wide, then centered. */
:root {
  --brand: #1f4e79;
  --brand-contrast: #ffffff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7a;
  --border: #dde2e8;
  --danger: #c0392b;
  --warn: #d4820a;
  --ok: #2e7d4f;
  --info: #3b6ea8;
  --urgent: #c0392b;
  --repair: #d4820a;
  --monitor: #3b6ea8;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --tabbar-h: 64px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 12px;
}
.brand { display: flex; align-items: center; text-decoration: none; color: var(--text); min-width: 0; }
.brand-logo { max-height: 40px; max-width: 180px; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* Page */
.page { max-width: 640px; margin: 0 auto; padding: 16px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-header h1 { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; text-decoration: none; color: var(--muted); font-size: 0.95rem; min-height: 44px; }
.section { margin-bottom: 24px; }
.section-title { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card-tight { padding: 0; overflow: hidden; }

/* List rows */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.row-link {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; min-height: 60px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.row-link:last-child { border-bottom: 0; }
.row-link:active { background: #eef1f5; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-link::after { content: "›"; color: var(--muted); font-size: 1.4rem; }
.row-link.no-chevron::after { content: none; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.btn-stack { display: grid; gap: 8px; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); border: 0;
}
@media (min-width: 700px) { .fab { right: calc(50% - 320px + 16px); } }

/* Forms */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
.field .help { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], input[type=number],
input[type=search], input[type=date], input[type=datetime-local], input[type=color], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
input[type=color] { padding: 4px; width: 72px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.checkbox { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; }
.checkbox input { width: 22px; height: 22px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--danger); font-size: 0.9rem; }
.field-error input, .field-error select, .field-error textarea { border-color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .span-2 { grid-column: span 2; }
.search-bar { position: sticky; top: 57px; z-index: 10; background: var(--bg); padding: 4px 0 12px; }

/* Choice pills (radio groups rendered as big tap targets) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; margin: 0;
  border: 1px solid var(--border); border-radius: 999px; background: #fff; font-weight: 600; cursor: pointer;
}
.pills input:checked + label { background: var(--brand); border-color: var(--brand); color: #fff; }
.pills input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700; line-height: 1.6; white-space: nowrap; background: #eef1f5; color: var(--text);
}
.chip-urgent { background: #fbe4e1; color: var(--urgent); }
.chip-repair_soon { background: #fdf0dc; color: #9a5d00; }
.chip-monitor { background: #e3edf8; color: var(--monitor); }
.chip-info { background: #eef1f5; color: var(--muted); }
.chip-cond-excellent { background: #dcf1e5; color: var(--ok); }
.chip-cond-good { background: #e6f4ea; color: var(--ok); }
.chip-cond-fair { background: #fdf0dc; color: #9a5d00; }
.chip-cond-poor { background: #fbe4e1; color: var(--danger); }
.chip-cond-replace { background: var(--danger); color: #fff; }
.chip-status-scheduled { background: #e3edf8; color: var(--info); }
.chip-status-draft { background: #fdf0dc; color: #9a5d00; }
.chip-status-finalized { background: #dcf1e5; color: var(--ok); }

/* Messages */
.messages { margin-bottom: 12px; }
.msg { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 8px; background: #e3edf8; color: var(--text); }
.msg-success { background: #dcf1e5; }
.msg-error { background: #fbe4e1; }
.msg-warning { background: #fdf0dc; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); transform: translateX(-50%); z-index: 50;
  background: #1b2430; color: #fff; padding: 10px 16px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow);
}

/* Save indicator for autosave forms */
.saved-indicator { font-size: 0.85rem; color: var(--ok); opacity: 0; transition: opacity 0.2s; }
.saved-indicator.show { opacity: 1; }
.htmx-request .saving-indicator { display: inline; }
.saving-indicator { display: none; font-size: 0.85rem; color: var(--muted); }

/* Key-value lists */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; max-width: 128px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--brand); }

/* Auth pages */
.auth-card { max-width: 420px; margin: 32px auto; }
.auth-card h1 { text-align: center; }

@media (min-width: 700px) {
  .page { padding: 24px 16px; }
}
