:root {
  --bg: #f4f6f9; --surface: #fff; --surface2: #f0f2f5; --border: #e1e5ea;
  --text: #17192b; --text2: #667085; --accent: #4f6ef7; --accent-hover: #3b5de7; --accent-bg: #eef1fe;
  --red: #c81e1e; --red-bg: #fde8e8; --green: #0e7a43; --green-bg: #e3f5eb; --amber: #92570a; --amber-bg: #fdf1dc;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a; --surface: #172033; --surface2: #233047; --border: #334155;
    --text: #e2e8f0; --text2: #94a3b8; --accent: #6b8afd; --accent-hover: #5878f5; --accent-bg: #1e2a4d;
    --red: #fca5a5; --red-bg: #4c1d1d; --green: #86efac; --green-bg: #143524; --amber: #fcd34d; --amber-bg: #3d2e0d;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --surface: #172033; --surface2: #233047; --border: #334155;
    --text: #e2e8f0; --text2: #94a3b8; --accent: #6b8afd; --accent-hover: #5878f5; --accent-bg: #1e2a4d;
    --red: #fca5a5; --red-bg: #4c1d1d; --green: #86efac; --green-bg: #143524; --amber: #fcd34d; --amber-bg: #3d2e0d;
    --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 21px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--text2); }
.hint { color: var(--text2); font-size: 13px; margin: 8px 0 0; }

