:root {
  --bg: #eef1f6; --panel: #ffffff; --panel2: #f3f5f9; --ink: #1f2937;
  --muted: #6b7280; --accent: #2563eb; --accent2: #7c3aed; --line: #e4e8ef;
  --good: #059669; --warn: #b45309;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 6px 18px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); min-height: 100dvh; background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
/* Background image (drop bg.jpg into /app/) softened by a light wash so content stays readable.
   Falls back to a clean light gradient when no image is present. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(rgba(238,241,246,.86), rgba(238,241,246,.92)),
    url("/app/bg.jpg") center / cover no-repeat fixed,
    linear-gradient(160deg, #eaf0fb 0%, #eef1f6 60%);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  background: rgba(255,255,255,.82); backdrop-filter: blur(10px);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand .dot {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.who { color: var(--muted); font-size: .85rem; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }

.hero {
  display: flex; flex-direction: column; gap: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 26px; margin-bottom: 26px; box-shadow: var(--shadow);
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.hero-main { min-width: 0; }
.hero h1 { margin: 0 0 6px; font-size: 1.7rem; letter-spacing: -.02em; }
.hero .sub { color: var(--muted); }

/* Static welcome photo (house + flag) */
.welcome-photo {
  flex: none; width: 208px; height: 128px; border-radius: 14px; overflow: hidden;
  background: var(--panel2); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.welcome-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Bottom row of the hero: weather cards on the left, emergency button pinned
   right (sits directly under the welcome photo, just past South San Francisco). */
.hero-bottom {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 28px;
  border-top: 1px solid var(--line); padding-top: 18px;
}
.hero-emergency { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

/* Two location cards: name + weather + time, generously spaced */
.locations {
  display: flex; flex-wrap: wrap; gap: 44px;
  flex: 1 1 auto; min-width: 0;
}
.loc { display: flex; flex-direction: column; gap: 3px; }
.loc-name { font-weight: 600; font-size: .95rem; }
.loc-wx { display: flex; align-items: baseline; gap: 8px; }
.loc-temp { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.loc-desc { color: var(--muted); font-size: .85rem; }
.loc-time { color: var(--muted); font-size: .85rem; }
.loc-time b { color: var(--ink); font-weight: 600; }
.weather { text-align: right; min-width: 190px; }
.wx-temp { font-size: 2.4rem; font-weight: 700; line-height: 1; }
.wx-desc { color: var(--muted); margin-top: 4px; }
.wx-meta { color: var(--muted); font-size: .8rem; margin-top: 6px; }
.wx-load { color: var(--muted); font-size: .9rem; }
.wx-err { color: var(--warn); font-size: .85rem; padding: 12px; }

.zone-head { display: flex; align-items: baseline; gap: 12px; margin: 30px 4px 14px; }
.zone-head h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.01em; }
.zone-note { color: var(--muted); font-size: .78rem; }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; box-shadow: var(--shadow);
}
.panel.wide { margin-top: 16px; }
.panel-head {
  display: flex; align-items: center; gap: 9px; font-weight: 600;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fbfcfe;
}
.p-ico { font-size: 18px; }
.panel-body { padding: 8px; max-height: 340px; overflow-y: auto; }

.row {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  padding: 10px 12px; border-radius: 10px;
}
.row:hover { background: var(--panel2); }
.r-ico { font-size: 18px; }
.r-name { font-size: .92rem; }
.muted { color: var(--muted); font-size: .88rem; padding: 14px; }

/* Quick-link tiles (Personal zone) */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.tile {
  display: flex; flex-direction: column; gap: 10px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px; color: var(--ink); min-height: 116px; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .ico { font-size: 26px; }
.tile .t-name { font-weight: 600; }
.tile .t-sub { color: var(--muted); font-size: .8rem; }

/* Photo galleries */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 8px 12px 4px; }
.shot { display: block; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden; background: var(--panel2); border: 1px solid var(--line); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }

.foot { margin-top: 40px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 14px; font-weight: 600; cursor: pointer; }

/* Embedded Google Calendar */
.cal-frame { width: 100%; height: 340px; border: 0; display: block; background: #fff; }
.cal-head { justify-content: space-between; }
.ph-title { display: flex; align-items: center; gap: 9px; }
.link-cal-btn {
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  color: var(--accent); background: rgba(37,99,235,.08);
  border: 1px solid rgba(37,99,235,.28); border-radius: 999px; padding: 6px 13px;
  transition: background .12s ease;
}
.link-cal-btn:hover { background: rgba(37,99,235,.15); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(16,24,40,.5); backdrop-filter: blur(3px); padding: 18px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative; width: 100%; max-width: 460px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(16,24,40,.25); max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 6px; font-size: 1.25rem; letter-spacing: -.01em; }
.modal-sub { color: var(--muted); font-size: .9rem; margin: 0 0 18px; line-height: 1.5; }
.modal-x {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 8px;
  border: 0; background: var(--panel2); color: var(--muted); font-size: 15px; cursor: pointer;
}
.modal-x:hover { background: var(--line); color: var(--ink); }
.btn-primary {
  display: block; text-align: center; text-decoration: none; font-weight: 600;
  padding: 13px 18px; border-radius: 12px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.btn-primary:hover { filter: brightness(1.05); }
.modal-note { color: var(--muted); font-size: .82rem; line-height: 1.5; margin: 8px 2px 0; }
.modal-or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .78rem; margin: 20px 0 14px; }
.modal-or::before, .modal-or::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.modal-steps { margin: 0; padding-left: 20px; color: var(--ink); font-size: .9rem; line-height: 1.7; }
.modal-steps li { margin-bottom: 4px; }
.copy-row { display: flex; gap: 8px; margin-top: 14px; }
.copy-row input {
  flex: 1; min-width: 0; font: inherit; font-size: .82rem; color: var(--ink);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
#calCopyBtn {
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  color: #fff; background: var(--accent); border: 0; border-radius: 10px; padding: 10px 16px;
}
#calCopyBtn.copied { background: var(--good); }

/* ---- Emergency alerts ---- */
:root { --danger: #dc2626; --danger2: #991b1b; }

/* Send panel */
.emergency-panel .panel-head { justify-content: space-between; }
.e-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); display: inline-block; }
.past-alerts-link { font: inherit; font-size: .8rem; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer; text-decoration: underline; }
.past-alerts-link:hover { color: var(--ink); }
.emergency-body { padding: 16px 18px 18px; }
.emergency-body textarea {
  width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; resize: vertical; color: var(--ink); background: var(--panel2);
}
.emergency-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.emergency-hint { color: var(--muted); font-size: .82rem; }
.alert-send-btn {
  font: inherit; font-weight: 700; color: #fff; border: 0; border-radius: 11px; padding: 12px 22px; cursor: pointer;
  background: linear-gradient(135deg, var(--danger), var(--danger2)); box-shadow: 0 6px 18px rgba(220,38,38,.3);
}
.alert-send-btn:hover { filter: brightness(1.06); }
.alert-send-btn:disabled { opacity: .6; cursor: default; filter: none; }
.alert-send-btn.armed { background: linear-gradient(135deg, #991b1b, #7f1d1d); box-shadow: 0 0 0 3px rgba(220,38,38,.28); }

/* Active banner (top of dashboard) */
.alert-mount { margin-bottom: 8px; }
.alert {
  border-radius: 16px; overflow: hidden; border: 1px solid rgba(220,38,38,.35);
  box-shadow: 0 8px 30px rgba(220,38,38,.18); margin-bottom: 22px;
}
.alert-top {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; color: #fff;
  background: linear-gradient(135deg, var(--danger), var(--danger2)); font-weight: 700; letter-spacing: .02em;
}
.alert-top .pulse { width: 11px; height: 11px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 0 rgba(255,255,255,.7); animation: apulse 1.6s infinite; }
@keyframes apulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.7);} 70% { box-shadow: 0 0 0 10px rgba(255,255,255,0);} 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0);} }
.alert-top .who { margin-left: auto; font-weight: 600; font-size: .85rem; opacity: .95; }
.alert-body { background: #fff; padding: 18px; }
.alert-msg { font-size: 1.12rem; font-weight: 600; line-height: 1.4; margin: 0 0 14px; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 10px 22px; color: var(--muted); font-size: .88rem; }
.alert-meta .m { display: flex; align-items: center; gap: 7px; }
.alert-meta a { color: var(--accent); text-decoration: none; font-weight: 600; }
.alert-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.alert-actions .btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px; padding: 9px 16px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none;
}
.alert-actions .btn.primary { border-color: transparent; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.alert-actions .btn.ghost { color: var(--muted); }

/* History list */
.hist-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.hist-item .h-msg { font-weight: 600; margin: 0 0 5px; }
.hist-item .h-meta { color: var(--muted); font-size: .82rem; line-height: 1.6; }
.hist-item .h-meta a { color: var(--accent); text-decoration: none; }
.hist-item.resolved { opacity: .72; }
.hist-badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 8px; }
.hist-badge.active { color: var(--danger2); background: rgba(220,38,38,.12); }
.hist-badge.done { color: var(--good); background: rgba(5,150,105,.12); }

