/* Reusable components -- uses contract vars from base.css */

/* -- Admin layout -- */
.admin-header {
  background: var(--color-text);
  color: #fff;
  padding: 0 var(--space-md);
}

.admin-header nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-sm) 0;
}

.admin-header a {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.875rem;
}

.admin-header a:hover {
  color: #fff;
  text-decoration: none;
}

.admin-header .admin-brand {
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
}

.admin-header button,
.admin-header [type="submit"] {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.8125rem;
  padding: var(--space-xs) var(--space-sm);
  min-height: 36px;
  border-radius: 6px;
}

.admin-header button:hover,
.admin-header [type="submit"]:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* -- Admin dashboard sections -- */
.admin-section {
  margin-bottom: var(--space-lg);
}

.admin-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* -- Metric cards -- */
.metrics-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
}

.metric-card.metric-good    { border-left: 4px solid var(--color-success); }
.metric-card.metric-neutral { border-left: 4px solid var(--color-warning); }
.metric-card.metric-bad     { border-left: 4px solid var(--color-danger); }

.metric-label {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

.metric-value {
  margin: var(--space-xs) 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

/* -- Definition lists (admin user show) -- */
dl.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
}

dl.detail-list dt {
  font-weight: 500;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

dl.detail-list dd {
  margin: 0;
  color: var(--color-text);
}

/* -- Auth pages (Devise) -- */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: var(--space-xl) var(--space-md);
}

.auth-header {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.auth-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.auth-header p {
  color: var(--color-text-muted);
  margin: 0;
}

.auth-card {
  width: 100%;
  max-width: var(--app-content-width);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-lg);
}

.auth-card .field {
  margin-bottom: var(--space-md);
}

.auth-card .field label {
  font-size: 0.875rem;
}

.auth-card .field input {
  margin-top: var(--space-xs);
}

.auth-card .actions {
  margin-top: var(--space-md);
}

.auth-card .actions input[type="submit"],
.auth-card .actions button {
  width: 100%;
}

.auth-card .check-field {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.auth-card .check-field input[type="checkbox"] {
  margin: 0;
}

.auth-card .check-field label {
  margin: 0;
  font-weight: 400;
  font-size: 0.875rem;
}

.auth-links {
  text-align: center;
  margin-top: var(--space-md);
  font-size: 0.875rem;
}

.auth-links a {
  display: block;
  padding: var(--space-xs) 0;
  color: var(--color-primary);
  min-height: auto;
}

.auth-errors {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
}

.auth-errors ul {
  margin: var(--space-xs) 0 0;
  padding-left: var(--space-md);
}

/* -- App header / footer -- */
.app-header {
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-md);
}

.app-header nav {
  max-width: 1200px;
  margin: 0 auto;
}

.app-header .app-brand {
  font-family: var(--font-display);
  font-size: 1.176rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}

.app-header .app-brand:hover {
  text-decoration: none;
}

.app-header nav a {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.app-header nav a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.app-header nav a[role="button"] {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.8125rem;
  padding: var(--space-xs) var(--space-md);
  min-height: 36px;
  border-radius: var(--radius);
}

.app-header nav a[role="button"]:hover {
  color: #fff;
  opacity: 0.9;
}

.app-header button,
.app-header [type="submit"] {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  font-size: 0.875rem;
  padding: var(--space-xs) var(--space-sm);
  min-height: 36px;
}

.app-header button:hover,
.app-header [type="submit"]:hover {
  background: transparent;
  color: var(--color-text);
}

/* Three-column row footer for unsigned-in chrome (landing, auth,
   privacy, terms). Copyright sits left, Privacy/Terms nav center,
   locale switcher right. Wraps to a left-aligned column under
   480px so phones don't squeeze. Signed-in users never see this
   footer — bottom-nav is their only chrome (see nav.css). */
.app-footer {
  border-top: 1px solid var(--color-border);
  padding: var(--space-lg) var(--space-md);
  margin-top: var(--space-xl);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}
@media (max-width: 480px) {
  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--space-md);
  }
}

.app-footer small {
  color: var(--color-text-muted);
}

.app-footer nav {
  padding: 0;
}

.app-footer a {
  color: var(--color-text-muted);
  font-size: 0.8125rem;
}

.app-footer a:hover {
  color: var(--color-text);
}

/* -- Mobile-first touch targets -- */
button, [role="button"], a { min-height: 44px; }

/* -- Inline SVG icons -- */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.icon-text { display: inline-flex; align-items: center; gap: 0.5rem; }

/* -- Locale switcher --
   Children are mixed: <span class="locale-current"> for the active
   locale, <a class="locale-link"> for the others. The global
   `a { min-height: 44px }` touch-target rule misaligns them — anchors
   become 44px tall while spans stay text-line height. Explicit
   min-height: auto + matching font-size keeps the row tight and aligned. */
.locale-switcher {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
  justify-content: center;
  margin-top: var(--space-sm);
}
.locale-switcher .locale-current,
.locale-switcher .locale-link {
  font-size: 0.85rem;
  line-height: 1;
  min-height: auto;
  padding: 0.15rem 0.4rem;
}
.locale-switcher .locale-current {
  font-weight: 600;
  color: var(--color-text);
}
.locale-switcher .locale-link {
  color: var(--color-text-muted);
  text-decoration: none;
}
.locale-switcher .locale-link:hover {
  color: var(--color-primary);
}

