:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface2: #222633;
  --border: #2e3345;
  --text: #e8eaef;
  --muted: #9aa3b5;
  --primary: #6c8cff;
  --primary-hover: #8aa3ff;
  --ok: #3dd68c;
  --warn: #f5a524;
  --err: #f31260;
  --radius: 12px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --header-h: 56px;
  --pad: 1rem;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

img, canvas, svg, video {
  max-width: 100%;
  height: auto;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
}

.main {
  flex: 1;
  padding: 1.25rem 0 2.5rem;
  width: 100%;
  min-width: 0;
}

/* ── Header ── */
.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 23, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-h);
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.logo {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  flex-shrink: 0;
  white-space: nowrap;
  line-height: 1;
}
.logo span { color: var(--primary); }

.nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem 1rem;
  flex-wrap: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.nav > a:not(.btn) {
  font-size: 0.9rem;
  white-space: nowrap;
  line-height: 1;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 160px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.1rem 0;
  padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.85rem;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.site-footer .footer-inner,
.site-footer .container {
  display: block;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
  text-align: center !important;
}
.site-footer strong {
  color: var(--text);
  font-weight: 700;
}

/* ── Hero / home ── */
.hero {
  text-align: center;
  padding: 2rem 0 1.5rem;
}
.hero h1 {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  margin: 0 0 0.5rem;
  line-height: 1.2;
  word-break: break-word;
}
.lead {
  color: var(--muted);
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  max-width: 36rem;
  margin: 0 auto 1.25rem;
}
.hero-actions { margin-bottom: 1.5rem; }

.features {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .features {
    grid-template-columns: repeat(3, 1fr);
  }
}

.feature-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.feature-card h3 { margin-top: 0; }

.page-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.page-head-main {
  display: block;
  min-width: 0;
  width: 100%;
}
.page-head-main > a {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}
.page-head h1 {
  display: block;
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  line-height: 1.25;
  word-break: break-word;
}
.page-head h2 {
  display: block;
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
  word-break: break-word;
}
.page-head-main > .mono,
.page-head-main > p {
  display: block;
  margin: 0.35rem 0 0;
}
.page-head-actions,
.page-head > .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
@media (min-width: 720px) {
  .page-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
  }
  .page-head-main {
    flex: 1 1 auto;
  }
  .page-head-actions {
    flex: 0 0 auto;
  }
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); color: var(--text); }
.btn-primary { background: var(--primary); color: #0a0c12; }
.btn-primary:hover { background: var(--primary-hover); color: #0a0c12; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--err); color: #fff; }
.btn-sm {
  padding: 0.4rem 0.7rem;
  min-height: 36px;
  font-size: 0.85rem;
}
.btn-block { width: 100%; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.btn-row .btn { flex: 1 1 auto; }
@media (min-width: 480px) {
  .btn-row .btn { flex: 0 1 auto; }
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.badge-ok { background: rgba(61, 214, 140, 0.15); color: var(--ok); }
.badge-warn { background: rgba(245, 165, 36, 0.15); color: var(--warn); }
.badge-err { background: rgba(243, 18, 96, 0.15); color: var(--err); }
.badge-muted { background: var(--surface2); color: var(--muted); }
.badge-lg { font-size: 0.8rem; padding: 0.3rem 0.75rem; }

/* ── Tables ── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}
.table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table th,
.table td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  word-break: break-word;
}
.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.mono {
  font-family: var(--mono);
  font-size: 0.82em;
  word-break: break-all;
}
.muted { color: var(--muted); }
.break-all { word-break: break-all; overflow-wrap: anywhere; }
.mt { margin-top: 0.75rem; }

/* ── Forms ── */
label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 500;
}

/* 16px+ prevents iOS zoom on focus */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="search"],
textarea,
select {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa3b5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(108, 140, 255, 0.45);
  outline-offset: 1px;
  border-color: var(--primary);
}

.form-card {
  max-width: 560px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}
.form-actions .btn { flex: 1 1 140px; }
.form-section {
  margin: 1.25rem 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.q-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px dashed var(--border);
}
.q-row .opts { grid-column: 1 / -1; }
.q-row input,
.q-row select { width: 100%; }
@media (min-width: 720px) {
  .q-row {
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    border-bottom: none;
    padding-bottom: 0;
  }
}

.chk {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  margin: 0;
  white-space: nowrap;
}
.chk input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 700px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.qr-box {
  margin: 0.75rem 0;
  min-height: 0;
}
.qr-box img {
  max-width: min(220px, 100%);
  height: auto;
  display: block;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.login-card {
  max-width: 400px;
  width: 100%;
  margin: 1.5rem auto;
  text-align: center;
}
.login-card h1 { margin-top: 0; }
.google-btn { margin-top: 1.25rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  text-align: left;
  word-break: break-word;
}
.alert-error { background: rgba(243, 18, 96, 0.12); color: var(--err); }
.alert-ok { background: rgba(61, 214, 140, 0.12); color: var(--ok); }

.search-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  align-items: stretch;
}
.search-bar label {
  flex: 1;
  margin: 0;
  width: 100%;
}
.search-bar input { margin-top: 0.35rem; }
.search-bar .btn { width: 100%; }
@media (min-width: 560px) {
  .search-bar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
  }
  .search-bar .btn { width: auto; }
}

.dl { margin: 0; }
.dl dt {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.75rem;
}
.dl dd {
  margin: 0.15rem 0 0;
  word-break: break-word;
}

.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.answers {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
}
.empty { text-align: center; color: var(--muted); }

details summary {
  cursor: pointer;
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }

/* ── Phone-specific polish ── */
@media (max-width: 640px) {
  :root { --pad: 0.85rem; }

  .header-inner {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0.5rem;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
  }

  .user-chip {
    max-width: min(200px, 50vw);
  }

  .card, .feature-card {
    padding: 0.9rem 0.95rem;
    border-radius: 10px;
  }

  .table {
    min-width: 480px;
    font-size: 0.8rem;
  }

  .main { padding: 1rem 0 2rem; }

  .site-footer {
    text-align: center;
  }
}

/* Landscape phones */
@media (max-height: 420px) and (orientation: landscape) {
  .hero { padding: 1rem 0; }
  .site-header { position: relative; }
}

.opts-label {
  grid-column: 1 / -1;
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}
.opts-label input {
  margin-top: 0.35rem;
  border-color: var(--primary);
}
.q-row .opts {
  grid-column: 1 / -1;
}
