:root {
  --bg: #f4f7fb;
  --card: #fff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --border: #d8e0ea;
  --error: #b91c1c;
  --ok: #047857;
  --tap: 48px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* prevent horizontal overflow on mobile */
  overflow-x: hidden;
}

/* ── Header ───────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.sub { margin: 0.15rem 0 0; opacity: 0.9; font-size: 0.8rem; }

#logoutBtn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: var(--tap);
  padding: 0 0.85rem;
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
#logoutBtn:active { background: rgba(255,255,255,0.3); }

/* ── Card ─────────────────────────────────────────── */
.card {
  margin: 0.75rem 0.75rem;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

/* ── Forms ────────────────────────────────────────── */
label {
  display: block;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

input, textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-size: 1rem; /* prevent iOS zoom on focus */
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  -webkit-appearance: none;
}

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

textarea { resize: vertical; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 1.25rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

button:active { background: var(--accent-dark); }

#loginBtn {
  width: 100%;
  margin-top: 0.75rem;
}

#saveConfig {
  margin-top: 0.5rem;
}

/* ── Tabs ─────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 0.75rem;
  margin-top: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs button {
  flex: 1;
  min-height: var(--tap);
  min-width: 0;
  background: #e8eef7;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.tabs button:first-child { border-radius: 8px 0 0 8px; }
.tabs button:last-child  { border-radius: 0 8px 8px 0; }

.tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  z-index: 1;
}

/* ── Stats table ──────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 240px;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

tr:last-child td { border-bottom: none; }

th {
  background: #f0f4fa;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Logs ─────────────────────────────────────────── */
.logs { display: grid; gap: 0.75rem; }

.log-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: #fafbfd;
}

.log-item time {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.log-item .from {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.log-item .q {
  font-weight: 600;
  margin: 0.35rem 0 0.25rem;
  font-size: 0.9rem;
}

.log-item .a {
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ── Utility ──────────────────────────────────────── */
.muted { color: var(--muted); font-size: 0.88rem; }
.error { color: var(--error); font-size: 0.9rem; }
.ok    { color: var(--ok);    font-size: 0.9rem; }

/* ── Desktop ──────────────────────────────────────── */
@media (min-width: 600px) {
  header { padding: 1rem 1.5rem; }
  header h1 { font-size: 1.35rem; }
  .card { margin: 0.75rem 1.5rem; padding: 1.25rem; }
  .tabs { padding: 0 1.5rem; }
}

@media (min-width: 720px) {
  main, #login { max-width: 900px; margin-left: auto; margin-right: auto; }
}
