/* CasaHub theme — teal palette inspired by the solarium gateway. */

:root {
  --color-primary: #7ccdcb;
  --color-primary-dark: #3f9294;
  --color-primary-deep: #2a5f61;
  --color-primary-soft: #e4f6f5;
  --color-background: #f2fbfa;
  --color-surface: #ffffff;
  --color-surface-2: #f7fcfc;
  --color-text: #183336;
  --color-muted: #5f7d7e;
  --color-border: #c5e6e5;
  --color-shadow: rgba(24, 51, 54, 0.12);
  --color-busy: #f3d9d4;
  --color-busy-text: #8a3d30;
  --color-accent: #ff5a5f;
  --color-accent-soft: #ffe8e8;

  --ok-bg: #dff4f3;   --ok-fg: #115e59;
  --warn-bg: #fff3d6; --warn-fg: #8a5a00;
  --bad-bg: #ffe8e8;  --bad-fg: #b3262b;
  --off-bg: #eef2f2;  --off-fg: #5f7d7e;
  --info-bg: #e0f2fe; --info-fg: #1d4ed8;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 4px 16px var(--color-shadow);
  --shadow-sm: 0 1px 3px var(--color-shadow);
  --shadow-lg: 0 12px 40px rgba(24, 51, 54, 0.22);
  --sidebar: 240px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

/* Dark theme: data-theme is set in <head> (partials/theme_head.html). */
:root[data-theme="dark"] {
  --color-primary: #7ccdcb;
  --color-primary-dark: #7ccdcb;
  --color-primary-deep: #a3dbd9;
  --color-primary-soft: rgba(124, 205, 203, 0.14);
  --color-background: #0f2224;
  --color-surface: #183336;
  --color-surface-2: #1d3b3e;
  --color-text: #e4f6f5;
  --color-muted: #9bb9ba;
  --color-border: #2a4a4d;
  --color-shadow: rgba(0, 0, 0, 0.35);
  --color-busy: rgba(243, 217, 212, 0.16);
  --color-busy-text: #f3b8ac;
  --color-accent-soft: rgba(255, 90, 95, 0.16);
  --ok-bg: rgba(124, 205, 203, 0.16); --ok-fg: #a3dbd9;
  --warn-bg: rgba(255, 200, 80, 0.14); --warn-fg: #fcd34d;
  --bad-bg: rgba(255, 90, 95, 0.16);  --bad-fg: #fca5a5;
  --off-bg: rgba(155, 185, 186, 0.12); --off-fg: #9bb9ba;
  --info-bg: rgba(96, 165, 250, 0.14); --info-fg: #93c5fd;
  color-scheme: dark;
}
:root[data-theme="dark"] .btn.primary { color: #0f2224; }
:root[data-theme="dark"] .brand-mark { color: #0f2224; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-background);
}
a { color: var(--color-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }
p { margin: 0 0 0.75rem; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
[x-cloak] { display: none !important; }

.icon {
  font-family: "Material Symbols Rounded";
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 450, "GRAD" 0, "opsz" 24;
  vertical-align: middle;
}
.icon.fill { font-variation-settings: "FILL" 1, "wght" 450, "GRAD" 0, "opsz" 24; }
.icon.sm { font-size: 17px; }
.icon.lg { font-size: 28px; }

/* --- layout --------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 18px;
  font-weight: 750; font-size: 1.1rem; color: var(--color-text);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--color-primary-dark); color: #fff;
  box-shadow: 0 4px 24px var(--color-shadow);
}
.brand-mark .logo-mark { width: 26px; height: 26px; }
.wordmark { letter-spacing: -0.01em; }
.wordmark > span { color: var(--color-primary-dark); }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-weight: 550;
}
.nav-link:hover { background: var(--color-primary-soft); color: var(--color-text); text-decoration: none; }
.nav-link.active { background: var(--color-primary-soft); color: var(--color-primary-dark); box-shadow: inset 3px 0 0 var(--color-primary-dark); }
.nav-link .count {
  margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--color-accent); color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-section {
  padding: 6px 12px 4px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--color-muted); opacity: 0.8;
}
.nav-link .external { margin-left: auto; font-size: 15px; opacity: 0.55; }
.sidebar .spacer { flex: 1; }
.nav-footer { border-top: 1px solid var(--color-border); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-link.user { cursor: default; }
.nav-link.user:hover { background: none; color: var(--color-muted); }
.sidebar form { margin: 0; }
.sidebar .nav-link.button { width: 100%; background: none; border: 0; cursor: pointer; font: inherit; }
.sidebar { overflow-y: auto; }

/* Top bar: back link on detail pages; on phones also the brand, sticky. */
.topbar:empty { display: none; }
.topbar { margin-bottom: 6px; }
.topbar-brand { display: none; }
.back {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--color-muted); font-size: 0.88rem; font-weight: 600;
  padding: 4px 8px 4px 4px; margin-left: -4px; border-radius: var(--radius-sm);
}
.back .icon { font-size: 18px; }
.back:hover { color: var(--color-text); background: var(--color-primary-soft); text-decoration: none; }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 22px;
}
@media (max-width: 640px) { .page-head { margin-bottom: 16px; } }
.page-head .subtitle { color: var(--color-muted); margin-top: 4px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 30px 0 12px; }
.main > .section-title:first-child { margin-top: 0; }
/* Vertical rhythm between the blocks of a page. */
:is(.main, .main > [x-data]) > :is(.card, .grid, .layout-aside) + :is(.card, .grid, .layout-aside) { margin-top: 18px; }

.bottom-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.35rem; }
  .topbar, .topbar:empty {
    display: flex; align-items: center; min-height: 52px;
    position: sticky; top: 0; z-index: 20;
    margin: 0 -16px 14px; padding: env(safe-area-inset-top) 12px 0;
    background: color-mix(in srgb, var(--color-background) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--color-border);
  }
  .topbar-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.05rem; color: var(--color-text); }
  .topbar-brand:hover { text-decoration: none; }
  .topbar-brand .brand-mark { width: 30px; height: 30px; border-radius: 9px; box-shadow: none; }
  .topbar-brand .brand-mark .logo-mark { width: 22px; height: 22px; }
  .back { font-size: 1rem; color: var(--color-text); padding: 8px 10px 8px 4px; }
  .back .icon { font-size: 22px; color: var(--color-primary-dark); }
  .bottom-nav {
    display: flex; justify-content: space-around;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--color-border);
    padding: 4px 2px env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    flex: 1; min-width: 0; min-height: 52px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 0.66rem; font-weight: 600; color: var(--color-muted); position: relative;
  }
  .bottom-nav a > span:not(.icon):not(.dot) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav a .icon { width: 52px; height: 28px; display: grid; place-items: center; border-radius: 999px; transition: background .15s; }
  .bottom-nav a.active { color: var(--color-primary-dark); }
  .bottom-nav a.active .icon { background: var(--color-primary-soft); font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav .dot {
    position: absolute; top: 2px; left: calc(50% + 6px);
    min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
    background: var(--color-accent); color: #fff; font-size: 0.62rem; font-weight: 700; line-height: 17px; text-align: center;
    box-shadow: 0 0 0 2px var(--color-surface);
  }
}

