/* ============================================
   DOG SAVE USA — Patriotic Theme
   Red, White & Blue · Dark Navy base
   All color pairings verified WCAG AA (4.5:1+)
   ============================================ */

/* --- Custom Properties --- */
:root {
    /* Navy foundations */
    --bg-primary: #0a1628;
    --bg-secondary: #0f1d33;
    --bg-card: #131f35;
    --bg-input: #0f1d33;

    /* Text — all pass AA on all backgrounds above */
    --text-primary: #e8e8e8;       /* 14.80:1 on bg-primary */
    --text-secondary: #b0b8c8;     /* 9.10:1 on bg-primary */
    --text-muted: #8899aa;         /* 6.20:1 on bg-primary */

    /* Accent red — AA compliant on dark backgrounds */
    --accent: #ea5060;             /* 5.02:1 on bg-primary, 4.56:1 on bg-card */
    --accent-hover: #f06070;       /* 5.71:1 on bg-primary */
    --accent-muted: rgba(234, 80, 96, 0.12);
    --accent-text: #0a1628;        /* 5.02:1 on accent — for text ON red */

    /* Accent blue — AA compliant on dark backgrounds */
    --blue: #5b8dd9;               /* 5.40:1 on bg-primary, 4.91:1 on bg-card */
    --blue-hover: #6e9de5;
    --blue-muted: rgba(91, 141, 217, 0.12);
    --blue-deep: #2a4a8a;          /* 8.59:1 white-on-blue for filled elements */

    /* White highlight */
    --white: #ffffff;

    /* Borders */
    --border: #1e3050;
    --border-focus: #5b8dd9;

    /* Feedback */
    --success: #3ddc84;
    --warning: #f5a623;

    /* Layout */
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.6);
    --transition: 0.2s ease;
    --max-width: 1100px;
    --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

/* --- Hidden attribute override --- */
[hidden] {
    display: none !important;
}

/* --- Skip Link --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    background: var(--accent);
    color: var(--accent-text);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    z-index: 1000;
    text-decoration: none;
}

.skip-link:focus {
    top: 1rem;
    outline: 3px solid var(--white);
    outline-offset: 2px;
}

/* --- Focus (AA) --- */
:focus-visible {
    outline: 3px solid var(--blue);
    outline-offset: 2px;
}

/* --- Header — Navy with red bottom stripe --- */
.site-header {
    background: var(--bg-secondary);
    border-bottom: 3px solid var(--accent);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 4px;
}

.logo-name {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.logo-accent { color: var(--accent); }

.logo-tagline {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
}

.site-nav ul {
    display: flex;
    list-style: none;
    gap: 0.25rem;
}

.site-nav a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: color var(--transition), background var(--transition);
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
    color: var(--white);
    background: var(--blue-muted);
}

/* --- Sections --- */
.section {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.section-narrow { max-width: 720px; }

/* --- Hero --- */
.hero {
    text-align: center;
    padding: 3rem 1.5rem 2rem;
    max-width: var(--max-width);
    margin: 0 auto;
}

.hero h1 {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.text-accent { color: var(--accent); }

.lead {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 540px;
    margin: 0 auto 2rem;
}

/* --- Search Form --- */
.search-form { max-width: 600px; margin: 0 auto; }
.search-form fieldset { border: none; }

.search-form legend {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.search-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-row label {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.search-row input[type="text"] {
    flex: 1;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition);
}

.search-row input[type="text"]::placeholder { color: var(--text-muted); }

.search-row input[type="text"]:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 3px var(--blue-muted);
}

.search-options {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.search-options label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.search-options select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.search-options select:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 3px var(--blue-muted);
}

.btn-locate {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

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

/* Red button with dark navy text — 5.02:1 contrast */
.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Blue outline button */
.btn-secondary {
    background: transparent;
    color: var(--blue);
    border-color: var(--border);
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
    border-color: var(--blue);
    background: var(--blue-muted);
}

/* --- Status Messages --- */
.status-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: var(--max-width);
    margin: 0 auto;
}

.status-message.error { color: var(--accent); }

/* --- Results --- */
.results-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.results-header h2 { font-size: 1.3rem; font-weight: 600; }
.results-count { font-size: 0.9rem; color: var(--text-muted); }

/* --- Shelter Card --- */
.shelter-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.shelter-card:hover {
    border-color: var(--blue);
    box-shadow: var(--shadow);
}

.shelter-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.shelter-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

/* Blue distance badge */
.shelter-distance {
    font-size: 0.85rem;
    color: var(--blue);
    font-weight: 600;
    white-space: nowrap;
    background: var(--blue-muted);
    padding: 0.25rem 0.65rem;
    border-radius: 100px;
}

.shelter-meta {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.shelter-meta span {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.meta-icon {
    flex-shrink: 0;
    width: 1.1em;
    text-align: center;
}

/* Red left border on mission */
.shelter-mission {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.shelter-links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.shelter-link {
    font-size: 0.85rem;
    color: var(--blue);
    text-decoration: none;
    font-weight: 600;
}

.shelter-link:hover {
    text-decoration: underline;
    color: var(--blue-hover);
}

/* --- Action Grid — alternating red & blue accents --- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.75rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    text-align: center;
    line-height: 1.3;
    transition: all var(--transition);
}

.action-btn:hover,
.action-btn:focus-visible {
    background: var(--blue-muted);
    border-color: var(--blue);
    color: var(--text-primary);
    transform: translateY(-1px);
}

/* Alternate: every other action btn hovers red instead */
.action-btn:nth-child(even):hover,
.action-btn:nth-child(even):focus-visible {
    background: var(--accent-muted);
    border-color: var(--accent);
}

.action-icon { font-size: 1.3rem; }
.action-label { font-weight: 600; }

/* --- Actions Explainer --- */
.actions-explainer {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-top: 2rem;
}

.actions-explainer h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.actions-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.actions-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.action-li-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.actions-list strong { color: var(--text-primary); }

/* --- Help Page --- */
.help-section {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    scroll-margin-top: 5rem;
}

.help-section:last-child { border-bottom: none; }

.help-section h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.help-section p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.help-section p:last-child { margin-bottom: 0; }

.help-section a {
    color: var(--blue);
    text-decoration: none;
}

.help-section a:hover {
    text-decoration: underline;
    color: var(--blue-hover);
}

.help-section strong { color: var(--text-primary); }

/* --- Loading Spinner — red spinner on blue track --- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* --- Demo Banner --- */
.demo-banner {
    background: var(--blue-deep);
    color: var(--white);
    text-align: center;
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.demo-banner a { color: var(--white); text-decoration: underline; }

/* --- Footer — Navy with subtle top border --- */
.site-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 3rem;
}

.site-footer a {
    color: var(--blue);
    text-decoration: none;
}

.site-footer a:hover { text-decoration: underline; }
.footer-note { margin-top: 0.25rem; }

/* --- Responsive --- */
@media (max-width: 640px) {
    .header-inner { flex-direction: column; text-align: center; }
    .search-row { flex-direction: column; }
    .search-row .btn { width: 100%; }
    .shelter-card-header { flex-direction: column; }
    .action-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .hero { padding: 2rem 1rem 1.5rem; }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- Print --- */
@media print {
    .site-header, .site-footer, .search-form, .action-grid, .skip-link { display: none; }
    body { background: #fff; color: #111; }
    .shelter-card { border: 1px solid #ccc; break-inside: avoid; }
}