/* ===== Mesa Grande — Notion/Tally-style utility UI (mobile-first) ===== */
:root {
  --bg: #ffffff;
  --bg-subtle: #f7f7f5;
  --ink: #37352f;
  --muted: rgba(55, 53, 47, 0.6);
  --faint: rgba(55, 53, 47, 0.4);
  --line: rgba(55, 53, 47, 0.11);
  --line-strong: rgba(55, 53, 47, 0.18);
  --accent: #2383e2;
  --accent-soft: #e7f0fb;
  --danger: #c0392b;
  --ok: #3a7d44;
  --radius: 6px;
  --pad: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 .4em; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .5em; }
h3 { font-size: .95rem; font-weight: 600; margin: 0 0 .4em; }
p { margin: .4em 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: .8rem; }

/* ===== Top bar ===== */
.topbar { background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar-inner { display: flex; align-items: center; gap: .5rem; padding: .5rem .9rem; max-width: 1100px; margin: 0 auto; position: relative; }
.brand { font-weight: 700; font-size: 1rem; color: var(--ink); white-space: nowrap; margin-right: auto; }
.brand:hover { text-decoration: none; }

/* Hamburger button — shown on mobile/tablet only */
.nav-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 38px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff; cursor: pointer; color: var(--ink); padding: 0;
}
.nav-toggle:hover { background: var(--bg-subtle); }
.nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after {
  display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px;
  position: relative; transition: transform .18s ease, background .18s ease;
}
.nav-toggle-bars::before, .nav-toggle-bars::after { content: ""; position: absolute; left: 0; }
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after { top: 6px; }
.topbar.open .nav-toggle-bars { background: transparent; }
.topbar.open .nav-toggle-bars::before { transform: translateY(6px) rotate(45deg); }
.topbar.open .nav-toggle-bars::after { transform: translateY(-6px) rotate(-45deg); }

/* Nav menu — collapsed by default on mobile, opens as a dropdown panel */
.nav { display: none; }
.topbar.open .nav {
  display: flex; flex-direction: column; align-items: stretch; gap: .1rem;
  position: absolute; left: 0; right: 0; top: 100%;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: .4rem .6rem .7rem; box-shadow: 0 10px 24px rgba(0, 0, 0, .07);
}
.nav a, .nav-signout button {
  color: var(--muted); padding: .6rem; border-radius: var(--radius); font-size: .95rem;
  white-space: nowrap; display: block; width: 100%; text-align: left;
  background: none; border: 0; cursor: pointer; font: inherit;
}
.nav a:hover, .nav-signout button:hover { background: var(--bg-subtle); color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--bg-subtle); font-weight: 600; }
.nav form { margin: 0; width: 100%; }
.nav-signout { margin-top: .2rem; border-top: 1px solid var(--line); padding-top: .3rem; }

/* Nav groups — on mobile render flat: a small header + indented links */
.nav-group { width: 100%; }
.nav-group-label {
  display: block; padding: .5rem .6rem .2rem; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--faint); font-weight: 600;
}
.nav-dropdown { display: flex; flex-direction: column; }
.nav-dropdown a { padding-left: 1.1rem; }

/* Tablet landscape & up: inline nav, hide hamburger */
@media (min-width: 960px) {
  .nav-toggle { display: none; }
  .nav {
    display: flex; flex-direction: row; align-items: center; gap: .1rem;
    position: static; padding: 0; background: none; border: 0; box-shadow: none;
  }
  .nav a, .nav-signout button { width: auto; padding: .35rem .5rem; font-size: .85rem; text-align: center; }
  .nav form { width: auto; }
  .nav-signout { margin-top: 0; border-top: 0; padding-top: 0; margin-left: .15rem; }

  /* Nav groups become hover/focus dropdowns on desktop */
  .nav-group { position: relative; width: auto; }
  .nav-group-label {
    display: inline-flex; align-items: center; gap: .15rem; padding: .35rem .5rem;
    font-size: .85rem; font-weight: 400; text-transform: none; letter-spacing: normal;
    color: var(--muted); border-radius: var(--radius); cursor: pointer; user-select: none;
  }
  .nav-group-label::after { content: "▾"; font-size: .7em; opacity: .7; }
  .nav-group:hover .nav-group-label,
  .nav-group:focus-within .nav-group-label { background: var(--bg-subtle); color: var(--ink); }
  .nav-dropdown {
    display: none; position: absolute; top: calc(100% - 2px); left: 0; min-width: 180px;
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .08); padding: .3rem; z-index: 40;
  }
  .nav-group:hover .nav-dropdown,
  .nav-group:focus-within .nav-dropdown { display: flex; }
  .nav-dropdown a { padding: .5rem .6rem; text-align: left; width: 100%; white-space: nowrap; font-size: .875rem; }
}