/* --- cards & grids ---------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-link { color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
.card-link:hover { text-decoration: none; border-color: var(--color-primary); box-shadow: var(--shadow); }
.card-sub { margin-bottom: 12px; }
.card-foot { display: inline-flex; align-items: center; gap: 4px; margin-top: 10px; font-size: 0.85rem; font-weight: 600; }
.faded { opacity: 0.6; }
.emoji { font-size: 1.5rem; line-height: 1; }
.grid > .card, .grid > .kpi { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head.tight { margin-bottom: 8px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head .icon { color: var(--color-primary-dark); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 18px 20px 4px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cards-grid { grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); }
.stack > * + * { margin-top: 18px; }
.stack > input[type=hidden] + * { margin-top: 0; }
.layout-aside { display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
@media (max-width: 900px) {
  .layout-aside { grid-template-columns: minmax(0, 1fr); }
  .save-bar { bottom: calc(68px + env(safe-area-inset-bottom)); }
}
@media (max-width: 640px) {
  .save-bar > span { display: none; }
  .save-bar .actions { width: 100%; }
  .save-bar .actions .btn { flex: 1; }
}

.kpi {
  display: flex; align-items: center; gap: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  color: var(--color-text);
}
a.kpi:hover { text-decoration: none; border-color: var(--color-primary); }
.kpi .bubble {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: var(--color-primary-soft); color: var(--color-primary-dark); flex-shrink: 0;
}
.kpi.alert .bubble { background: var(--color-accent-soft); color: var(--color-accent); }
.kpi .value { font-size: 1.6rem; font-weight: 750; line-height: 1.1; }
.kpi .label { color: var(--color-muted); font-size: 0.85rem; }

/* --- tables & lists --------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-muted); font-weight: 650; padding: 10px 14px;
  border-bottom: 1px solid var(--color-border); white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--color-surface-2); }
tr.clickable { cursor: pointer; position: relative; }
tr.clickable .row-main { color: inherit; }
tr.clickable .row-main::after { content: ""; position: absolute; inset: 0; }
tr.clickable .row-main:focus-visible { outline: none; }
tr.clickable:has(.row-main:focus-visible) { box-shadow: inset 0 0 0 2px var(--color-primary-dark); }
table.compact { margin-top: 12px; }
table.compact td, table.compact th { padding: 8px 10px; }

/* On phones a table.cards shows each row as a small card. The first cell
   (class "title") is the heading; the others are "label: value" lines. */
