:root {
  --bg: #FAF8F5;
  --card: #FFFFFF;
  --text: #2A2724;
  --muted: #8A817A;
  --line: #ECE6DF;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(42, 39, 36, .04), 0 6px 18px rgba(42, 39, 36, .06);
  --accent: #B5653A;

  --ok-fg: #2F6B4A; --ok-bg: #E8F2EC;
  --soon-fg: #8A6300; --soon-bg: #FBF1D7;
  --over-fg: #B23A2E; --over-bg: #FBE7E4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(250, 248, 245, .85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.topbar h1 .house { margin-right: 6px; }
.topbar h1 .thin { color: var(--muted); font-weight: 500; }
.sync { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.refresh {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 32px; height: 32px; border-radius: 10px; cursor: pointer; font-size: 16px;
  transition: transform .2s, background .2s;
}
.refresh:hover { background: #fff; transform: rotate(90deg); }
.refresh.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Banner (demo / errors) */
.banner {
  margin: 16px 0 0; padding: 12px 16px; border-radius: 14px;
  background: var(--soon-bg); color: var(--soon-fg); font-size: 14px;
  border: 1px solid rgba(138, 99, 0, .15);
}
.banner.error { background: var(--over-bg); color: var(--over-fg); }

/* Sections */
.section { margin-top: 22px; }
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head .section-title { margin: 0; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-top: 22px; overflow-x: auto; padding-bottom: 2px; }
.tab {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 550;
  white-space: nowrap; transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; border: 1px solid var(--line);
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

/* Alerts */
.alerts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.alert {
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.alert.over { background: var(--over-bg); border-color: rgba(178, 58, 46, .2); }
.alert.soon { background: var(--soon-bg); border-color: rgba(138, 99, 0, .2); }
.alert .a-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.alert .a-name { font-weight: 650; }
.alert .a-when { font-size: 12px; font-weight: 650; white-space: nowrap; }
.alert.over .a-when { color: var(--over-fg); }
.alert.soon .a-when { color: var(--soon-fg); }
.alert .a-sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.alert .a-contact { margin-top: 8px; font-size: 14px; }

/* Schedule */
.cat-group { margin-bottom: 18px; }
.cat-head { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 650; }
.cat-head .cat-icon { font-size: 18px; }
.cat-head .cat-count { color: var(--muted); font-weight: 500; font-size: 13px; }
.maint-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.maint .m-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.maint .m-name { font-weight: 600; }
.maint .m-meta { color: var(--muted); font-size: 13px; margin-top: 8px; display: grid; gap: 3px; }
.maint .m-meta b { color: var(--text); font-weight: 600; }
.maint .m-contact { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; }

/* Badges */
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.due_soon { background: var(--soon-bg); color: var(--soon-fg); }
.badge.overdue { background: var(--over-bg); color: var(--over-fg); }

/* Links */
a.telmail { color: var(--accent); text-decoration: none; font-weight: 600; }
a.telmail:hover { text-decoration: underline; }
.specialty-tag { display: inline-block; background: #F3EEE8; color: var(--muted); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; margin-bottom: 8px; }

/* Contractor card */
.contractor .c-name { font-weight: 650; font-size: 16px; }
.contractor .c-row { font-size: 14px; margin-top: 6px; color: var(--text); }
.contractor .c-row .lbl { color: var(--muted); width: 64px; display: inline-block; }

/* Insurance */
.ins .i-type { font-weight: 700; font-size: 16px; }
.ins .i-co { color: var(--muted); margin-bottom: 8px; }
.ins .i-row { font-size: 14px; display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.ins .i-row .lbl { color: var(--muted); }
.ins .i-premium { font-weight: 700; font-size: 18px; margin-top: 8px; }
.broker { margin-top: 14px; }
.broker .card { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.broker .b-name { font-weight: 650; }

/* Costs */
.cost-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.cost-totals .card { text-align: center; }
.cost-totals .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.cost-totals .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }
.chart { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 12px; font-size: 14px; }
.bar-track { background: #F1EBE3; border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #D89B6B); border-radius: 999px; }
.bar-val { color: var(--muted); font-variant-numeric: tabular-nums; }

.hist-cost { font-weight: 700; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hist-total { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

.empty { color: var(--muted); padding: 20px 0; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 30px; }

@media (max-width: 560px) {
  .topbar h1 { font-size: 17px; }
  .topbar h1 .thin { display: none; }
  .bar-row { grid-template-columns: 88px 1fr auto; }
}
