* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f4f6fb;
    color: #1f2933;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2.5rem clamp(1.5rem, 4vw, 4rem);
    background: linear-gradient(135deg, #0f172a, #1e293b);
    color: #fff;
    gap: 1.5rem;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 2.8rem);
    font-weight: 600;
}

.app-header p {
    margin: 0.5rem 0 0;
    max-width: 40rem;
    color: rgba(255, 255, 255, 0.75);
}

.app-header .header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    font-weight: 500;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem clamp(1.5rem, 4vw, 4rem);
    background: #fff;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
    position: sticky;
    top: 0;
    z-index: 900;
}

.logo-link {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #0f172a;
}

.logo-link:hover {
    color: #2563eb;
    text-decoration: none;
}

.logo-link--light {
    color: #fff;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.logo-link--light:hover {
    color: rgba(255, 255, 255, 0.85);
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-bar-actions select {
    min-width: 200px;
    padding: 0.6rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: #fff;
}

.app-shell {
    flex: 1;
    display: flex;
    min-height: 0;
    background: #f4f6fb;
}

.sidebar {
    width: 260px;
    background: #0f172a;
    color: #fff;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: 12px 0 32px rgba(15, 23, 42, 0.18);
    flex-shrink: 0;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-group:last-child {
    margin-top: auto;
}

.sidebar-label {
    margin: 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
}

.sidebar-user {
    margin: 0;
    font-weight: 600;
    word-break: break-word;
}

.sidebar-link {
    display: block;
    padding: 0.6rem 0 0.6rem 0.4rem;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
    border-left: 3px solid transparent;
}

.sidebar-link:hover,
.sidebar-link:focus {
    color: #fff;
    text-decoration: none;
}

.sidebar-link.active {
    color: #fff;
    font-weight: 700;
    padding-left: 0.4rem;
    border-left: 3px solid rgba(255, 255, 255, 0.7);
}

.sidebar-button {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.sidebar-button + .sidebar-button {
    margin-top: 0.75rem;
}

.logout-button {
    margin-top: 0.5rem;
}

.page-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.page-heading {
    margin-bottom: 2rem;
}

.page-heading h1 {
    margin: 0.5rem 0 0.75rem;
    font-size: clamp(2rem, 4vw, 2.6rem);
    font-weight: 600;
    color: #0f172a;
}

.page-heading p {
    margin: 0;
    color: #4b5563;
}

main {
    padding: clamp(1.5rem, 4vw, 4rem);
    flex: 1;
}

.projects h2,
.brand-meta h2,
.metrics h2,
.qa-section h2 {
    margin: 0 0 1.5rem;
    font-size: 1.5rem;
    color: #111827;
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}

.project-card {
    background: #fff;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.project-card h3 {
    margin: 0;
    font-size: 1.25rem;
}

.project-card p {
    margin: 0;
    color: #4b5563;
    min-height: 4rem;
}

.project-card dl {
    display: grid;
    gap: 0.75rem;
    margin: 0;
}

.project-card dt {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    color: #94a3b8;
}

.project-card dd {
    margin: 0.25rem 0 0;
    font-weight: 500;
    color: #1f2933;
}

.primary,
.secondary,
.danger,
.ghost,
.icon {
    border: none;
    border-radius: 999px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.3);
}

.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 32px rgba(37, 99, 235, 0.35);
}

.primary.ghost {
    background: rgba(37, 99, 235, 0.15);
    color: #1e3a8a;
    box-shadow: none;
}

.primary.ghost:hover {
    background: rgba(37, 99, 235, 0.25);
}

.secondary {
    background: #fff;
    color: #1f2933;
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.secondary:hover {
    background: #f1f5f9;
}

.danger {
    background: #ef4444;
    color: #fff;
    box-shadow: 0 12px 24px rgba(239, 68, 68, 0.25);
}

.danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 32px rgba(239, 68, 68, 0.3);
}

.danger.ghost {
    background: rgba(239, 68, 68, 0.12);
    color: #991b1b;
    box-shadow: none;
}

.danger.ghost:hover {
    background: rgba(239, 68, 68, 0.18);
}

.icon {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    font-size: 1.5rem;
    line-height: 1;
    background: transparent;
    color: #64748b;
}

.icon:hover {
    background: rgba(148, 163, 184, 0.15);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #fff;
    border-radius: 20px;
    max-width: 520px;
    width: 100%;
    padding: 2.5rem;
    box-shadow: 0 32px 64px rgba(15, 23, 42, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-content header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-content h2 {
    margin: 0;
    font-size: 1.75rem;
}

#create-project-form {
    display: grid;
    gap: 1rem;
}

label {
    display: grid;
    gap: 0.5rem;
    font-size: 0.95rem;
    color: #1f2933;
}

input[type="text"],
textarea,
select {
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    transition: border 0.15s ease;
    font-family: inherit;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

textarea {
    resize: vertical;
}

.form-hint {
    margin: 0;
    font-size: 0.9rem;
    color: #64748b;
}

.form-hint.small {
    font-size: 0.8rem;
}

.hidden {
    display: none !important;
}

.empty-state {
    background: rgba(148, 163, 184, 0.12);
    border-radius: 16px;
    padding: 1.2rem 1.5rem;
    color: #4b5563;
}

.project-view {
    display: grid;
    gap: 2rem;
}

.audit-view {
    display: grid;
    gap: 2rem;
}

.competitor-view {
    display: grid;
    gap: 2rem;
}

.prompt-view {
    display: grid;
    gap: 2rem;
}

.brand-meta dl {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 0;
    background: #fff;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.brand-meta dt {
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 600;
    color: #94a3b8;
}

.brand-meta dd {
    margin: 0.25rem 0 0;
    font-size: 1.1rem;
    font-weight: 500;
    color: #1f2933;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.metric-card {
    background: #fff;
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.metric-card h3 {
    margin: 0;
    font-size: 1rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0.5rem 0;
    color: #0f172a;
}

.metric-caption {
    margin: 0;
    color: #4b5563;
}

.metric-card .chart-container {
    position: relative;
    width: 100%;
    height: 220px;
}

.metric-card .chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.optimization-view {
    display: grid;
    gap: 2rem;
}

.optimization-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.optimization-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 1rem;
}

.suggestion-list {
    display: grid;
    gap: 1rem;
}

.suggestion-card {
    background: #fff;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    display: grid;
    gap: 0.75rem;
    border-left: 4px solid #2563eb;
}

.suggestion-card.tech {
    border-left-color: #f97316;
}

.suggestion-card.trust {
    border-left-color: #10b981;
}

.suggestion-card h3 {
    margin: 0;
    font-size: 1.05rem;
    color: #0f172a;
}

.suggestion-card p {
    margin: 0;
    color: #475569;
    line-height: 1.5;
}

.suggestion-card ul {
    margin: 0;
    padding-left: 1.2rem;
    color: #475569;
    display: grid;
    gap: 0.4rem;
}

.mentions-trend .chart-container {
    position: relative;
    width: 100%;
    height: 320px;
}

.mentions-trend .chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.audit-sentiment .chart-container {
    position: relative;
    width: 100%;
    height: 320px;
}

.audit-sentiment .chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.technical-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.technical-section .section-header button {
    white-space: nowrap;
}

.prompt-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.prompt-controls label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.95rem;
    color: #64748b;
    margin: 0;
}

.prompt-controls select {
    min-width: 220px;
}

.qa-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.audit-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.audit-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#audit-selector {
    min-width: 200px;
}

.run-date {
    font-size: 0.95rem;
    color: #64748b;
}

.qa-list {
    display: grid;
    gap: 1.5rem;
}

.qa-card {
    background: #fff;
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    border: 1px solid transparent;
    transition: transform 0.15s ease, border 0.15s ease;
}

.qa-card h3 {
    margin: 0 0 0.75rem;
    font-size: 1.2rem;
    color: #1f2933;
}

.qa-card p {
    margin: 0;
    line-height: 1.55;
    color: #4b5563;
}

.qa-card.highlight {
    border-color: rgba(37, 99, 235, 0.35);
    transform: translateY(-2px);
}

.table-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.benchmark-table {
    width: 100%;
    border-collapse: collapse;
}

.benchmark-table thead {
    background: #0f172a;
    color: #fff;
}

.benchmark-table th,
.benchmark-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.benchmark-table tbody tr:last-child td {
    border-bottom: none;
}

.benchmark-table tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.02);
}

