:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --border: #e2e0d8;
  --text: #1d1d1b;
  --muted: #6b6a63;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --danger: #b4372f;
  --danger-soft: #f8e5e3;
  --warn: #9a6a00;
  --warn-soft: #fbf0d4;
  --ok: #1f7a43;
  --ok-soft: #e1f3e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513; --surface: #1c1d1a; --surface-2: #242522; --border: #33342f;
    --text: #ecebe6; --muted: #9c9b93; --accent: #4fb397; --accent-ink: #0d1f1a; --accent-soft: #1d3a32;
    --danger: #e8776d; --danger-soft: #3a1f1c; --warn: #e2b44a; --warn-soft: #3a3019;
    --ok: #6fcf97; --ok-soft: #19331f; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { fill: var(--accent-ink); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { padding: .4rem .75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.me { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .6rem 1rem; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .me { margin-left: auto; }
  #me-email { display: none; }
}

/* ---------- layout ---------- */
.view { max-width: 1040px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
@media (max-width: 760px) { .view { padding: 1.25rem 1rem 3rem; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 1.25rem; }
.stack > * + * { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); filter: none; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); filter: none; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); filter: none; }
.btn.sm { padding: .3rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }

/* ---------- forms ---------- */
label.field { display: block; }
.field > span { display: block; font-size: .85rem; font-weight: 550; margin-bottom: .3rem; }
.field > small { display: block; color: var(--muted); font-size: .8rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 90px; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 9px; gap: 2px; }
.segmented label { padding: .35rem .9rem; border-radius: 7px; cursor: pointer; font-weight: 550; color: var(--muted); }
.segmented input { display: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
fieldset { border: 0; margin: 0; padding: 0; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 0 0 .75rem; }
.form-section + .form-section { border-top: 1px solid var(--border); padding-top: 1.25rem; margin-top: 1.25rem; }

/* ---------- badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: 8px; font-size: .9rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert ul { margin: .35rem 0 0; padding-left: 1.1rem; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; margin-bottom: 1.25rem; font-size: 1.15rem; }
.auth-card .brand svg { width: 34px; height: 34px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tabs button { flex: 1; background: none; border: 0; padding: .6rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- sites / accounts ---------- */
.site { overflow: hidden; }
.site-head { display: flex; align-items: center; gap: 1rem; padding: 1.1rem 1.25rem; }
.site-logo { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: .95rem; }
.site-head h2 { margin: 0; }
.site-head a { font-size: .85rem; }
.accounts { border-top: 1px solid var(--border); }
.account { display: flex; align-items: center; gap: .75rem; padding: .8rem 1.25rem; flex-wrap: wrap; }
.account + .account { border-top: 1px solid var(--border); }
.account .name { font-weight: 600; }
.account .meta { color: var(--muted); font-size: .8rem; }
.empty { padding: 1.5rem 1.25rem; color: var(--muted); text-align: center; font-size: .9rem; }
.soon { opacity: .6; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td .err { color: var(--danger); font-size: .8rem; max-width: 340px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,15,12,.45); display: grid; place-items: center; padding: 1rem; z-index: 2000; animation: fade .15s ease-out; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 2rem); overflow: auto; animation: rise .18s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .modal-backdrop, .modal { animation: none; } }

details.howto { background: var(--surface-2); border-radius: 8px; padding: .65rem .9rem; font-size: .88rem; }
details.howto summary { cursor: pointer; font-weight: 600; }
details.howto ol { margin: .5rem 0 0; padding-left: 1.2rem; }
details.howto li + li { margin-top: .25rem; }

/* ---------- map ---------- */
.map { height: 300px; border-radius: 8px; border: 1px solid var(--border); z-index: 0; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips .check { padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 99px; font-size: .85rem; }

/* ---------- preview / toasts ---------- */
pre.code { background: var(--surface-2); padding: 1rem; border-radius: 8px; overflow: auto; font-size: .8rem; max-height: 360px; margin: 0; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 3000; max-width: calc(100vw - 2rem); }
.toast { background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 8px; font-size: .9rem; box-shadow: var(--shadow); animation: rise .18s ease-out; max-width: 420px; }
.toast.error { background: var(--danger); color: #fff; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 1rem 1.25rem; display: flex; gap: .5rem; justify-content: flex-end; border-radius: 0 0 var(--radius) var(--radius); }
.token-once { background: var(--warn-soft); border-radius: 8px; padding: .75rem 1rem; word-break: break-all; }

/* ---------- photo uploader ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.photo-grid:empty { display: none; }
.photo { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.failed { border-color: var(--danger); }
.photo-ph { display: grid; place-items: center; height: 100%; font-size: .8rem; color: var(--muted); }
.photo.failed .photo-ph { color: var(--danger); }
.photo-main { position: absolute; left: 6px; top: 6px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 700; padding: .05rem .4rem; border-radius: 99px; }
.photo-actions { position: absolute; right: 4px; top: 4px; display: flex; gap: 3px; }
.photo-actions button { width: 26px; height: 26px; border-radius: 6px; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: .85rem; line-height: 1; }
.photo-actions button:hover { background: rgba(0,0,0,.8); }
