/* Norman — mobile-first design system (cards, layout, controls) */

:root {
  --ds-touch: 2.75rem; /* 44px */
  --ds-container-max: 32rem;
  --ds-container-wide: 72rem;
  --ds-gap: 0.75rem;
  --ds-gap-lg: 1rem;
  --ds-stack: 0.5rem;
  --ds-font-title: 1.25rem;
  --ds-font-body: 0.9375rem;
  --ds-font-caption: 0.75rem;
  --ds-line-tight: 1.2;
  --ds-line: 1.45;
  --z-modal: 300;
  --z-sticky: 200;
  --z-toast: 1000;
}

/* ---------- Shell & single responsive column ---------- */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-container {
  width: 100%;
  max-width: var(--ds-container-max);
  margin: 0 auto;
  padding: 0 var(--page-pad-x) max(1.25rem, env(safe-area-inset-bottom)) var(--page-pad-x-right);
  padding-top: max(1.25rem, env(safe-area-inset-top));
  flex: 1;
}

.app-container--wide {
  max-width: var(--ds-container-wide);
}

.app-container--padded-bottom {
  padding-bottom: max(5.5rem, calc(1.25rem + env(safe-area-inset-bottom)));
}

/* ---------- Page header ---------- */

.ds-page-header {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: var(--ds-gap-lg);
  padding: 0.15rem 0 0;
}

.ds-page-header__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: var(--ds-line-tight);
  color: var(--text-primary);
  margin: 0;
}

.ds-page-header__subtitle {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: var(--ds-line);
  color: var(--text-secondary);
}

.ds-page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

/* ---------- Cards ---------- */

.ds-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.ds-card--flat {
  box-shadow: var(--shadow-xs);
}

.ds-card--pad,
.ds-section-card,
.ds-metric-card,
.ds-action-card {
  padding: 1rem 1rem 1.05rem;
}

.ds-section-card__label {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 0.45rem;
}

.ds-section-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--ds-stack);
}

.ds-metric-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  min-height: 4.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: none;
  border: 1px solid var(--border);
  padding: 0.75rem 0.9rem;
}

.ds-metric-card__value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.ds-metric-card__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
}

.ds-metric-card__hint {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.35;
}

.ds-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--ds-gap);
}

@media (min-width: 480px) {
  .ds-metric-grid--4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.ds-action-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ---------- Empty state ---------- */

.ds-empty-state {
  text-align: center;
  padding: 2.25rem 1.15rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.55;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--divider-strong);
}

.ds-empty-state__title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-2);
  margin: 0 0 0.35rem;
}

.ds-empty-state p {
  margin: 0;
}

/* ---------- Input row ---------- */

.ds-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ds-input-row__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.ds-input-row input[type="url"],
.ds-input-row input[type="text"],
.ds-input-row input[type="search"],
.ds-input-row input[type="number"] {
  width: 100%;
  min-height: var(--ds-touch);
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  border: 0;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text-primary);
  transition: box-shadow 0.15s ease, background 0.12s ease;
}

.ds-input-row input:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.ds-input-row input::placeholder {
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ---------- Chips & segmented ---------- */

.ds-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--ds-touch);
  padding: 0.35rem 0.9rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 99px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.ds-chip[aria-pressed="true"],
.ds-chip.is-selected {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47, 107, 255, 0.22);
  border-color: var(--accent);
}

.ds-chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ds-segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  background: var(--surface-2);
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ---------- Buttons ---------- */

.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--ds-touch);
  padding: 0.45rem 1.1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: 99px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.12s ease;
}

.ds-btn:active {
  transform: scale(0.98);
}

.ds-btn--primary {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 16px rgba(47, 107, 255, 0.28);
}

.ds-btn--ghost {
  color: var(--text-2);
  background: var(--surface-2);
  box-shadow: none;
}

.ds-btn--danger {
  color: var(--danger);
  background: var(--run-warm-bg);
  box-shadow: none;
}

/* ---------- Sticky bottom action bar ---------- */

.ds-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.6rem var(--page-pad-x) max(0.75rem, env(safe-area-inset-bottom)) var(--page-pad-x-right);
  background: color-mix(in srgb, var(--bg) 88%, #fff);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.06);
}

.ds-bottom-bar__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: var(--ds-container-max);
  width: 100%;
  margin: 0 auto;
  justify-content: stretch;
}

.ds-bottom-bar__row .ds-btn {
  flex: 1 1 auto;
  min-width: 0;
}

/* ---------- Modals (simple) ---------- */

.ds-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.ds-modal-backdrop[hidden] {
  display: none !important;
}

.ds-modal {
  width: 100%;
  max-width: var(--ds-container-max);
  max-height: 85dvh;
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg);
  margin: 0;
  border: 1px solid var(--border);
  padding: 1rem 1rem 1.25rem;
  animation: dsSheetIn 0.2s ease;
}

@keyframes dsSheetIn {
  from {
    transform: translateY(12px);
    opacity: 0.85;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ---------- Accordion / details ---------- */

.ds-details {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.ds-details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  min-height: var(--ds-touch);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

.ds-details > summary::-webkit-details-marker {
  display: none;
}

.ds-details[open] > summary {
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------- A11y: focus (global assist) ---------- */

:where(button, a, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

:where(a.back-link):focus-visible {
  outline-offset: 3px;
}

@media (min-width: 640px) {
  .app-container {
    padding-top: 1.75rem;
  }
}

@media (min-width: 900px) {
  .app-container--wide {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