/* Emergency open button (lives in the hero bottom row) */
.emergency-open-btn {
  display: inline-flex; align-items: center; gap: 9px; font: inherit; font-weight: 700; cursor: pointer;
  color: #fff; border: 0; border-radius: 12px; padding: 12px 20px;
  background: linear-gradient(135deg, var(--danger), var(--danger2)); box-shadow: 0 6px 18px rgba(220,38,38,.28);
}
.emergency-open-btn:hover { filter: brightness(1.06); }
.emergency-open-btn .e-dot { background: #fff; }

/* Alert send modal */
.alert-modal h3 { display: flex; align-items: center; gap: 9px; }
.alert-modal textarea { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; resize: vertical; color: var(--ink); background: var(--panel2); margin-bottom: 12px; }
.alert-modal .alert-send-btn { width: 100%; padding: 14px; }

/* Panel tools (upload / new folder / connect) */
.panel-tools { display: flex; gap: 8px; }
.tool-btn { font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--accent); background: rgba(37,99,235,.08); border: 1px solid rgba(37,99,235,.28); border-radius: 999px; padding: 5px 11px; white-space: nowrap; }
.tool-btn:hover { background: rgba(37,99,235,.16); }
.tool-btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; }

/* Upload progress tray */
.upload-tray { position: fixed; right: 18px; bottom: 18px; width: 320px; max-width: calc(100vw - 36px); z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 50px rgba(16,24,40,.25); overflow: hidden; }
.upload-tray-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: .9rem; background: #fbfcfe; }
.upload-tray-head button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
#uploadList { max-height: 260px; overflow-y: auto; padding: 6px; }
.up-row { display: grid; grid-template-columns: 1fr 70px 34px; align-items: center; gap: 8px; padding: 7px 8px; }
.up-name { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.up-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s ease; }
.up-pct { font-size: .78rem; color: var(--muted); text-align: right; }
.up-row.done .up-pct { color: var(--good); }
.up-row.err .up-pct { color: var(--danger); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1f2937; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: .88rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 70; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Folder navigation (Drive-like) */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 10px 14px 2px; }
.crumb { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 5px; font: inherit; font-size: .84rem; border-radius: 6px; }
.crumb.here { color: var(--ink); font-weight: 600; cursor: default; }
.crumb-sep { color: var(--muted); font-size: .84rem; }
.ftiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; padding: 8px 12px 10px; }
.ftile { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; cursor: pointer; color: var(--ink); font: inherit; text-align: left; }
.ftile:hover { border-color: var(--accent); }
.ftile .fi { font-size: 18px; }
.ftile .fn { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  .welcome-photo { width: 132px; height: 88px; }
  .locations { gap: 32px; }
  .hero-bottom { flex-direction: column; gap: 18px; }
  .hero-emergency { align-items: stretch; width: 100%; }
  .hero-emergency .emergency-open-btn { justify-content: center; }
  .past-alerts-link { align-self: center; }
  .panels { grid-template-columns: 1fr; }
  .cal-frame { height: 300px; }
}