@media (max-width: 640px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--color-border);
  }
  table.cards tr:last-child { border-bottom: 0; }
  table.cards td { display: block; padding: 0; border: 0; text-align: left; }
  table.cards td.title { order: 0; flex: 1 1 55%; font-size: 1rem; margin-bottom: 6px; }
  table.cards td.status { order: 1; margin-left: auto; margin-bottom: 6px; }
  table.cards td[data-label] {
    order: 2; flex: 1 1 calc(50% - 12px); min-width: 0;
    display: flex; flex-direction: column; align-items: flex-start; padding: 4px 0; font-size: 0.9rem;
  }
  table.cards td[data-label]::before {
    content: attr(data-label); color: var(--color-muted);
    font-size: 0.7rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
  }
}
.num { text-align: right; font-variant-numeric: tabular-nums; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows > li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--color-border);
}
.rows > li:last-child { border-bottom: 0; }
.rows .grow { flex: 1; min-width: 0; }
.rows .meta { color: var(--color-muted); font-size: 0.85rem; }
.row-link { display: flex; align-items: center; gap: 12px; color: inherit; flex: 1; min-width: 0; }
.row-link:hover { text-decoration: none; }
.rows > li:has(.row-link) { padding: 0; }
.rows > li .row-link { padding: 12px 8px; margin: 0 -8px; border-radius: var(--radius-sm); transition: background .12s; }
.rows > li :is(a, button).row-link:hover { background: var(--color-surface-2); text-decoration: none; }
.rows > li > form { flex: 1; margin: 0; }
.row-button { width: calc(100% + 16px); border: 0; background: none; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.row-link .chev { color: var(--color-muted); opacity: 0.6; }
.row-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; background: var(--color-primary-soft); color: var(--color-primary-dark); }
.row-icon.bad { background: var(--bad-bg); color: var(--bad-fg); }
.row-icon.warn { background: var(--warn-bg); color: var(--warn-fg); }
.list-card { padding: 6px 20px; }
.progress-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 0.85rem; color: var(--color-muted); }
.progress-row .progress { width: 140px; }

.empty {
  text-align: center; color: var(--color-muted); padding: 26px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.empty .icon { font-size: 36px; color: var(--color-primary); }

/* --- badges & chips ------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 650; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.off { background: var(--off-bg); color: var(--off-fg); }
.badge.info { background: var(--info-bg); color: var(--info-fg); }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 8px;
  background: var(--color-primary-soft); color: var(--color-primary-deep);
  font-size: 0.78rem; font-weight: 600;
}
.chip.coral { background: var(--color-accent-soft); color: var(--color-accent); }
.house-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.warning-text { color: var(--color-busy-text); font-size: 0.85rem; display: inline-flex; gap: 4px; align-items: center; }
.muted { color: var(--color-muted); }
.small { font-size: 0.85rem; }

.progress { height: 8px; border-radius: 999px; background: var(--color-primary-soft); overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--color-primary); border-radius: inherit; }

/* --- buttons & forms -------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--color-primary-soft); border-color: var(--color-primary); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; box-shadow: inset 0 0 0 2px var(--color-primary-dark);
}
.btn.primary { background: var(--color-primary-dark); border-color: var(--color-primary-dark); color: #fff; }
.btn.primary:hover { background: var(--color-primary-deep); }
.btn.danger { color: var(--bad-fg); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-fg); }
.btn.primary.danger { background: var(--bad-fg); border-color: var(--bad-fg); color: #fff; }
.btn.primary.danger:hover { background: var(--bad-fg); filter: brightness(0.9); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--color-primary-soft); }
.btn.sm { padding: 5px 10px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn.icon-only { padding: 6px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.end { justify-content: flex-end; }

/* Toolbar with filters, and a segmented control (radios or buttons). */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar select { width: auto; min-width: 170px; padding-top: 8px; padding-bottom: 8px; }
.toolbar .segmented { margin-right: auto; }
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; max-width: 100%; overflow-x: auto;
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius);
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented > button, .segmented > label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  padding: 6px 12px; border: 0; border-radius: var(--radius-sm); background: none;
  font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--color-muted);
  cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.segmented > label input { position: absolute; opacity: 0; pointer-events: none; }