/* -- Locale nav dropdown (top menu) -- */
.locale-nav {
  position: relative;
  display: inline-flex;
}
.locale-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.8125rem;
  color: var(--color-text);
  cursor: pointer;
  min-height: auto;
  line-height: 1;
  transition: border-color 0.15s;
}
.locale-nav-btn:hover {
  border-color: var(--color-muted);
}
.locale-nav-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  min-width: 140px;
  z-index: 100;
  overflow: hidden;
}
.locale-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.8125rem;
  color: var(--color-text);
  text-decoration: none;
  min-height: auto;
  transition: background 0.1s;
}
.locale-nav-item:hover {
  background: var(--color-bg-alt, var(--color-border));
}
.locale-nav-active {
  font-weight: 600;
  color: var(--color-primary);
}
.hidden { display: none !important; }

/* -- Early access feedback -- */
.ea-success {
  color: var(--color-success);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}
.ea-error {
  color: var(--color-danger);
  font-size: 0.9rem;
  margin-bottom: var(--space-xs);
}

/* -- Grid responsive -- */
@media (max-width: 767px) {
  .grid { grid-template-columns: 1fr !important; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
}

/* =============================================================
   App layout
   ============================================================= */

/* Centered content column (the primary layout for all app screens) */
.content-column {
  width: 100%;
  max-width: var(--app-content-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* Page wrapper — full-height, flex column, space for bottom nav on mobile */
.app-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Section within a page (vertical rhythm) */
.app-section {
  padding: var(--space-lg) 0;
}

/* Sticky page-level header strip (title + actions row) */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-md);
  gap: var(--space-sm);
}

.page-title {
  font-size: var(--text-title);
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

/* =============================================================
   Buttons (extend base.css defaults)
   ============================================================= */

/* Named variants — use these for non-primary actions. The bare <button>
 * / [type="submit"] in base.css is the canonical primary; reach for these
 * only when an action is secondary, ghost, or destructive.
 *
 * appearance: none is mandatory — see base.css comment. */
.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  font: inherit;
  font-size: var(--text-body-sm);
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  transition: opacity var(--duration-quick) var(--ease-in-out),
              background-color var(--duration-quick) var(--ease-in-out),
              border-color var(--duration-quick) var(--ease-in-out);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); text-decoration: none; }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--color-surface); color: var(--color-text); text-decoration: none; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover { opacity: 0.88; text-decoration: none; }

.btn-sm {
  font-size: var(--text-caption);
  padding: var(--space-xs) var(--space-sm);
  min-height: 32px;
}

.btn-full { width: 100%; }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* =============================================================
   Cards
   ============================================================= */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
}

.card + .card { margin-top: var(--space-sm); }

.card-title {
  font-size: var(--text-heading);
  font-weight: 600;
  margin: 0 0 var(--space-xs);
  color: var(--color-text);
}

.card-body {
  font-size: var(--text-body-sm);
  color: var(--color-text-muted);
}

/* Clickable card row */
.card-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--duration-quick) var(--ease-in-out);
  text-decoration: none;
  color: var(--color-text);
}
.card-row:hover { background: var(--color-bg); text-decoration: none; }
.card-row + .card-row { border-top: none; border-radius: 0; }
.card-row:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card-row:last-child  { border-radius: 0 0 var(--radius) var(--radius); }
.card-row:only-child  { border-radius: var(--radius); }

/* =============================================================
   Badges / pills
   ============================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  padding: 0.2em 0.6em;
  font-size: var(--text-caption);
  font-weight: 500;
  border-radius: var(--radius-full);
  white-space: nowrap;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }
.badge-danger  { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: transparent; }
.badge-info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: transparent; }
.badge-primary { background: var(--color-primary);    color: var(--color-primary-text); border-color: transparent; }

/* =============================================================
   Empty states
   ============================================================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-md);
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-sm);
  opacity: 0.5;
}

.empty-state h2 {
  font-size: var(--text-heading);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.empty-state p {
  font-size: var(--text-body-sm);
  margin-bottom: var(--space-md);
  max-width: 28ch;
}

/* =============================================================
   Mobile bottom nav
   ============================================================= */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: stretch;
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-xs) 0 var(--space-sm);
  font-size: var(--text-micro);
  color: var(--color-text-muted);
  text-decoration: none;
  min-height: 52px;
  transition: color var(--duration-quick) var(--ease-in-out);
}

.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a:hover { color: var(--color-primary); text-decoration: none; }
.bottom-nav a.active { color: var(--color-primary); }

/* Push content above bottom nav */
.has-bottom-nav { padding-bottom: calc(52px + env(safe-area-inset-bottom, 0)); }

/* Hide bottom nav when inside native shell (bridge handles native tab bar) */
[data-bridge-components] .bottom-nav { display: none; }

/* =============================================================
   Form helpers (extends base.css form styles)
   ============================================================= */

.field-hint {
  font-size: var(--text-caption);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

.field-error {
  font-size: var(--text-caption);
  color: var(--color-danger);
  margin-top: var(--space-xs);
}

input.field-invalid,
select.field-invalid,
textarea.field-invalid {
  border-color: var(--color-danger);
}

input.field-invalid:focus,
select.field-invalid:focus,
textarea.field-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* -- Social auth buttons (Sign in with Google / Apple) -- */
.auth-social {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.auth-social-divider {
  position: relative;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: var(--space-sm) 0;
}

.auth-social-divider::before,
.auth-social-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: calc(50% - 2.5rem);
  height: 1px;
  background: var(--color-border);
}

.auth-social-divider::before { left: 0; }
.auth-social-divider::after { right: 0; }

.auth-social-divider span {
  background: var(--color-surface);
  padding: 0 var(--space-sm);
}

.auth-social-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.auth-social-button:hover {
  background: var(--color-surface-alt, var(--color-surface));
  border-color: var(--color-text-muted);
}

.auth-social-icon {
  flex-shrink: 0;
}