.mentions-column {
    text-align: right;
    width: 180px;
}

.benchmark-table td.mentions-column {
    font-weight: 600;
}

.empty-state-row {
    text-align: center;
    padding: 2rem 1rem;
    color: #64748b;
}

.prompt-table td:first-child {
    max-width: 640px;
    white-space: normal;
}

.audit-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    padding: 0.25rem 0.75rem;
    background: rgba(37, 99, 235, 0.15);
    color: #1e3a8a;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 999px;
}

.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #0f172a, #1e293b);
}

.auth-card {
    width: min(480px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 2.5rem;
    box-shadow: 0 32px 64px rgba(15, 23, 42, 0.25);
    display: grid;
    gap: 1.5rem;
}

.auth-card h1 {
    margin: 0;
    font-size: 1.8rem;
    color: #0f172a;
}

.auth-subtitle {
    margin: 0;
    color: #4b5563;
}

.auth-toggle {
    display: inline-flex;
    align-self: center;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 999px;
    padding: 0.25rem;
    gap: 0.25rem;
}

.auth-toggle-button {
    border: none;
    background: transparent;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    color: #1f2933;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.auth-toggle-button.active {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
}

.auth-toggle-button:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.auth-messages {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
}

.auth-messages.error {
    background: rgba(239, 68, 68, 0.12);
    color: #991b1b;
}

.auth-form {
    display: grid;
    gap: 1rem;
}

.auth-form label input {
    border-radius: 12px;
}

.auth-form button {
    width: 100%;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: grid;
    place-items: center;
    z-index: 2000;
}

.loading-card {
    background: #fff;
    border-radius: 20px;
    padding: 2rem 2.5rem;
    display: grid;
    justify-items: center;
    gap: 1.25rem;
    box-shadow: 0 32px 64px rgba(15, 23, 42, 0.25);
    text-align: center;
}

.loading-overlay[hidden] {
    display: none !important;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(37, 99, 235, 0.15);
    border-top-color: #2563eb;
    border-radius: 999px;
    animation: spin 1s linear infinite;
}

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

.back-link {
    color: #2563eb;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.back-link:hover {
    color: #1d4ed8;
}

@media (max-width: 900px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }

    .app-header .header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }

    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .top-bar-actions {
        width: 100%;
    }

    .top-bar-actions select {
        width: 100%;
    }

    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
        box-shadow: none;
    }

    .sidebar-group {
        flex: 1 1 200px;
    }

    .sidebar-group:last-child {
        margin-top: 0;
    }
}

@media (max-width: 600px) {
    .metric-value {
        font-size: 2rem;
    }

    .qa-card {
        padding: 1.25rem;
    }

    .app-header {
        padding: 2rem 1.5rem;
    }

    .top-bar {
        padding: 1rem 1.5rem;
    }

    .sidebar {
        padding: 1.5rem 1.25rem;
    }

    main {
        padding: 1.5rem;
    }
}