.segmented > button:hover, .segmented > label:hover { color: var(--color-text); }
.segmented > button.active, .segmented > label:has(input:checked) {
  background: var(--color-surface); color: var(--color-primary-dark); box-shadow: var(--shadow-sm);
}
.segmented > label:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--color-primary-dark); }
.toggle {
  display: inline-flex; align-items: center; gap: 8px; margin: 0; cursor: pointer;
  font-size: 0.88rem; font-weight: 600; color: var(--color-text);
}
.toggle input {
  appearance: none; -webkit-appearance: none; width: 36px; height: 20px; margin: 0;
  border-radius: 999px; background: var(--color-border); position: relative; cursor: pointer; transition: background .15s;
}
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s;
}
.toggle input:checked { background: var(--color-primary-dark); }
.toggle input:checked::after { transform: translateX(16px); }
@media (max-width: 640px) {
  .toolbar .segmented { margin-right: 0; width: 100%; }
  .toolbar select { flex: 1; min-width: 0; }
}
.head-actions > form { display: contents; }
.head-actions { justify-content: flex-end; }
.head-actions > .btn, .head-actions > form .btn, .head-actions .menu-toggle { height: 40px; }
.head-actions .menu-toggle { width: 40px; }

/* dropdown menu (⋮) */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 260px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px;
}
.menu form { margin: 0; }
.menu-item {
  display: flex; gap: 10px; align-items: flex-start; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--color-text); font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--color-primary-soft); outline: none; }
.menu-item .icon { color: var(--color-primary-dark); margin-top: 1px; }
.menu-item small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--color-muted); margin-top: 1px; }
.menu-item:hover { text-decoration: none; }
.menu-item.danger, .menu-item.danger .icon { color: var(--bad-fg); }
.menu-item.danger:hover { background: var(--bad-bg); }
.modal.narrow { width: min(420px, 100%); }
@media (max-width: 640px) {
  .head-actions { width: 100%; justify-content: flex-start; }
  .head-actions .menu-wrap { margin-left: auto; }
  .page-head > .actions:not(.head-actions) { width: 100%; }
  .page-head > .actions:not(.head-actions) > .btn.primary:only-child { flex: 1; }
}

label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--color-muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
input[type=date], input[type=time], input[type=month], select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text);
  font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--color-primary-dark); vertical-align: middle; }
.field { margin-bottom: 14px; }
.field .help { color: var(--color-muted); font-size: 0.8rem; margin-top: 4px; }
.field .error { color: var(--bad-fg); font-size: 0.8rem; margin-top: 4px; }
.fields { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(min(136px, 100%), 1fr)); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin: 0; flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 550; color: var(--color-text); }

.stepper { display: flex; align-items: center; border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; background: var(--color-surface); }
.stepper button { border: 0; background: var(--color-primary-soft); color: var(--color-primary-dark); width: 38px; align-self: stretch; cursor: pointer; font-size: 1.1rem; font-weight: 700; }
.stepper input { border: 0; text-align: center; border-radius: 0; padding: 10px 4px; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* --- tabs ------------------------------------------------------------------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 18px; overflow-x: auto; }
.tabs button, .tabs a {
  border: 0; background: none; font: inherit; font-weight: 600; color: var(--color-muted);
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
  display: inline-flex; gap: 6px; align-items: center;
}
.tabs button:hover, .tabs a:hover { color: var(--color-text); text-decoration: none; }
.tabs .active { color: var(--color-primary-dark); border-bottom-color: var(--color-primary-dark); }

