/*
 * css/base.css
 * Reset · Typography · Shared layout · Global components
 * Mobile-first.  No framework.  Depends on tokens.css.
 */

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background: var(--color-bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
ul, ol { list-style: none; }

/* ── Accessibility helpers ───────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--clr-brand-500); outline-offset: 2px; }

/* ── Typography ──────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  line-height: var(--leading-tight);
  color: var(--color-text-primary);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p { line-height: var(--leading-relaxed); }

/* ── Page shell ──────────────────────────────────────────────── */
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

/* ── Form elements ───────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); }

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--color-text-primary);
}
.form-label .required {
  color: var(--clr-error-500);
  margin-left: var(--space-1);
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-size: var(--text-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--color-text-disabled); }
.input:hover { border-color: var(--clr-neutral-400); }
.input:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgb(23 178 106 / 0.18);
}
.input.is-error {
  border-color: var(--clr-error-500);
  box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15);
}
.input:disabled { background: var(--clr-neutral-100); color: var(--color-text-disabled); cursor: not-allowed; }

/* Select chevron */
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}

/* Field error */
.field-error {
  font-size: var(--text-xs);
  color: var(--color-error-text);
  min-height: 1.2em;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px; /* touch target */
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn--primary {
  background: var(--color-btn-primary-bg);
  color: var(--color-btn-primary-text);
  box-shadow: var(--shadow-brand);
}
.btn--primary:hover:not(:disabled) {
  background: var(--color-btn-primary-bg-hover);
  box-shadow: 0 6px 20px rgb(23 178 106 / 0.45);
  transform: translateY(-1px);
}

.btn--ghost {
  background: var(--color-btn-ghost-bg);
  color: var(--color-btn-ghost-text);
  border: 1.5px solid var(--color-border);
}
.btn--ghost:hover:not(:disabled) { background: var(--color-btn-ghost-bg-hover); }

.btn--link {
  background: none;
  border: none;
  color: var(--color-text-brand);
  padding: var(--space-1) var(--space-2);
  font-weight: var(--fw-semibold);
  min-height: auto;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn--link:hover { color: var(--clr-brand-800); }

.btn--full { width: 100%; }

/* Spinner inside btn */
.btn__spinner {
  width: 18px; height: 18px;
  border: 2px solid rgb(255 255 255 / 0.4);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: spin 0.65s linear infinite;
}

/* ── Feedback banners ────────────────────────────────────────── */
.feedback {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  line-height: var(--leading-normal);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}
.feedback[hidden] { display: none; }

.feedback--error {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  color: var(--color-error-text);
}
.feedback--success {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  color: var(--color-success-text);
}
.feedback--info {
  background: var(--color-info-bg);
  border: 1px solid var(--color-info-border);
  color: var(--color-info-text);
}

/* ── Page loader overlay ─────────────────────────────────────── */
.page-loader {
  position: fixed;
  inset: 0;
  background: rgb(255 255 255 / 0.75);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: var(--z-loader);
  transition: opacity var(--transition-base);
}
.page-loader[hidden] { display: none; }

.page-loader__spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--clr-brand-100);
  border-top-color: var(--clr-brand-500);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(17 24 39 / 0.55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  z-index: var(--z-modal);
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: var(--space-6);
  position: relative;
}

.modal__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: var(--clr-neutral-100);
  border: none;
  border-radius: var(--radius-sm);
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: var(--text-lg);
  transition: background var(--transition-fast);
}
.modal__close:hover { background: var(--clr-neutral-200); }

/* ── Toasts ──────────────────────────────────────────────────── */
.toast-region {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 2rem);
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-base), transform var(--transition-base);
}
.toast--visible { opacity: 1; transform: translateY(0); }

.toast--success { background: var(--clr-brand-700);   color: #fff; }
.toast--error   { background: var(--clr-error-700);   color: #fff; }
.toast--info    { background: var(--clr-neutral-800); color: #fff; }

.toast__icon { font-size: 1rem; flex-shrink: 0; }

/* ── Skeleton shimmer ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--clr-neutral-200) 25%,
    var(--clr-neutral-100) 50%,
    var(--clr-neutral-200) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.skeleton-line {
  height: 1em;
  border-radius: var(--radius-sm);
}

/* ── Utility classes ─────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-2   { margin-top: var(--space-2); }
.mt-4   { margin-top: var(--space-4); }
.mt-6   { margin-top: var(--space-6); }
.mb-4   { margin-bottom: var(--space-4); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.stack  { display: flex; flex-direction: column; }
.row    { display: flex; align-items: center; }
.w-full { width: 100%; }
.text-sm    { font-size: var(--text-sm); }
.text-muted { color: var(--color-text-secondary); }
.text-brand { color: var(--color-text-brand); }
.font-semibold { font-weight: var(--fw-semibold); }
.font-bold     { font-weight: var(--fw-bold); }
.text-center   { text-align: center; }
