:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6860;
  --line: #e3e0d8;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --link: #1d4ed8;
  --ok: #15803d;
  --bad: #b91c1c;
  --badge: #eeece6;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1d1c1a;
    --text: #ecebe6;
    --muted: #9b988f;
    --line: #2f2e2a;
    --accent: #f97316;
    --accent-text: #1c1b19;
    --link: #93b4ff;
    --ok: #4ade80;
    --bad: #f87171;
    --badge: #2a2926;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top, 0) 16px env(safe-area-inset-bottom, 0);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.dot { color: var(--accent); }

/* Public placeholder */
body.public { min-height: 100vh; display: grid; place-items: center; }
.hero { text-align: center; padding: 4rem 0; }
.hero h1 { font-size: clamp(2.4rem, 8vw, 4.5rem); font-weight: 700; letter-spacing: -0.03em; margin: 0; }
.hero .lede { color: var(--muted); font-size: 1.1rem; margin-top: 0.5rem; }

/* Cards / forms */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
}
.narrow { max-width: 420px; }
.stack { display: grid; gap: 0.9rem; }
.narrow-form { max-width: 420px; }
label { display: grid; gap: 0.3rem; font-weight: 500; }
input:not([type="checkbox"]) {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.methods { display: grid; gap: 0.6rem; margin: 1.2rem 0; }

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-block;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); width: 100%; }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; width: auto; }
.btn.danger { color: var(--bad); }
button.link { font: inherit; background: none; border: 0; color: var(--link); cursor: pointer; padding: 0; }

.status { min-height: 1.5em; margin: 0.8rem 0 0; }
.status[data-kind="error"] { color: var(--bad); }
.status[data-kind="ok"] { color: var(--ok); }
.notice { background: var(--badge); border-radius: 8px; padding: 0.6rem 0.9rem; }
.notice.warn { border-left: 3px solid var(--bad); }

/* Signed-in pages */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1.2rem; align-items: center; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active { color: var(--text); font-weight: 600; }
form.inline { display: inline-flex; gap: 0.4rem; align-items: center; margin: 0; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 0 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-head h1 { margin: 0; }
.count { color: var(--muted); font-weight: 400; font-size: 0.9em; margin-left: 0.3rem; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--badge);
  color: var(--muted);
  vertical-align: middle;
  margin-left: 0.3rem;
}
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }
.badge.proto { margin-left: 0; font-family: var(--mono); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table.services { width: 100%; border-collapse: collapse; }
.services th, .services td { text-align: left; padding: 0.6rem 0.9rem; vertical-align: top; border-top: 1px solid var(--line); }
.services thead th { border-top: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.services tr.cont td { border-top-style: dashed; }
.services td a.mono, .services td code { display: block; white-space: nowrap; }

/* Keys */
.keys { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 1rem;
}
.key-main { display: grid; gap: 0.3rem; flex: 1 1 280px; }
.rename input { max-width: 240px; }
.revoke label { display: inline-flex; flex-direction: row; gap: 0.3rem; font-weight: 400; align-items: center; }

/* Phone: table rows become cards */
@media (max-width: 640px) {
  .table-wrap { border: 0; background: none; }
  .services thead { display: none; }
  .services, .services tbody, .services tr, .services td { display: block; width: 100%; }
  .services tr { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 0.6rem; padding: 0.4rem 0; }
  .services tr.cont { margin-top: -0.4rem; border-top-left-radius: 0; border-top-right-radius: 0; }
  .services td { border: 0; padding: 0.25rem 0.9rem; }
  .services td:empty { display: none; }
  .services td[data-label]:not([data-label="Name"])::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 5.5rem;
    color: var(--muted);
    font-size: 0.8rem;
  }
  .services td a.mono, .services td code { display: inline-block; margin-right: 0.6rem; }
}

/* Public certificates (/cert) */
.certs-head h1 a.brand { font-size: inherit; }
.certs-head p { margin: -0.4rem 0 1.5rem; max-width: 60ch; }
.cert-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.cert {
  display: grid;
  gap: 0.35rem;
  align-content: start;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem 0.6rem 0.8rem;
  color: var(--text);
}
.cert:hover { text-decoration: none; border-color: var(--muted); }
.cert img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.cert-title { font-weight: 600; line-height: 1.35; padding: 0 0.2rem; }
.cert time { padding: 0 0.2rem; }