/* --- sortable task lists ---------------------------------------------------- */

.task-list { list-style: none; margin: 0; padding: 0; }
.task-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
}
.task-list .handle { cursor: grab; color: var(--color-muted); }
.task-list .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.task-list .text .chip { margin-left: 6px; }
.task-list .edit-row { display: flex; flex-wrap: wrap; gap: 6px; }
.task-list .edit-row input { flex: 1 1 200px; }
.task-list .edit-row select { flex: 0 1 170px; }
.grid.lists { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
@media (max-width: 640px) { .grid.lists { grid-template-columns: 1fr; } }
.list-title { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.add-row { margin-top: 8px; }
.save-bar {
  position: sticky; bottom: 12px; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--color-border); box-shadow: var(--shadow);
}
.task-list .template { color: var(--color-muted); font-size: 0.8rem; font-family: var(--mono); }
.task-list .sortable-ghost { opacity: 0.4; }
.task-list li.done .text { text-decoration: line-through; color: var(--color-muted); }

/* --- notices, modal, drawer, toast ----------------------------------------- */

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--color-primary-soft); color: var(--color-primary-deep); margin-bottom: 16px;
}
.notice.warn { background: var(--warn-bg); color: var(--warn-fg); }
.notice.bad { background: var(--bad-bg); color: var(--bad-fg); }