/* ===== Public showcase landing (warm heritage feel, distinct from the app) ===== */
body.public { background: #f6f2ea; }
body.public main { max-width: 760px; padding-bottom: 0; }

.signin-link {
  position: fixed; top: 1rem; right: 1.25rem; z-index: 10;
  font-size: .85rem; letter-spacing: .02em; color: #6b5a48;
  text-decoration: none; padding: .35rem .6rem; border-radius: 6px;
}
.signin-link:hover { color: #3d2f22; background: rgba(61, 47, 34, .06); text-decoration: none; }

.landing {
  text-align: center; min-height: 72vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 1rem 1rem;
}
.landing-logo {
  width: 100%; max-width: 440px; height: auto; display: block; margin: 0 auto;
  mix-blend-mode: multiply; /* drops the logo's white box into the paper background */
}
.landing-tagline {
  font-family: Georgia, "Iowan Old Style", serif; font-style: italic;
  color: #5b4a3a; font-size: 1.1rem; letter-spacing: .01em; margin: 1.5rem auto 0; max-width: 30rem;
}
.landing-footer {
  text-align: center; color: #8a7860; font-size: .78rem;
  letter-spacing: .04em; padding: 2.5rem 1rem 3rem;
}

/* Monospace masked code value */
.code-val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }

/* ===== Upload affordance ("+ Add files" label hides a native input) ===== */
.upload-inline { margin: 0; }
label.btn { position: relative; overflow: hidden; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* Nicer native file inputs on the create/edit forms */
input[type="file"]::file-selector-button {
  font: inherit; margin-right: .6rem; padding: .3rem .6rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink); cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--bg-subtle); }

