/* ─────────────────────────────────────────────────────────────────────────────
   M49 Explorer — design system ported from the v1 Vue application (apps/web).
   Plain CSS (no Tailwind build). Tokens, surfaces, panels, navigation, and the
   localized-format panel mirror the original visual identity.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #1e66c8;
  --accent-soft: #3b82f6;
  --bg-tertiary: #f8fafc;
  --border-strong: #cbd5e1;
  --sans: 'Manrope', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --display: 'Outfit', var(--sans);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

:root[data-theme='dark'] {
  /* Monochrome Charcoal Theme */
  --background: #0a0a0a;
  --surface: #0f0f0f;
  --surface-muted: #141414;
  --line: #262626;
  --text: #ffffff;
  --muted: #a3a3a3;
  --accent: #ffffff;
  --accent-soft: #d4d4d4;
  --accent-dim: #666666;
  --border-strong: #404040;
  --bg-tertiary: #1a1a1a;
  --bg-elevated: #1f1f1f;
}

.low-power-light-ui {
  --background: #e2e8f0;
  --surface: #f1f5f9;
  --surface-muted: #e2e8f0;
  --line: #cbd5e1;
  --text: #334155;
  --muted: #64748b;
  --accent: #475569;
  --accent-soft: #64748b;
}

.low-power-light-ui body,
body:has(.low-power-light-ui) {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.low-power-light-ui .panel {
  background: var(--surface);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

button,
a[href],
[role='button'],
input[type='button'],
input[type='submit'],
input[type='reset'],
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
[aria-disabled='true'] {
  cursor: not-allowed;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: var(--sans);
  background: var(--background);
  color: var(--text);
}

:root[data-theme='light'] body {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

:root[data-theme='dark'] body {
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    var(--background);
  background-size: 40px 40px, 40px 40px, 100% 100%;
}

h1,
h2,
h3 {
  font-family: var(--display);
  letter-spacing: -0.02em;
}

a {
  color: var(--accent-soft);
}

code,
pre {
  font-family: var(--mono);
}

/* ── Layout shell ──────────────────────────────────────────────────────────── */
.app-root {
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
}

.app-main {
  margin: 0 auto;
  max-width: 1500px;
  padding: 1rem;
}

@media (min-width: 1024px) {
  .app-main {
    padding: 2rem;
  }
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 0.5rem 0;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

.explorer-grid {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 1280px) {
  .explorer-grid {
    grid-template-columns: 2fr 1fr;
  }
}

.format-region {
  margin-top: 1.25rem;
}

.error-banner {
  margin-bottom: 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(244, 63, 94, 0.4);
  background: rgba(244, 63, 94, 0.1);
  padding: 0.75rem;
  font-size: 0.875rem;
  color: #f43f5e;
}

.site-footer {
  margin-top: 1.5rem;
  padding: 1.25rem 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ── Panels & surfaces ─────────────────────────────────────────────────────── */
.panel {
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

:root[data-theme='dark'] .panel {
  background: rgba(15, 15, 15, 0.95);
  border-color: #262626;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
}

.panel--pad {
  padding: 1rem;
}

.panel--pad-lg {
  padding: 1.25rem;
}

.panel-fill {
  height: 100%;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.panel-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.dot-default {
  fill: color-mix(in srgb, var(--accent) 24%, var(--surface));
  opacity: 0.62;
  transition: opacity 180ms ease;
}

.dot-selected {
  fill: var(--accent);
  opacity: 1;
}

/* ── App header ────────────────────────────────────────────────────────────── */
.app-header {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}

@media (min-width: 1024px) {
  .app-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo-icon {
  width: 3.5rem;
  height: 3.5rem;
  transform: scale(1.25);
  transform-origin: center;
}

.header-copy {
  display: grid;
  gap: 0.14rem;
}

.header-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.05;
}

.header-tagline {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.15;
  color: var(--muted);
}

.hero-link {
  color: var(--accent-soft);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.hero-link:hover {
  color: var(--text);
}

.header-actions {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .header-actions {
    gap: 0.75rem;
  }
}

@media (min-width: 1024px) {
  .header-actions {
    width: auto;
    justify-content: flex-end;
  }
}

.icon-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0.375rem;
  color: var(--muted);
  background: transparent;
  flex-shrink: 0;
}

.icon-toggle:hover {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
}

.icon-toggle[aria-pressed='true'] {
  border-color: rgba(16, 185, 129, 0.6);
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.icon-toggle svg {
  width: 1rem;
  height: 1rem;
}

.theme-control {
  display: flex;
  width: 100%;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.25rem;
}

@media (min-width: 640px) {
  .theme-control {
    width: auto;
  }
}

.theme-option {
  display: inline-flex;
  flex: 1 1 0;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 0;
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-family: var(--sans);
  background: transparent;
  color: var(--muted);
}

@media (min-width: 640px) {
  .theme-option {
    flex: none;
  }
}

.theme-option:hover {
  color: var(--text);
}

.theme-option[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
}

.theme-option svg {
  width: 0.875rem;
  height: 0.875rem;
}

.syncing {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Navigation panel ──────────────────────────────────────────────────────── */
.nav-section {
  margin-bottom: 1.5rem;
}

.nav-label {
  margin: 0 0 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.nav-label svg {
  width: 0.875rem;
  height: 0.875rem;
}

.breadcrumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.breadcrumb-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text);
  text-decoration: none;
}

a.breadcrumb-chip:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
}

.breadcrumb-chip svg {
  width: 0.875rem;
  height: 0.875rem;
  color: var(--muted);
}

.breadcrumb-chip .font-medium {
  font-weight: 500;
}

.nav-children {
  display: grid;
  gap: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.625rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  contain: layout style;
}

.nav-item:hover {
  background: #f1f5f9;
  color: var(--text);
}

:root[data-theme='dark'] .nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: var(--accent);
}

:root[data-theme='dark'] .nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.nav-item-icon {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
}

.nav-item .font-medium {
  font-weight: 500;
}

/* ── Metric cards (localization info) ──────────────────────────────────────── */
.metric-card {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1.25rem;
}

:root[data-theme='dark'] .metric-card {
  background: linear-gradient(135deg, rgba(31, 31, 31, 0.9) 0%, rgba(20, 20, 20, 0.9) 100%);
  border-color: #262626;
}

.metric-card:hover {
  border-color: #cbd5e1;
}

:root[data-theme='dark'] .metric-card:hover {
  border-color: #404040;
}

.metric-label {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.metric-value {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
}

/* ── Localized format panel ────────────────────────────────────────────────── */
.format-grid {
  display: grid;
  gap: 1rem;
}

/* The hidden attribute must win over display:grid/flex utilities so the
   inactive Formats/Preview tab section stays collapsed (SSR and on toggle). */
[hidden] {
  display: none !important;
}

.format-cards {
  display: grid;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .format-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.lang-tz-row {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.lang-tz-at {
  font-size: 0.875rem;
  font-weight: 600;
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}

.format-block {
  border-radius: 0.75rem;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.75rem;
}

.format-section-heading {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 0 0.75rem;
  font-size: 1.02rem;
  font-weight: 700;
}

.format-rows {
  display: grid;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.format-row-label {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
}

.format-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2rem;
}

.format-divider {
  margin: 0.5rem 0;
  height: 1px;
  width: 100%;
  background: color-mix(in srgb, var(--line) 70%, transparent);
}

.value-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.inline-code {
  display: inline-flex;
  align-items: center;
  max-width: min(100%, 480px);
  border-radius: 0.5rem;
  padding: 0.2rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 72%, #000000 28%);
  white-space: nowrap;
  overflow-x: auto;
}

.copy-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: color-mix(in srgb, var(--surface) 82%, #000000 18%);
  color: var(--muted);
}

.copy-icon-btn:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--line) 60%, var(--accent) 40%);
}

.copy-icon-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

.copy-icon-btn .copy-check {
  display: none;
}

.copy-icon-btn[data-copied='true'] {
  color: #16a34a;
  border-color: #16a34a;
}

.copy-icon-btn[data-copied='true'] .copy-check {
  display: inline;
}

.copy-icon-btn[data-copied='true'] .copy-default {
  display: none;
}

.timezone-select {
  color-scheme: dark;
}

.timezone-select--cta {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 58%, var(--accent) 42%);
  border-radius: 0.65rem;
  padding: 0.3rem 2rem 0.3rem 0.7rem;
  background: color-mix(in srgb, var(--surface) 72%, #000000 28%);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.4;
  text-align: left;
}

.timezone-select--fit {
  width: max-content;
  min-width: 9rem;
  max-width: 100%;
}

.timezone-select--cta:hover {
  border-color: color-mix(in srgb, var(--line) 44%, var(--accent) 56%);
}

.timezone-select--cta:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 34%, transparent);
  border-color: color-mix(in srgb, var(--line) 35%, var(--accent) 65%);
}

.timezone-select option {
  color: var(--text);
  background: var(--surface);
}

.tabs-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  border-bottom: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
}

.tab-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 0;
  border-radius: 0;
  padding: 0.72rem 0.5rem;
  background: transparent;
  color: var(--muted);
  text-align: center;
  font-size: 0.98rem;
  font-weight: 600;
  font-family: var(--sans);
}

.tab-icon {
  width: 0.95rem;
  height: 0.95rem;
}

.tab-button:hover {
  color: var(--text);
}

.tab-button::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: transparent;
}

.tab-button--active {
  color: var(--text);
}

.tab-button--active::after {
  background: color-mix(in srgb, var(--accent) 72%, #ffffff 28%);
}

.preview-empty {
  font-size: 0.875rem;
  color: var(--muted);
}

.api-endpoint-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: color-mix(in srgb, var(--surface-muted) 80%, transparent);
  overflow: hidden;
}

.api-endpoint-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 0.35rem;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: color-mix(in srgb, var(--accent) 80%, var(--text) 20%);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.api-endpoint-uri {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}

.api-endpoint-uri:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-soft {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.btn-soft:hover {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  color: var(--text);
}

/* ── Accessibility & motion ────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