.overlay { position: fixed; inset: 0; background: rgba(15, 34, 36, 0.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal {
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 22px;
}
dialog.modal { border: 0; color: inherit; }
dialog.modal::backdrop { background: rgba(15, 34, 36, 0.45); }
dialog.modal p { margin: 0 0 18px; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(440px, 100%);
  background: var(--color-surface); box-shadow: var(--shadow-lg); padding: 22px; overflow-y: auto;
  border-left: 1px solid var(--color-border);
}
.toasts { position: fixed; top: 16px; right: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  background: var(--color-text); color: var(--color-surface); font-weight: 550;
}

.info-panel { background: var(--color-surface-2); border: 1px dashed var(--color-border); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }
.info-panel table td, .info-panel table th { padding: 5px 8px; }
.info-panel code { background: var(--color-primary-soft); color: var(--color-primary-deep); padding: 1px 6px; border-radius: 6px; cursor: pointer; }

.telegram-preview {
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: 14px 14px 14px 4px;
  padding: 12px 14px; white-space: pre-wrap; font-size: 0.92rem;
}

/* --- calendar grid ---------------------------------------------------------- */

.fc { --fc-border-color: var(--color-border); --fc-today-bg-color: var(--color-primary-soft); --fc-page-bg-color: var(--color-surface); --fc-neutral-bg-color: var(--color-surface-2); }
.fc .fc-button-primary { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.fc .fc-button-primary:not(:disabled).fc-button-active, .fc .fc-button-primary:hover { background: var(--color-primary-deep); border-color: var(--color-primary-deep); }
.fc .fc-toolbar-title { font-size: 1.15rem; text-transform: capitalize; }
.fc-event { cursor: pointer; border-radius: 6px; padding: 1px 4px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 0.85rem; color: var(--color-muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.house-dot.outline { border: 2px solid var(--color-primary-dark); }
/* The global table styles must not leak into FullCalendar's own tables. */
.fc th, .fc td { padding: 0; }
.fc .fc-col-header-cell { padding: 6px 0; }
.fc tbody tr:hover { background: none; }
.fc .fc-toolbar.fc-header-toolbar { margin-bottom: 14px; gap: 8px; }
.fc .fc-button { border-radius: var(--radius-sm); font-weight: 600; text-transform: none; }
.fc .fc-list-day-cushion { background: var(--color-surface-2); }
.fc .fc-toolbar-chunk { display: flex; align-items: center; gap: 6px; }
.fc .fc-toolbar-title { white-space: nowrap; }
.fc .fc-list-event-time { display: none; }
@media (max-width: 640px) {
  .fc .fc-toolbar-title { font-size: 1rem; }
  .fc .fc-button { padding: 0.35em 0.6em; }
}

/* --- login ------------------------------------------------------------------ */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, var(--color-primary-soft), transparent 50%), var(--color-background); }
.login-card { width: min(400px, 100%); }
.login-card .brand { justify-content: center; font-size: 1.4rem; padding-bottom: 6px; }

.issue-card { margin: 0; }
.issue-photo { width: 100%; max-height: 200px; object-fit: cover; border-radius: var(--radius); margin-bottom: 10px; }
.issue-resolve { margin-top: 12px; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--color-border); }
.photos figcaption { font-size: 0.75rem; color: var(--color-muted); margin-top: 4px; }

.htmx-request.btn { opacity: 0.6; }
.hide-mobile { }
@media (max-width: 640px) { .hide-mobile { display: none; } .grid.two { grid-template-columns: 1fr; } }

@media (max-width: 640px) {
  .grid.kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px; gap: 10px; }
  .kpi .bubble { width: 38px; height: 38px; border-radius: 12px; }
  .kpi .value { font-size: 1.3rem; }
  .card { padding: 16px; }
  .card.flush { padding: 0; }
  .card.flush .card-head { padding: 16px 16px 4px; }
  .list-card { padding: 4px 16px; }
}

/* --- dashboard: week agenda ------------------------------------------------- */

.dashboard > .todo { margin-top: 0; }
@media (min-width: 901px) {
  /* "A fazer" stays in view while the week scrolls. */
  .dashboard > .todo { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.todo-jump { display: inline-block; margin-top: 6px; font-weight: 600; }
@media (min-width: 901px) { .todo-jump { display: none; } }
.todo-status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
:is(#a-fazer, .day) { scroll-margin-top: 72px; }

.week-agenda .card-head .meta { color: var(--color-muted); font-size: 0.85rem; margin-top: 2px; }
.week-nav { flex-wrap: nowrap; gap: 6px; }
.week-agenda > .notice { margin-bottom: 12px; color: var(--warn-fg); }
.week-agenda > .notice:hover { text-decoration: none; filter: brightness(0.98); }

.week-strip { list-style: none; margin: 0 0 6px; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.week-strip a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 2px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface-2); color: var(--color-text); font-size: 0.78rem; line-height: 1.2; text-align: center;
}
.week-strip a:hover { text-decoration: none; border-color: var(--color-primary); }
.week-strip a.today { border-color: var(--color-primary-dark); box-shadow: inset 0 0 0 1px var(--color-primary-dark); }
.week-strip a.quiet { color: var(--color-muted); }
.strip-weekday { font-size: 0.72rem; color: var(--color-muted); }
.strip-day { font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.strip-counts { display: flex; gap: 6px; font-weight: 600; color: var(--color-primary-dark); font-variant-numeric: tabular-nums; }
.quiet .strip-counts { color: var(--color-muted); }
.strip-dot { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn-fg); }
@media (max-width: 640px) {
  .week-strip { gap: 4px; }
  .week-strip a { font-size: 0.7rem; padding: 6px 0; }
  .strip-counts { gap: 3px; }
}

.day { padding: 14px 0 4px; border-top: 1px solid var(--color-border); margin-top: 12px; }
.day:first-child { margin-top: 10px; }
.day-head { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; font-weight: 700; margin: 0 0 8px; }
.day-tag {
  text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.7rem; font-weight: 750;
  padding: 2px 8px; border-radius: 999px; background: var(--color-primary-soft); color: var(--color-primary-deep);
}
.day.today .day-tag { background: var(--color-primary-dark); color: var(--color-surface); }

.moves { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.move {
  border: 1px solid var(--color-border); border-left: 4px solid var(--house, var(--color-primary));
  border-radius: var(--radius-sm); padding: 8px 10px 8px 12px; background: var(--color-surface);
}
.move.pending { border-style: dashed; border-left-style: solid; background: var(--color-surface-2); }
.move-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 0.92rem; }
.move-kind { font-weight: 650; color: var(--color-muted); }
.move-line {
  display: flex; align-items: center; gap: 8px; color: inherit; font-size: 0.88rem;
  margin: 2px -6px 0; padding: 4px 6px; border-radius: 8px;
}
.move-line:hover { background: var(--color-surface-2); text-decoration: none; }
.move-line .grow { flex: 1; min-width: 0; }
.move-line .when { font-weight: 650; font-variant-numeric: tabular-nums; }
.move-line .chev { color: var(--color-muted); opacity: 0.6; }
.move-line .badge { font-size: 0.7rem; padding: 2px 8px; }
.detail-line, .list-status { display: block; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-status { color: var(--color-muted); margin-top: 1px; }
.progress.thin { display: inline-block; vertical-align: middle; height: 4px; width: 56px; min-width: 0; }
.tone-ok { color: var(--ok-fg); }
.tone-warn { color: var(--warn-fg); }
.tone-bad { color: var(--bad-fg); }
.tone-info { color: var(--info-fg); }
.tone-off { color: var(--off-fg); }
.flags { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; }
.flag { font-size: 0.76rem; font-weight: 600; padding: 2px 8px; border-radius: 8px; }
.flag a { color: inherit; }
.flag.tone-ok { background: var(--ok-bg); }
.flag.tone-warn { background: var(--warn-bg); }
.flag.tone-bad { background: var(--bad-bg); }
.staying { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--color-muted); font-size: 0.82rem; margin-top: 8px; }
.day-head + .staying { margin-top: 0; }
.stay { display: inline-flex; align-items: center; gap: 3px; }

/* --- dashboard: houses today ------------------------------------------------ */

/* Attention first: rows only for houses needing action, pills for the calm ones,
   so the card grows with the work and not with the number of houses. */
.houses-summary { display: flex; flex-wrap: wrap; gap: 6px; }
/* The rows share their columns (subgrid), so chips and details line up. */
.house-rows {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 6px 12px;
  grid-template-columns: minmax(0, max-content) max-content minmax(0, 1fr) auto;
}
.house-rows > li { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }
.house-row {
  grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: center; gap: 4px 12px;
  border: 1px solid var(--color-border); border-left: 4px solid var(--house, var(--color-primary));
  border-radius: var(--radius-sm); padding: 7px 8px 7px 12px; background: var(--color-surface); color: var(--color-text);
}
.house-row:hover { text-decoration: none; background: var(--color-surface-2); }
.house-row.tone-bad { border-color: var(--bad-fg); border-left-color: var(--house, var(--bad-fg)); background: var(--bad-bg); }
.house-row.tone-bad:hover { filter: brightness(0.98); }
.row-name { font-weight: 650; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-detail { font-size: 0.82rem; color: var(--color-muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.house-row.tone-bad .row-detail { color: var(--bad-fg); }
.house-row .chev { color: var(--color-muted); opacity: 0.6; }
.state-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; font-weight: 650; white-space: nowrap;
  padding: 2px 9px 2px 6px; border-radius: 999px; justify-self: start;
}
.state-chip .icon { font-size: 16px; }
.state-chip.ok { background: var(--ok-bg); color: var(--ok-fg); }
.state-chip.warn { background: var(--warn-bg); color: var(--warn-fg); }
.state-chip.bad { background: var(--bad-fg); color: var(--color-surface); }
.state-chip.info { background: var(--info-bg); color: var(--info-fg); }
.state-chip.off { background: var(--off-bg); color: var(--off-fg); }
.all-clear { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.9rem; }

.calm-groups { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; }
.house-rows + .calm-groups, .all-clear + .calm-groups { padding-top: 10px; border-top: 1px dashed var(--color-border); }
.calm-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.calm-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
.house-pill {
  position: relative; display: inline-flex; align-items: center; gap: 5px; font-size: 0.8rem; font-weight: 600;
  padding: 3px 10px 3px 7px; border-radius: 999px; border: 1px solid var(--color-border);
  background: var(--color-surface-2); color: var(--color-text); white-space: nowrap;
}
.house-pill:hover { text-decoration: none; border-color: var(--color-primary); }
.house-pill .house-dot { width: 8px; height: 8px; }
.house-pill.flagged::after { content: ""; position: absolute; top: -2px; right: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn-fg); }

.all-houses { margin-top: 10px; }
.all-houses > summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--color-primary-dark); width: fit-content; }
.all-houses[open] > summary { margin-bottom: 8px; }

@media (max-width: 640px) {
  /* Name on the first line; chip and detail flow on the second. */
  .house-rows { grid-template-columns: minmax(0, 1fr); }
  .house-rows > li { display: block; grid-column: auto; }
  .house-row { display: block; position: relative; padding-right: 30px; }
  .house-row .row-name { display: block; margin-bottom: 4px; }
  .house-row .state-chip { display: inline-flex; vertical-align: middle; margin-right: 6px; }
  .house-row .row-detail { display: inline; white-space: normal; vertical-align: middle; }
  .house-row .chev { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
  .calm-groups { gap: 8px 14px; }
}
