/* ==========================================================================
   Alex2MQTT — shared stylesheet
   Self-hosted, no external fonts or frameworks. System font stack.
   Light + dark themes driven by the same CSS custom properties.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Palette — light */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #e2e6ec;
  --text: #1b2027;
  --text-muted: #5c6672;
  --heading: #12161c;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.10);

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.14);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 880px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Palette — dark (same variables, redefined) */
    --bg: #0f1319;
    --surface: #171d25;
    --surface-2: #1f2732;
    --border: #2a323d;
    --text: #e5e9ef;
    --text-muted: #9aa5b2;
    --heading: #f2f5f9;

    --accent: #5b8bff;
    --accent-hover: #7aa0ff;
    --accent-contrast: #0b0f15;
    --accent-soft: rgba(91, 139, 255, 0.16);

    --danger: #f2555a;
    --danger-hover: #ff6b70;
    --danger-soft: rgba(242, 85, 90, 0.16);
    --success: #38c172;
    --success-soft: rgba(56, 193, 114, 0.16);
    --warn: #f0a53d;
    --warn-soft: rgba(240, 165, 61, 0.16);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

img {
  max-width: 100%;
  height: auto;
}

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--heading);
}
.brand:hover {
  text-decoration: none;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  flex: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}
.nav a {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
}
.nav a:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 30px 16px 48px;
  flex: 1 0 auto;
}

.center-screen {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px 26px;
  margin: 0 0 22px;
}
.card:last-child {
  margin-bottom: 0;
}
.card--narrow {
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4 {
  color: var(--heading);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.8rem;
  margin: 0 0 0.5em;
}
h2 {
  font-size: 1.35rem;
  margin: 0 0 0.6em;
}
h3 {
  font-size: 1.12rem;
  margin: 1.5em 0 0.5em;
}
h4 {
  font-size: 1rem;
  margin: 1.4em 0 0.4em;
}
.card > h1:first-child,
.card > h2:first-child,
.card > h3:first-child {
  margin-top: 0;
}

p {
  margin: 0 0 1em;
}
p:last-child {
  margin-bottom: 0;
}
.muted {
  color: var(--text-muted);
}
.lead {
  font-size: 1.08rem;
  color: var(--text-muted);
}
.text-center {
  text-align: center;
}

/* Reading content (privacy, tou, examples) */
.prose h2 {
  margin-top: 1.7em;
}
.prose h3 {
  margin-top: 1.6em;
}
.prose ol,
.prose ul {
  padding-left: 1.35em;
  margin: 0 0 1em;
}
.prose li {
  margin: 0.3em 0;
}
.prose li:last-child {
  margin-bottom: 0;
}

/* ---------- Code ---------- */
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.12em 0.4em;
  border-radius: 6px;
  word-break: break-word;
}

pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 0 0 1em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text);
}
pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.03s ease,
    box-shadow 0.15s ease;
}
.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}
.btn--danger {
  background: var(--danger);
}
.btn--danger:hover {
  background: var(--danger-hover);
}
.btn--sm {
  min-height: 36px;
  padding: 7px 13px;
  font-size: 0.86rem;
  border-radius: 8px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 20px;
}

/* ---------- Status pill (async endpoint state) ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.98rem;
  font-weight: 600;
}
.status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.status--ok {
  color: var(--success);
  background: var(--success-soft);
}
.status--warn {
  color: var(--warn);
  background: var(--warn-soft);
}
.status--expired {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ---------- Tables ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
thead th {
  text-align: left;
  padding: 12px 15px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td,
tbody th {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}
tbody tr:last-child td,
tbody tr:last-child th {
  border-bottom: none;
}
tbody tr:hover td {
  background: var(--accent-soft);
}

/* Key/value credentials table (row headers) */
.creds th {
  width: 1%;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.creds td {
  font-family: var(--mono);
  font-size: 0.9rem;
  word-break: break-all;
  color: var(--text);
}
.creds tr:hover td {
  background: transparent;
}

/* ---------- Feature grid (landing) ---------- */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.feature {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.feature h3 {
  margin: 0 0 0.35em;
  font-size: 1.02rem;
}
.feature p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---------- Changelog (What's New) ---------- */
.changelog {
  margin: 0;
  padding: 0;
  list-style: none;
}
.changelog li {
  position: relative;
  padding-left: 22px;
  margin: 0 0 0.7em;
  color: var(--text);
}
.changelog li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 0.62em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.changelog li:last-child {
  margin-bottom: 0;
}

/* ---------- Tabs (code example selector) ---------- */
.tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.tab {
  appearance: none;
  -webkit-appearance: none;
  flex: 1 1 auto;
  min-height: 40px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--accent-contrast);
  background: var(--accent);
}
.tab:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}
.tabpanel {
  outline: none;
}
.tabpanel[hidden] {
  display: none;
}
.tabpanel > :first-child {
  margin-top: 0;
}
.source-link {
  margin-top: 0.8em;
}

/* ---------- Login with Amazon ---------- */
.login-section {
  text-align: center;
  padding: 12px 0 6px;
}
.login-section p {
  color: var(--text-muted);
  margin-bottom: 18px;
}
.lwa-btn {
  display: inline-block;
  line-height: 0;
}
.lwa-btn img {
  border-radius: 6px;
}

/* ---------- Footer ---------- */
.site-footer {
  flex-shrink: 0;
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  text-align: center;
  padding: 22px 16px;
  font-size: 0.9rem;
}
.site-footer p {
  margin: 0;
}

/* ---------- Loading spinner (account-linking redirect) ---------- */
.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  body {
    font-size: 15.5px;
  }
  .nav-inner {
    padding: 10px 14px;
  }
  .brand {
    font-size: 1.05rem;
  }
  .nav {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
  .nav a {
    padding: 8px 10px;
    font-size: 0.9rem;
  }
  .container {
    padding: 22px 14px 40px;
  }
  .card {
    padding: 18px 16px;
  }
  h1 {
    font-size: 1.5rem;
  }
  h2 {
    font-size: 1.2rem;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
