:root {
  --bg: #f6f6f4; --card: #ffffff; --ink: #1a1a1a; --muted: #6b6b6b; --line: #e4e4e0;
  --accent: #6e56cf; --accent-ink: #fff; --danger: #e5484d; --ok: #30a46c;
  --radius: 12px; --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121212; --card: #1c1c1e; --ink: #f2f2f2; --muted: #a0a0a0; --line: #2c2c2e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 15px; margin: 12px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.wrap { max-width: 900px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

input, select, textarea, button {
  font: inherit; color: inherit; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); padding: 10px 12px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 15px; }
input[type=checkbox] { width: auto; }

button, .btn { cursor: pointer; width: auto; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--card); border: 1px solid var(--line); padding: 9px 14px; font-weight: 500; white-space: nowrap; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button.sm, .btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; border: 1px solid var(--line); background: var(--card); white-space: nowrap; }
.chip.tier { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--gc, var(--line)); border-radius: 10px;
  padding: 10px 12px; display: flex; gap: 10px; align-items: center; cursor: pointer; }
.item:active { opacity: .8; }
.item .name { font-weight: 600; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch; padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; }
nav.bottom a.on { color: var(--accent); }
nav.bottom a span.ic { font-size: 20px; line-height: 1; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.me { font-size: 13px; color: var(--muted); }
.me b { color: var(--ink); }

.qrbox { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px; }
.qrbox canvas { border-radius: 8px; background: #fff; padding: 8px; max-width: 100%; height: auto; }
.linkbox { display: flex; gap: 6px; width: 100%; }
.linkbox input { font-size: 13px; }

.tiers { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tiercol { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 90px; }
.tiercol h3 { margin: 0 0 6px; text-align: center; }
.tiercard { border-left: 4px solid var(--gc, var(--line)); background: var(--bg); border-radius: 6px; padding: 6px 8px; margin: 4px 0;
  font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.tiercard select { width: auto; padding: 2px 4px; font-size: 12px; border-radius: 6px; }

.note { border-top: 1px solid var(--line); padding: 8px 0; }
.note .who { font-size: 12px; color: var(--muted); }
.note .who b { color: var(--ink); }

.toast { position: fixed; bottom: calc(var(--nav-h) + 14px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.faded { opacity: .45; }
.center { text-align: center; }
.big { font-size: 28px; font-weight: 700; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.login { max-width: 360px; margin: 15vh auto; }
.count { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; margin-left: 4px; }
.contact { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.contact:first-child { border-top: 0; }
.contact .n { font-weight: 600; }
.contact .p { color: var(--muted); font-size: 14px; }
.tiercol.unranked { grid-column: 1 / -1; }
.tiercol.unranked .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }

/* v2 additions */
select.mini, input.mini { width: auto; padding: 6px 9px; font-size: 13px; border-radius: 8px; }
.chip.tier.dropped { background: var(--danger); border-color: var(--danger); color: #fff; }
.tiercol.dropped { grid-column: 1 / -1; }
.tiercol.dropped .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.badge { position: absolute; top: -6px; right: -12px; background: var(--danger); color: #fff; font-size: 10px; border-radius: 999px; padding: 1px 5px; font-weight: 700; }
nav.bottom a span.ic { position: relative; }
.inbox { border: 2px solid var(--accent); }
.inbox .list { max-height: 300px; overflow: auto; }
.qrbox { cursor: pointer; }
.shortlink { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 17px; font-weight: 700; word-break: break-all; text-align: center; }
.bigqr { position: fixed; inset: 0; background: #fff; color: #111; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 20px; }
.bigqr canvas { max-width: 100%; height: auto; }
.photo { display: block; width: 96px; height: 120px; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px dashed var(--line); flex: none; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .ph { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); font-size: 22px; text-align: center; line-height: 1.2; }
.item .name { line-height: 1.2; }
/* read-only (exec) accounts: write controls are hidden; the database refuses writes regardless */
body.ro .w { display: none !important; }
body.ro input:disabled, body.ro select:disabled, body.ro textarea:disabled { opacity: 1; color: var(--ink); background: var(--bg); }

/* desktop-only spreadsheet view */
.desktop-only { display: none; }
@media (min-width: 900px) { .desktop-only { display: inline-flex; gap: 8px; align-items: center; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--ink); color: var(--bg); }
.sheetwrap { overflow: auto; max-height: 75vh; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 1500px; }
table.sheet th, table.sheet td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; vertical-align: middle; white-space: nowrap; }
table.sheet th { position: sticky; top: 0; background: var(--bg); text-align: left; padding: 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; z-index: 1; }
table.sheet th.sortable { cursor: pointer; }
table.sheet td.open { text-align: center; width: 28px; border-left: 4px solid var(--gc, transparent); }
table.sheet td input, table.sheet td select { border: 0; border-radius: 0; background: transparent; padding: 7px 8px; min-width: 110px; font-size: 13px; }
table.sheet td input:focus, table.sheet td select:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--card); }
table.sheet td span { display: block; padding: 7px 8px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.sheet td.c-info input, table.sheet td.c-hang_with input, table.sheet td.c-connection input { min-width: 260px; }
table.sheet td.c-notes span { max-width: 420px; }
@media (min-width: 900px) { .wrap:has(.sheetwrap) { max-width: 1500px; } }
