/* ============================================================
   DonorNearby V3.0 — Design System (Base Components)
   Tokens are in theme.css. Dark mode in dark-mode.css.
   Emergency UI in emergency-ui.css. Admin ops in admin-ops.css.
   This file: base reset + core reusable components.
   ============================================================ */

/* ─── Base Reset ─── */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
}

/* ─── Typography ─── */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: var(--weight-bold);
    line-height: 1.25;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    margin: 0;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-md); }

.text-hero {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    font-weight: var(--weight-extrabold);
    letter-spacing: -0.02em;
    line-height: 1.15;
}
@media (min-width: 640px) { .text-hero { font-size: var(--text-4xl); } }

.text-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
}

.text-caption {
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.5;
}

.text-operational {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ─── Accessibility ─── */
.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(--border-focus);
    outline-offset: 2px;
}
.skip-link {
    position: fixed; top: -100px; left: var(--space-4); z-index: 9999;
    background: var(--emergency); color: white;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-weight: var(--weight-semibold); font-size: var(--text-sm);
    transition: top var(--transition-normal);
    text-decoration: none;
}
.skip-link:focus { top: var(--space-4); }

/* ─── Cards & Surfaces ─── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
}
.card-elevated {
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}
.card-emergency {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--emergency);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-sans); font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md); border: 1px solid transparent;
    cursor: pointer; transition: all var(--transition-fast);
    line-height: 1.4; text-decoration: none;
    white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled, .btn[disabled] {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* Primary */
.btn-primary {
    background: var(--emergency); color: var(--text-on-emergency);
    border-color: var(--emergency);
}
.btn-primary:hover { background: var(--emergency-hover); }
.btn-primary:active { background: var(--emergency-active); }

/* Secondary */
.btn-secondary {
    background: var(--bg-surface); color: var(--text-primary);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-sunken); }

/* Ghost */
.btn-ghost {
    background: transparent; color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-sunken); color: var(--text-primary); }

/* Emergency CTA — decisive, high contrast */
.btn-emergency {
    background: var(--emergency); color: white;
    font-weight: var(--weight-bold);
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-md);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-emergency);
    letter-spacing: -0.01em;
}
.btn-emergency:hover {
    background: var(--emergency-hover);
    box-shadow: 0 4px 16px rgba(198,40,40,0.3);
    transform: translateY(-1px);
}
.btn-emergency:active { transform: translateY(0); }

/* Success */
.btn-success {
    background: var(--success); color: white; border-color: var(--success);
}
.btn-success:hover { background: var(--success-hover); }

/* Danger confirm */
.btn-danger {
    background: transparent; color: var(--emergency);
    border-color: var(--emergency);
}
.btn-danger:hover { background: var(--emergency); color: white; }

/* Sizes */
.btn-xs { padding: var(--space-0_5) var(--space-2); font-size: var(--text-2xs); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); }

/* ─── Badges ─── */
.badge {
    display: inline-flex; align-items: center;
    font-size: var(--text-xs); font-weight: var(--weight-semibold);
    padding: 2px var(--space-2); border-radius: var(--radius-full);
    border: 1px solid transparent; line-height: 1.5;
    white-space: nowrap;
}
.badge-critical  { background: var(--urgency-critical-bg); color: var(--urgency-critical); border-color: currentColor; }
.badge-high      { background: var(--urgency-high-bg);     color: var(--urgency-high);     border-color: currentColor; }
.badge-medium    { background: var(--urgency-medium-bg);   color: var(--urgency-medium);   border-color: currentColor; }
.badge-low       { background: var(--urgency-low-bg);      color: var(--urgency-low);      border-color: currentColor; }
.badge-immediate { background: var(--urgency-immediate-bg);color: var(--urgency-immediate); border-color: currentColor; }
.badge-success   { background: var(--success-light); color: var(--success); }
.badge-info      { background: var(--info-light);    color: var(--info); }
.badge-warning   { background: var(--warning-light); color: var(--warning); }
.badge-neutral   { background: var(--neutral-light); color: var(--neutral); }
.badge-pending     { background: var(--warning-light); color: var(--warning); }
.badge-in-progress { background: var(--info-light);    color: var(--info); }
.badge-fulfilled   { background: var(--success-light); color: var(--success); }
.badge-cancelled   { background: var(--neutral-light); color: var(--neutral); }
.badge-blood {
    background: var(--emergency-light); color: var(--emergency);
    font-weight: var(--weight-bold); font-size: var(--text-sm);
    padding: var(--space-1) var(--space-3);
}

/* ─── Form Inputs ─── */
.input {
    width: 100%;
    font-family: var(--font-sans); font-size: var(--text-sm);
    padding: var(--space-2_5) var(--space-3);
    background: var(--bg-surface); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input:focus {
    outline: none; border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}
.input::placeholder { color: var(--text-muted); }

.input-label {
    display: block; font-size: var(--text-sm); font-weight: var(--weight-semibold);
    color: var(--text-primary); margin-bottom: var(--space-1);
}
.input-required { color: var(--emergency); }
.input-help {
    font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-1);
}
.input-error {
    font-size: var(--text-xs); color: var(--emergency); margin-top: var(--space-1);
}

