/* Small Towns AI — WCAG 2.1 AA compliant styles */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-primary: #0b3d6e;
    --color-primary-dark: #092e54;
    --color-primary-hover: #0a3562;
    --color-text: #1a1a2e;
    --color-text-light: #4a4a5e;
    --color-bg: #f3f4f6;
    --color-white: #ffffff;
    --color-border: #d0d5dd;
    --color-focus: #2563eb;
    --color-error: #b91c1c;
    --color-error-bg: #fef2f2;
    --color-success: #166534;
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.5);
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 16px;
    background: var(--color-primary);
    color: var(--color-white);
    padding: 12px 24px;
    border-radius: 0 0 8px 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    z-index: 1000;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
}

/* Header */
.header {
    background: var(--color-primary);
    color: var(--color-white);
    padding: 20px 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-seal {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}
.header-seal svg {
    width: 100%;
    height: 100%;
}
.header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.header .subtitle {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 1px;
    font-weight: 400;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header .badge {
    background: rgba(255,255,255,0.25);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-white);
    border: 1px solid rgba(255,255,255,0.5);
}
.staff-link {
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.4);
    transition: all 0.2s;
}
.staff-link:hover {
    background: rgba(255,255,255,0.15);
    color: var(--color-white);
}
.staff-link:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Tab bar / Navigation */
.tab-nav {
    background: var(--color-primary-dark);
    padding: 0 40px;
    display: flex;
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab-nav [role="tab"] {
    background: none;
    border: none;
    color: rgba(255,255,255,0.65);
    font-size: 14px;
    font-weight: 600;
    padding: 14px 24px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.15s;
}
.tab-nav [role="tab"]:hover {
    color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.05);
}
.tab-nav [role="tab"]:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: -3px;
}
.tab-nav [role="tab"][aria-selected="true"] {
    color: var(--color-white);
    border-bottom-color: #4da3ff;
}

/* Main container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 36px 24px;
}

/* Search form */
.search-form {
    margin-bottom: 16px;
}
.search-form label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-light);
    margin-bottom: 8px;
}
.search-input-wrapper {
    position: relative;
}
.search-input-wrapper input[type="text"] {
    width: 100%;
    padding: 16px 130px 16px 20px;
    font-size: 17px;
    border: 2px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-white);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    color: var(--color-text);
}
.search-input-wrapper input[type="text"]:focus {
    outline: none;
    border-color: var(--color-focus);
    box-shadow: var(--focus-ring);
}
.search-input-wrapper input[type="text"]::placeholder {
    color: #767676; /* 4.5:1 contrast on white */
}
.search-input-wrapper button[type="submit"] {
    position: absolute;
    right: 8px;
    top: 8px;
    bottom: 8px;
    padding: 0 28px;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.search-input-wrapper button[type="submit"]:hover {
    background: var(--color-primary-hover);
}
.search-input-wrapper button[type="submit"]:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}
.search-input-wrapper button[type="submit"]:disabled {
    background: #6b7280;
    cursor: not-allowed;
}

/* Example chips */
.examples {
    display: flex;
    gap: 8px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}
.examples button {
    padding: 7px 15px;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.examples button:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: #eef3fa;
}
.examples button:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Answer panel */
.answer-panel {
    background: var(--color-white);
    border-radius: 12px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08);
    overflow: hidden;
    display: none;
}
.answer-panel.visible { display: block; }

.answer-header {
    padding: 16px 24px;
    background: #f8fafe;
    border-bottom: 1px solid #e8edf2;
    display: flex;
    align-items: center;
    gap: 12px;
}
.answer-header .icon {
    width: 30px;
    height: 30px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}
.answer-header .title {
    font-weight: 600;
    font-size: 15px;
    color: #333;
}

.answer-body {
    padding: 24px;
    font-size: 16px;
    line-height: 1.75;
    color: #2a2a3e;
}
.answer-body p { margin-bottom: 12px; }
.answer-body p:last-child { margin-bottom: 0; }
.answer-body h1, .answer-body h2, .answer-body h3 {
    margin: 18px 0 8px;
    color: var(--color-text);
}
.answer-body h1 { font-size: 22px; }
.answer-body h2 { font-size: 19px; }
.answer-body h3 { font-size: 17px; }
.answer-body ul, .answer-body ol {
    margin: 8px 0 12px 24px;
}
.answer-body li { margin-bottom: 5px; }
.answer-body strong { color: var(--color-text); }

/* Citation links */
.cite-link {
    color: var(--color-primary);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    vertical-align: super;
    line-height: 0;
    padding: 0 1px;
}
.cite-link:hover,
.cite-link:focus {
    text-decoration: underline;
    outline: none;
}
.cite-link:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 1px;
}

/* Loading state */
.loading {
    padding: 44px 24px;
    text-align: center;
    color: var(--color-text-light);
}
.loading .spinner {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Sources */
.sources {
    border-top: 1px solid #e8edf2;
    padding: 18px 24px;
    background: #fafbfc;
}
.sources-title {
    font-size: 12px;
    font-weight: 700;
    color: #595959; /* 4.5:1 on #fafbfc */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}
.source-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    font-size: 14px;
    transition: background 0.2s;
    border-radius: 6px;
    margin: 0 -8px;
}
.source-item.highlight {
    background: #eef3fa;
}
.source-item a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-item a:hover { text-decoration: underline; }
.source-item a:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}
.source-item .num {
    background: #e8edf2;
    color: #333;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}
.source-item .jurisdiction-badge {
    background: #e8f0fe;
    color: var(--color-primary);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Error state */
.error-msg {
    padding: 24px;
    color: var(--color-error);
    background: var(--color-error-bg);
    border-radius: 8px;
    font-size: 15px;
}

/* Stats */
.stats {
    display: flex;
    gap: 20px;
    padding: 10px 24px 14px;
    font-size: 13px;
    color: var(--color-text-light);
}

/* Footer */
.footer {
    text-align: center;
    padding: 32px 24px;
    font-size: 13px;
    color: #595959;
}

/* Responsive */
@media (max-width: 640px) {
    .header { padding: 16px 18px; }
    .header-seal { width: 36px; height: 36px; }
    .header h1 { font-size: 18px; }
    .header .subtitle { font-size: 12px; }
    .tab-nav { padding: 0 12px; }
    .tab-nav [role="tab"] { padding: 12px 16px; font-size: 13px; }
    .container { padding: 24px 14px; }
    .search-input-wrapper input[type="text"] { padding: 14px 100px 14px 16px; font-size: 16px; }
    .search-input-wrapper button[type="submit"] { padding: 0 18px; font-size: 15px; }
    .answer-body { padding: 20px 18px; }
    .sources { padding: 14px 18px; }
    .examples button { font-size: 12px; padding: 6px 12px; }
}
