/* Home: calm paper background, forest-green accent. Amber means due soon, red means overdue. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece8df;
  --text: #1d211e;
  --muted: #687068;
  --faint: #a3a89f;
  --line: #e6e2d8;
  --accent: #1f6b52;
  --on-accent: #ffffff;
  --accent-soft: #dcefe6;
  --accent-text: #185641;
  --warn-soft: #fbe9c6;
  --warn-text: #8a5200;
  --danger: #c8372d;
  --danger-soft: #fbe1dd;
  --danger-text: #a62a21;
  --shadow: 0 1px 2px rgba(40, 45, 30, .05), 0 6px 20px rgba(40, 45, 30, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1b1f1c;
    --surface-2: #272c28;
    --text: #eef1ec;
    --muted: #9ea69f;
    --faint: #6b736c;
    --line: #2d332e;
    --accent: #56c296;
    --on-accent: #0c1a14;
    --accent-soft: #17382c;
    --accent-text: #7fd8b3;
    --warn-soft: #3b2d10;
    --warn-text: #f1b858;
    --danger: #ff7b6e;
    --danger-soft: #40201c;
    --danger-text: #ff9a8f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(env(safe-area-inset-bottom) + 84px);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { letter-spacing: -0.02em; margin: 0; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ic { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

/* ---------- navigation: tab bar on phones, side rail on wide screens ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px max(10px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 8px) max(10px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
#tabbar .brand { display: none; }
#tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; }
#tabbar a span { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; }
#tabbar a .ic { width: 21px; height: 21px; }
#tabbar a.on { color: var(--accent-text); }
#tabbar a.on span { background: var(--accent-soft); }
body.logged-out #tabbar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.titles { flex: 1; min-width: 0; }
#crumb { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#crumb:empty { display: none; }
.topbar h1 { font-size: 24px; font-weight: 800; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
main { max-width: 760px; margin: 0 auto; padding: 4px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }

@media (min-width: 860px) {
  body { padding-bottom: 0; }
  #tabbar {
    top: 0; right: auto; width: 220px; display: flex; flex-direction: column; gap: 4px; padding: 20px 12px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--surface);
  }
  #tabbar .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-size: 18px; }
  #tabbar .brand img { width: 32px; height: 32px; border-radius: 9px; }
  #tabbar a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 15px; }
  #tabbar a span { width: auto; height: auto; }
  #tabbar a.on { background: var(--accent-soft); }
  #tabbar a.on span { background: none; }
  #page { margin-left: 220px; }
  body.logged-out #page { margin-left: 0; }
  .topbar, main { max-width: 800px; margin-left: auto; margin-right: auto; }
  .topbar { padding-top: 22px; }
  #toast { bottom: 28px !important; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 9px 16px; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 15px;
  white-space: nowrap; text-decoration: none; transition: transform .1s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: none; color: var(--danger-text); padding-left: 0; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.small .ic { width: 15px; height: 15px; }
.btn:disabled { opacity: .45; }
.file-btn { cursor: pointer; }
.link { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 600; cursor: pointer; text-decoration: underline; }
.icon-btn {
  border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; padding: 0; cursor: pointer; flex: none;
}
.icon-btn.flat { background: none; box-shadow: none; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 0; }

/* ---------- inputs ---------- */
.search { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--muted); margin-bottom: 4px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; padding: 12px 0; font-size: 16px; color: var(--text); outline: none; }
.search:focus-within { outline: 2px solid var(--accent); }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=date], textarea, select {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 16px; /* 16px stops iOS zooming in */
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { min-height: 130px; resize: vertical; line-height: 1.5; display: block; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 700; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.error { color: var(--danger-text); font-size: 15px; margin: 0; }

/* ---------- sections and cards ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 26px 2px 10px; min-height: 28px; }
.section-head h2 { font-size: 13px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.section-head > a { display: inline-flex; align-items: center; gap: 2px; font-size: 14px; font-weight: 600; color: var(--accent-text); text-decoration: none; }
.section-head > a .ic { width: 14px; height: 14px; }
.section-head > span { font-size: 13px; font-weight: 700; color: var(--faint); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.quiet { display: flex; align-items: center; gap: 8px; margin: 0; padding: 14px 16px; color: var(--muted); font-size: 15px; }
.quiet .ic { color: var(--accent); }
.quiet.as-button { width: 100%; border: 0; text-align: left; cursor: pointer; }
.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .loading { animation: none; } }
.alert { display: inline-block; margin: 0 0 8px; padding: 3px 12px; border-radius: 999px; background: var(--danger-soft); color: var(--danger-text); font-size: 13px; font-weight: 700; }
.more { margin-top: 32px; color: var(--muted); font-size: 14px; }
.more summary { cursor: pointer; font-weight: 600; }
.more .toolbar { margin-top: 10px; }

.empty { text-align: center; color: var(--muted); padding: 56px 12px; max-width: 460px; margin: 0 auto; }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 20px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.empty-icon .ic { width: 30px; height: 30px; }
.empty-title { color: var(--text); font-size: 20px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.02em; }
.empty .btn { margin-top: 10px; }

/* ---------- locations ---------- */
.places { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.place { position: relative; display: grid; gap: 1px; padding: 14px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); text-decoration: none; }
.place-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; margin-bottom: 10px; }
.place-icon .ic { width: 21px; height: 21px; }
.place b { font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.place > span:not(.place-icon) { color: var(--muted); font-size: 14px; }
.place em { position: absolute; top: 14px; right: 14px; font-style: normal; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ---------- rows (items, documents, vendors) ---------- */
.rows { overflow: hidden; }
.row, .row-link { display: flex; align-items: center; gap: 12px; min-width: 0; text-decoration: none; }
.row { padding: 11px 12px 11px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-link { flex: 1; }
.row-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; flex: none; }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--faint); width: 16px; height: 16px; }
.drive-link { display: inline-flex; align-items: center; gap: 6px; margin: 10px 2px 0; font-size: 14px; font-weight: 600; color: var(--muted); text-decoration: none; }
.drive-link .ic { width: 16px; height: 16px; }

/* ---------- maintenance ---------- */
.tasks { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.task { display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 12px; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.tick { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--faint); background: none; color: transparent; display: grid; place-items: center; padding: 0; cursor: pointer; flex: none; }
.tick .ic { width: 16px; height: 16px; stroke-width: 3; }
.tick.on, .task.done .tick { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.task.overdue .tick { border-color: var(--danger); }
.task-main { flex: 1; min-width: 0; display: grid; cursor: pointer; }
.task-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-main span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task.done .task-main b { color: var(--muted); font-weight: 500; }
.due { flex: none; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.due.soon { background: var(--warn-soft); color: var(--warn-text); }
.due.overdue { background: var(--danger-soft); color: var(--danger-text); }
.sched { margin-bottom: 10px; overflow: hidden; }
.sched header { display: flex; align-items: center; gap: 10px; padding: 12px 8px 10px 16px; }
.sched header div { flex: 1; min-width: 0; }
.sched h3 { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.sched header span { color: var(--muted); font-size: 13px; }
.sched .tasks { border-top: 1px solid var(--line); }
.sched .none { margin: 0; padding: 10px 16px 14px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.sched details { border-top: 1px solid var(--line); }
.sched summary { padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }

/* ---------- notes ---------- */
.notes { padding: 14px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.notes-edit { padding: 12px; display: grid; gap: 10px; }

/* ---------- vendors ---------- */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; flex: none; }
.vendor { display: flex; align-items: flex-start; gap: 12px; padding: 12px 8px 12px 14px; border-top: 1px solid var(--line); }
.vendor:first-child { border-top: 0; }
.vendor-main { flex: 1; min-width: 0; display: grid; }
.vendor-main a { text-decoration: none; }
.vendor-main > span { color: var(--muted); font-size: 13px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 12px; border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill .ic { width: 15px; height: 15px; color: var(--accent-text); }
.vendor-head { display: flex; align-items: center; gap: 14px; padding: 16px; margin-top: 8px; }
.vendor-head .avatar { width: 52px; height: 52px; font-size: 22px; }
.vendor-head div { display: grid; min-width: 0; }
.vendor-head b { font-size: 20px; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.vendor-head span { color: var(--muted); }
.vendor-head + .pills { margin-top: 12px; }
.vendor-head + .pills .pill { background: var(--surface); box-shadow: var(--shadow); padding: 8px 14px; }

/* ---------- sheets ---------- */
dialog.sheet {
  border: 0; padding: 20px; width: min(440px, calc(100% - 24px)); border-radius: 22px;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet::backdrop { background: rgba(15, 20, 15, .45); }
.sheet form { display: grid; gap: 14px; }
.sheet h3 { font-size: 19px; font-weight: 800; overflow-wrap: anywhere; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet.menu { display: grid; gap: 6px; }
.sheet.menu:not([open]) { display: none; }
.sheet.menu h3 { margin-bottom: 8px; }
.menu-item { border: 0; border-radius: 12px; padding: 12px 14px; background: var(--surface-2); text-align: left; font-weight: 600; cursor: pointer; }
.menu-item.danger { color: var(--danger-text); }
.menu-item.cancel { background: none; text-align: center; color: var(--muted); }
@media (max-width: 520px) {
  dialog.sheet { margin: auto auto 12px; width: calc(100% - 16px); max-width: none; padding-bottom: calc(env(safe-area-inset-bottom) + 20px); }
}

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 84px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18); z-index: 30; max-width: calc(100% - 32px);
}

/* ---------- login ---------- */
.login { max-width: 340px; margin: 14vh auto 0; text-align: center; display: grid; gap: 12px; }
.login img { width: 76px; height: 76px; border-radius: 20px; margin: 0 auto 4px; }
.login h2 { margin: 0 0 8px; font-size: 28px; font-weight: 800; }
.login .btn { padding: 12px; }