/* ===== Modal dialog ===== */
dialog.modal {
  position: relative; border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 1.25rem 1.25rem 1.4rem; max-width: 440px; width: calc(100% - 2rem);
  color: var(--ink); background: #fff; box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, .4); }
dialog.modal .modal-x { position: absolute; top: .55rem; right: .6rem; margin: 0; }
dialog.modal .modal-title { margin: 0 0 1rem; font-size: 1.15rem; }
dialog.modal label { display: block; font-weight: 500; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
dialog.modal input, dialog.modal select, dialog.modal textarea { max-width: none; width: 100%; }

/* modal: link-existing row */
.row-inline { display: flex; gap: .5rem; align-items: center; margin: 0; }
.row-inline select { flex: 1; }
/* modal: "or create new" divider */
.or-divider { display: flex; align-items: center; gap: .6rem; color: var(--faint); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; margin: 1rem 0; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
/* modal: create-new stacked form */
.stack > div { margin-bottom: .7rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.two-col > div { margin-bottom: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }

@media (max-width: 380px) { .two-col { grid-template-columns: 1fr; } }

/* ===== Layout ===== */
main { max-width: 960px; margin: 0 auto; padding: 1.25rem .9rem 5rem; }

/* ===== Flash ===== */
.flash { padding: .55rem .8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; border: 1px solid var(--line); }
.flash-notice { background: #eef7f0; border-color: #cfe6d5; color: #2b6b39; }
.flash-alert  { background: #fbeeec; border-color: #f0d2cd; color: #9e2f22; }

/* ===== Page header ===== */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1, .page-head h2 { margin: 0; }

/* ===== Buttons ===== */
/* One button size everywhere. Height matches inputs/selects (38px) so buttons
   line up with form fields. Reset native appearance so <a>, <button>, and
   <input type=submit> render identically. */
.btn, input[type="submit"], button.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  box-sizing: border-box; height: 38px; padding: 0 .9rem;
  background: var(--ink); color: #fff; border: 1px solid var(--ink);
  border-radius: var(--radius); font-size: .875rem; font-weight: 500; line-height: 1;
  cursor: pointer; font-family: inherit; text-decoration: none; white-space: nowrap;
}
.btn:hover, input[type="submit"]:hover { opacity: .88; text-decoration: none; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line-strong); }
.btn-ghost:hover { background: var(--bg-subtle); opacity: 1; }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--line-strong); }
.btn-danger:hover { background: #fbeeec; border-color: #e7b7b0; }

/* Square icon button (in-table micro actions like the ✓ toggle) */
.icon-btn {
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: #fff; color: var(--ink);
  cursor: pointer; font-size: .85rem; line-height: 1; font-family: inherit;
}
.icon-btn:hover { background: var(--bg-subtle); border-color: var(--ok); color: var(--ok); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.actions > form:last-child { margin-left: auto; } /* separate Delete to the right */

/* Panel header (title + inline action) */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .3rem; }
.panel-head h2 { margin: 0; }

/* Linked-item list (contacts on a task/project) */
.link-list { list-style: none; margin: .3rem 0 0; padding: 0; }
.link-list li { display: flex; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.link-list li:last-child { border-bottom: 0; }
.link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.link-name { font-weight: 500; color: var(--ink); }
.link-meta { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.link-meta a { color: var(--muted); }
.link-meta .dot { opacity: .5; }
.empty-inline { color: var(--muted); padding: .5rem 0 .2rem; margin: 0; }

/* Subtle × icon button (unlink / modal close) */
.icon-x { background: none; border: 0; color: var(--faint); cursor: pointer; font-size: 1.15rem; line-height: 1; padding: .15rem .4rem; border-radius: 6px; }
.icon-x:hover { background: var(--bg-subtle); color: var(--danger); }

/* ===== Cards ===== */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); margin-bottom: .9rem; }
.card h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); }
table.index { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 480px; }
table.index th, table.index td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.index thead th { background: var(--bg-subtle); color: var(--muted); font-weight: 500; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
table.index tbody tr:last-child td { border-bottom: 0; }
table.index tbody tr:hover td { background: #fbfbfa; }
table.index a { color: var(--ink); font-weight: 500; }
table.index a:hover { color: var(--accent); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 2rem 1rem; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ===== Badges ===== */
.badge { display: inline-block; padding: .08rem .45rem; border-radius: 4px; font-size: .74rem; font-weight: 500;
  background: var(--bg-subtle); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; text-transform: capitalize; }
.badge-capital, .badge-active, .badge-in_progress { background: var(--accent-soft); color: #1a5fb4; border-color: #cbe0f7; }
.badge-good, .badge-excellent, .badge-complete, .badge-completed { background: #eaf5ec; color: #2b6b39; border-color: #cfe6d5; }
.badge-fair, .badge-planning, .badge-on_hold { background: #fbf3e2; color: #8a6d1f; border-color: #efe1bf; }
.badge-poor, .badge-needs_repair { background: #fbeeec; color: #9e2f22; border-color: #f0d2cd; }
.badge-danger { background: #fbeeec; color: #9e2f22; border-color: #f0d2cd; }

/* ===== Forms ===== */
form > div, .form-row { margin-bottom: .8rem; }
form label { display: block; font-weight: 500; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="email"], input[type="password"], input[type="file"], textarea, select {
  width: 100%; max-width: 460px; padding: .5rem .6rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius); font: inherit; font-size: .9rem; background: #fff; color: var(--ink); min-height: 38px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.hint { color: var(--faint); font-size: .78rem; font-weight: 400; display: block; margin-top: .2rem; }

/* record display (show pages) */
.record > div { display: flex; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.record > div:last-child { border-bottom: 0; }
.record strong { color: var(--muted); font-weight: 500; min-width: 120px; flex-shrink: 0; }

/* ===== Dashboard ===== */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1.1rem; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; text-decoration: none; color: var(--ink); }
.stat:hover { background: var(--bg-subtle); text-decoration: none; }
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.stat .l { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-top: .3rem; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; }
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list li { padding: .45rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; font-size: .9rem; }
.dash-list li:last-child { border-bottom: 0; }
.dash-list .when { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.money-split { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.money-split .m .n { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.money-split .m .l { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.text-danger { color: var(--danger); }
.muted { color: var(--muted); }
.inline-form { display: inline; margin: 0; }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .dash-grid { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.7rem; }
}

/* ===== Attachments / photo grid ===== */
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; margin: .5rem 0; }
.attach { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: relative; background: var(--bg-subtle); }
.attach img { width: 100%; height: 90px; object-fit: cover; display: block; }
.attach .file { display: flex; align-items: center; justify-content: center; height: 90px; font-size: .78rem; color: var(--muted); text-align: center; padding: .4rem; word-break: break-word; }
.attach .cap { display: flex; align-items: center; justify-content: space-between; gap: .3rem; padding: .25rem .4rem; font-size: .72rem; border-top: 1px solid var(--line); }
.attach .cap a { color: var(--muted); }
.attach form { margin: 0; }
.attach .rm { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: .8rem; padding: 0 .1rem; line-height: 1; }

/* ===== Settings ===== */
.opt-list { list-style: none; margin: 0 0 .6rem; padding: 0; }
.opt-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.opt-list li.archived { opacity: .45; }
.opt-list form { margin: 0; display: flex; gap: .4rem; align-items: center; flex: 1; flex-wrap: wrap; }
.opt-list input[type="text"] { max-width: 260px; }
.add-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.add-row input[type="text"] { max-width: 240px; }
.settings-section { scroll-margin-top: 70px; }
.pill-link { display:inline-block; padding:.2rem .5rem; border:1px solid var(--line-strong); border-radius:999px; font-size:.8rem; color:var(--muted); margin:0 .3rem .3rem 0; }
.pill-link:hover { background: var(--bg-subtle); text-decoration:none; }