select.input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%235C5C5C' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 12px;
    padding-right: var(--space-8);
}

textarea.input {
    min-height: 80px;
    resize: vertical;
}

/* ─── Tables ─── */
.table-wrap {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius-xl); overflow: hidden;
    box-shadow: var(--shadow-card);
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap thead { background: var(--bg-sunken); }
.table-wrap th {
    font-size: var(--text-xs); font-weight: var(--weight-semibold);
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-tertiary);
    padding: var(--space-3) var(--space-4); text-align: left;
}
.table-wrap td {
    font-size: var(--text-sm); color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-light);
}
.table-wrap tbody tr { transition: background var(--transition-fast); }
.table-wrap tbody tr:hover { background: var(--bg-sunken); }

/* ─── Alerts ─── */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg); border: 1px solid;
    font-size: var(--text-sm); line-height: 1.5;
}
.alert-error   { background: var(--emergency-light); color: var(--emergency); border-color: var(--emergency-muted); }
.alert-success { background: var(--success-light);   color: var(--success);   border-color: var(--success-muted); }
.alert-warning { background: var(--warning-light);   color: var(--warning);   border-color: var(--warning-muted); }
.alert-info    { background: var(--info-light);      color: var(--info);      border-color: var(--info-muted); }

/* ─── Stat Cards ─── */
.stat-card {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--bg-surface);
}
.stat-card .stat-value {
    font-family: var(--font-display);
    font-size: var(--text-2xl); font-weight: var(--weight-extrabold);
    line-height: 1; letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}
.stat-card .stat-label {
    font-size: var(--text-xs); font-weight: var(--weight-semibold);
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-tertiary); margin-top: var(--space-1);
}

/* ─── Theme Toggle ─── */
.theme-toggle {
    position: relative; width: 40px; height: 22px;
    background: var(--border-strong); border-radius: var(--radius-full);
    cursor: pointer; border: none; padding: 0;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}
.theme-toggle::after {
    content: ''; position: absolute;
    top: 2px; left: 2px; width: 18px; height: 18px;
    background: white; border-radius: 50%;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
[data-theme="dark"] .theme-toggle { background: var(--emergency); }
[data-theme="dark"] .theme-toggle::after { transform: translateX(18px); }

/* ─── Language Switcher ─── */
.lang-switcher {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    font-size: var(--text-xs);
}
.lang-switcher__option {
    padding: var(--space-1) var(--space-2_5);
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
    text-decoration: none;
    transition: all var(--transition-fast);
    border-right: 1px solid var(--border);
}
.lang-switcher__option:last-child { border-right: none; }
.lang-switcher__option:hover { background: var(--bg-sunken); color: var(--text-primary); }
.lang-switcher__option.active {
    background: var(--emergency); color: white;
    font-weight: var(--weight-semibold);
}
/* ─── Interactive Cards ─── */
.card-interactive {
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}
.card-interactive:hover {
    border-color: var(--emergency-muted);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Card Header */
.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
}
.card-header__title {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    margin: 0;
}

/* Trust Signal Card */
.card-trust {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--card-trust-bg);
    border: 1px solid var(--card-trust-border);
}
.card-trust__icon {
    width: 40px; height: 40px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
}
.card-trust__title {
    font-size: var(--text-sm); font-weight: var(--weight-bold);
    color: var(--text-primary); margin-bottom: var(--space-0_5);
}
.card-trust__desc {
    font-size: var(--text-xs); color: var(--text-tertiary);
    line-height: 1.5;
}

/* ─── Pagination ─── */
.pagination {
    display: flex; justify-content: center; gap: var(--space-2); margin-top: var(--space-6);
}
.pagination__item {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-lg);
    font-size: var(--text-sm); font-weight: var(--weight-medium);
    text-decoration: none; transition: all var(--transition-fast);
    background: var(--bg-surface); color: var(--text-secondary);
    border: 1px solid var(--border);
}
.pagination__item:hover { background: var(--bg-sunken); }
.pagination__item.active {
    background: var(--emergency); color: white;
    border-color: var(--emergency);
}

/* ─── Section Divider ─── */
.section-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: var(--space-8) 0;
}

/* ─── Live Status Indicator ─── */
.live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: live-pulse 2s infinite;
}
@keyframes live-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.15); }
}

/* ─── Fade-in Animation ─── */
.fade-in {
    animation: fadeInUp 0.5s ease-out both;
}
.fade-in-delay-1 { animation-delay: 0.1s; }
.fade-in-delay-2 { animation-delay: 0.2s; }
.fade-in-delay-3 { animation-delay: 0.3s; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
    .text-hero { font-size: var(--text-2xl); }
    .stat-card .stat-value { font-size: var(--text-xl); }
    .btn-emergency { padding: var(--space-2_5) var(--space-4); font-size: var(--text-sm); }
}

/* ─── Social Links ─── */
.social-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
    text-decoration: none;
}
.social-link:hover {
    border-color: var(--emergency);
    color: var(--emergency);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}
.social-link svg {
    width: 18px;
    height: 18px;
}