/* sign-in pages */
body.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px 28px; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.sub { color: var(--text2); margin: 0 0 20px; }
.fine { color: var(--text2); font-size: 12.5px; }
.card .fine { margin: 16px 0 0; text-align: center; }
.card label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
input[type=email], input[type=text], input[type=search], input:not([type]), select {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 15px; font-family: inherit; }
.card input { margin-bottom: 12px; }
input.code { font-size: 26px; letter-spacing: 8px; text-align: center; }
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
button, .btn { display: inline-block; width: 100%; padding: 9px 14px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; font-size: 14.5px; font-weight: 600; cursor: pointer;
  text-align: center; text-decoration: none; font-family: inherit; }
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.google { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.google:hover { background: var(--surface2); }
button.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { border-color: var(--text2); }
button.danger { background: var(--red-bg); color: var(--red); }
button.small { width: auto; padding: 5px 11px; font-size: 13px; }
button.link, a.link { width: auto; background: none; border: none; color: var(--accent); padding: 0;
  font-size: 14px; font-weight: 500; cursor: pointer; }
button.link:hover, a.link:hover { background: none; text-decoration: underline; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.row form { margin: 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--text2); font-size: 12.5px; margin: 18px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.error { background: var(--red-bg); color: var(--red); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.note, .flash { background: var(--green-bg); color: var(--text); padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.apps { list-style: none; padding: 0; margin: 0 0 8px; }
.apps li a { display: block; padding: 11px 14px; margin-bottom: 8px; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); background: var(--surface2); }
.apps li a:hover { border-color: var(--accent); text-decoration: none; }
.card.wide { max-width: 460px; }
.card .h { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin: 22px 0 10px; }
.card .note, .card .error { margin: 0 0 14px; }
.card .fine.left { text-align: left; }
.applist-home { list-style: none; padding: 0; margin: 0 0 8px; }
.applist-home .app { padding: 11px 14px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface2); }
.applist-home.others .app { background: var(--surface); border-style: dashed; }
.app-main { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.app-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.app-text .desc { color: var(--text2); font-size: 13px; line-height: 1.35; }
.app-action { flex-shrink: 0; }
.app-action form { margin: 0; }
a.btn.small { width: auto; padding: 5px 14px; font-size: 13px; }
details.more { margin-top: 6px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 500; width: fit-content; }
details.more ul { margin: 6px 0 2px; padding-left: 18px; font-size: 13.5px; list-style: disc; }
details.more li { margin: 3px 0; }
.desc-box { background: var(--surface2); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin: 0 0 14px; }
textarea { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-family: inherit; font-size: 14px; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* admin */
.bar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.bar-inner { max-width: 1240px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; align-items: center; gap: 4px 24px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); padding: 14px 0; }
.brand span { color: var(--accent); font-weight: 600; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { padding: 15px 12px 13px; color: var(--text2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 19px; padding: 0 6px; border-radius: 99px; background: var(--red);
  color: var(--bg); font-size: 11.5px; line-height: 19px; text-align: center; }
.me { font-size: 13px; padding: 12px 0; }
.page { max-width: 1240px; margin: 0 auto; padding-block: 20px 60px; padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.page > p { margin: 0 0 14px; }
.flash { margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.empty { color: var(--text2); margin: 4px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two > .panel { margin-bottom: 0; min-width: 0; }
.two + .panel, .two + section { margin-top: 18px; }
@media (max-width: 820px) { .two { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  color: var(--text); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat .num { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--text2); font-size: 13px; margin-top: 4px; }
.stat.warn .num { color: var(--red); }

.requests, .feed, .plain, .members, .applist { list-style: none; padding: 0; margin: 0; }
.requests li { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 0; border-top: 1px solid var(--border); }
.requests li:first-child { border-top: none; }
.req-actions { display: flex; gap: 8px; }
.req-actions form { margin: 0; }
.feed li { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.feed li:first-child { border-top: none; }
.feed .when { color: var(--text2); font-size: 13px; }
.plain li, .members li, .applist li { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--border); }
.plain li:first-child, .members li:first-child, .applist li:first-child { border-top: none; }
.applist label { display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; }
.who { display: inline-flex; flex-direction: column; color: var(--text); line-height: 1.3; }
.who:hover { text-decoration: none; }
.who:hover strong { color: var(--accent); }
.who .muted { font-size: 12.5px; }
.right { display: flex; align-items: center; gap: 8px; }
.right form { margin: 0; }
button.x { width: 26px; height: 26px; padding: 0; border-radius: 6px; background: transparent; color: var(--text2);
  font-size: 18px; line-height: 1; border: 1px solid transparent; }
button.x:hover { background: var(--red-bg); color: var(--red); }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  vertical-align: middle; white-space: nowrap; background: var(--surface2); color: var(--text2); }
.pill.active { background: var(--green-bg); color: var(--green); }
.pill.new { background: var(--amber-bg); color: var(--amber); }
.pill.blocked { background: var(--red-bg); color: var(--red); }
.pill.owner { background: var(--accent-bg); color: var(--accent); }

details.add > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.add > summary::before { content: "+ "; color: var(--accent); }
details.add[open] > summary { margin-bottom: 14px; }
.addform .fields { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.addform .fields input { flex: 1 1 220px; width: auto; }
.addform button { width: auto; margin-top: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { display: flex; gap: 7px; align-items: center; font-size: 14px; white-space: nowrap; cursor: pointer; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.toolbar input[type=search] { flex: 1 1 220px; width: auto; }
.toolbar select { width: auto; flex: 0 1 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { width: auto; padding: 5px 11px; font-size: 13px; font-weight: 500; background: var(--surface2); color: var(--text2);
  border: 1px solid var(--border); border-radius: 99px; }
.chip:hover { background: var(--surface2); color: var(--text); }
.chip.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.scroll { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--text2); font-weight: 600; white-space: nowrap; }
.grid th.c { text-align: center; max-width: 92px; white-space: normal; line-height: 1.2; }
td.c { text-align: center; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
tr.blocked td { opacity: .65; }
tr.owner td { background: var(--surface2); }
.tick { color: var(--text2); }
.grid tbody tr:hover td { background: var(--surface2); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); gap: 18px; margin-bottom: 18px; }
.cards .panel { margin-bottom: 0; display: flex; flex-direction: column; min-width: 0; }
.appcard > p { margin: -6px 0 10px; font-size: 13px; }
.appcard .members { flex: 1; }
.give { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.give select { flex: 1; width: auto; }
.appcard > p.appdesc { margin: -4px 0 8px; font-size: 13.5px; color: var(--text); }
details.edit { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
details.edit summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 500; }
details.edit .addform { margin-top: 10px; }
details.edit label { display: block; font-size: 12.5px; color: var(--text2); margin-bottom: 8px; }
details.edit input, details.edit textarea { margin-top: 3px; }
details.add .addform > input, details.add .addform > textarea { margin-bottom: 10px; }

.person-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.person-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.person-head p { margin: 2px 0; }
.rename { display: flex; gap: 8px; }
.rename input { width: 220px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack button { width: auto; }
.stack .hint { margin-top: 4px; }

.js .nojs { display: none; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); color: var(--bg); }
code { font-size: 13px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media (max-width: 860px) {
  .bar-inner { padding-top: 8px; }
  .brand { padding: 6px 0; }
  .me { order: 2; margin-left: auto; padding: 6px 0; }
  .tabs { order: 3; flex: 1 0 100%; justify-content: space-between; }
  .tabs a { padding: 10px 6px 9px; }
}

/* app admins */
.admins { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 10px; font-size: 13.5px; }
.admin-chip { display: inline-flex; align-items: center; gap: 2px; padding: 1px 2px 1px 9px; border-radius: 99px;
  background: var(--amber-bg); color: var(--amber); font-weight: 600; font-size: 12.5px; }
.admin-chip form { margin: 0; }
.admin-chip button.x { width: 22px; height: 22px; font-size: 15px; color: var(--amber); }
.sub-h { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin: 14px 0 6px; }
.give input[type=email] { flex: 1; width: auto; }
.appcard { scroll-margin-top: 76px; }
