/* ==========================================================================
   Base Styles & Variables
   ========================================================================== */

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background-color: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --transition-fast: 150ms ease;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--background-color);
}

/* ==========================================================================
   Header
   ========================================================================== */

header {
    background: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
}

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

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

.header-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.alert-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-form label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.alert-form input[type="number"] {
    width: 90px;
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
}

.alert-form input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.alert-form button {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info span {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.back-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.8rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn,
button {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.btn-primary,
button[type="submit"] {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover,
button[type="submit"]:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

/* ==========================================================================
   Main Layout
   ========================================================================== */

main {
    padding: 0;
}

.secondary-header {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-color);
    position: sticky;
    top: 0;
    z-index: 5;
}

.secondary-header-left {
    flex: 0 0 auto;
    width: 380px;
    min-width: 260px;
    max-width: 60vw;
    padding-right: 0;
    padding-left: 1rem;
    border-right: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.secondary-header-right {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: stretch;
}

.alert-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.page-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.75rem 0;
}

.app-layout {
    display: flex;
    gap: 1.5rem;
    height: calc(100vh - 100px);
    padding: 1rem 1rem 1rem;
}

.config-column {
    flex: 0 0 auto;
    width: 380px;
    min-width: 260px;
    max-width: 60vw;
    resize: horizontal;
    overflow: auto;
    padding-right: 1rem;
    border-right: 1px solid var(--border-color);
}

.documents-column {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
}

/* ==========================================================================
   Document Cards
   ========================================================================== */

.document {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
}

.document:last-child {
    border-bottom: none;
}

.document-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: none;
    padding: 0;
}

.document-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
}

.document-title a {
    color: #0369a1;
    text-decoration: none;
}

.document-title a:hover {
    text-decoration: underline;
}

.go-badge {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 500;
}

.document-content {
    margin-bottom: 0.5rem;
}

.document-text {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.document-meta {
    margin-top: 0.5rem;
}

.document-explanations {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.document-explanations summary {
    cursor: pointer;
    color: var(--text-muted);
}

.document-explanations summary:hover {
    color: var(--text-secondary);
}

.document-explanations p {
    margin: 0.5rem 0 0 0;
}

.end-of-documents {
    padding: 1rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

@media (max-width: 900px) {
    .secondary-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .secondary-header-left {
        width: 100%;
        min-width: 0;
        max-width: none;
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
        padding-left: 1rem;
    }

    .secondary-header-right {
        width: 100%;
    }

    .app-layout {
        flex-direction: column;
        height: auto;
    }

    .config-column {
        flex: none;
        width: 100%;
        min-width: 0;
        max-width: none;
        resize: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-right: 0;
        padding-bottom: 1rem;
    }
}

/* ==========================================================================
   Empty States
   ========================================================================== */

.empty-state {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.loading-text,
.placeholder-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==========================================================================
   Config Panel
   ========================================================================== */

.config-panel h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.config-section {
    margin-bottom: 1.25rem;
}

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

.config-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ==========================================================================
   Keywords
   ========================================================================== */

.keywords-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.keyword-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    background-color: transparent;
    color: var(--text-primary);
    font-size: 0.8rem;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.keyword-tag:hover {
    background-color: transparent;
}

.keyword-label {
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.keyword-tag button {
    background-color: transparent;
    color: inherit;
    border: none;
}

.keyword-tag button:hover {
    background-color: transparent;
}

.keyword-label:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.keyword-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    margin-left: 0.15rem;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
    border: none;
    border-radius: 2px;
    cursor: pointer;
}

.keyword-tag:hover .keyword-delete {
    display: inline-flex;
}

.keyword-delete:hover {
    background-color: var(--danger-color);
    color: white;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */

.form-group {
    margin-bottom: 0.75rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

/* Model Select */
.model-select-wrapper {
    position: relative;
    width: 100%;
}

.model-select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background-color: white;
    color: var(--text-primary);
    cursor: pointer;
}

.model-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Model Tooltip */
.model-tooltip {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    background-color: var(--text-primary);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity var(--transition-fast),
        visibility var(--transition-fast);
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.model-tooltip::before {
    content: "";
    position: absolute;
    left: 12px;
    bottom: 100%;
    border: 6px solid transparent;
    border-bottom-color: var(--text-primary);
}

.model-select-wrapper:hover .model-tooltip {
    opacity: 1;
    visibility: visible;
}

.model-tooltip a {
    color: #93c5fd;
    text-decoration: none;
}

.model-tooltip a:hover {
    color: white;
    text-decoration: underline;
}

.model-tooltip-label {
    color: var(--text-muted);
    margin-right: 0.25rem;
}

/* Prompt Textarea */
.prompt-input {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.5;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background-color: white;
    color: var(--text-primary);
    resize: vertical;
    min-height: 40px;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.prompt-input::placeholder {
    color: var(--text-muted);
}

/* ==========================================================================
   View Transitions
   ========================================================================== */

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.15s;
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==========================================================================
   Progress Indicator
   ========================================================================== */

.progress-container {
    padding: 0.5rem;
    background: #f0f9ff;
    border-left: 2px solid #0ea5e9;
    margin-bottom: 0;
    font-size: 0.8rem;
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

#progress-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.progress-text {
    color: #0369a1;
}

.progress-container .loader {
    display: none;
}

.progress-container.stream-active .loader {
    display: grid;
}

/* HTML: <div class="loader"></div> */
.loader {
    width: 1em;
    aspect-ratio: 1;
    display: grid;
    border-radius: 50%;
    background:
        linear-gradient(
                0deg,
                rgb(0 0 0 / 50%) 30%,
                #0000 0 70%,
                rgb(0 0 0 / 100%) 0
            )
            50%/8% 100%,
        linear-gradient(
                90deg,
                rgb(0 0 0 / 25%) 30%,
                #0000 0 70%,
                rgb(0 0 0 / 75%) 0
            )
            50%/100% 8%;
    background-repeat: no-repeat;
    animation: l23 1s infinite steps(12);
}

.loader::before,
.loader::after {
    content: "";
    grid-area: 1/1;
    border-radius: 50%;
    background: inherit;
    opacity: 0.915;
    transform: rotate(30deg);
}

.loader::after {
    opacity: 0.83;
    transform: rotate(60deg);
}

@keyframes l23 {
    100% {
        transform: rotate(1turn);
    }
}

/* ==========================================================================
   Keyword Count
   ========================================================================== */

.keyword-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 0.35rem;
    background-color: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9px;
}

/* ==========================================================================
   Login Page
   ========================================================================== */

.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-container h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 1.5rem 0;
    padding: 0;
    color: var(--text-primary);
    text-align: center;
    width: 320px;
}

.login-container form {
    width: 320px;
    margin: 0;
    padding: 0;
}

.login-container .info-message {
    width: 320px;
    padding: 0.75rem;
    margin: 0 0 1rem 0;
    background-color: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 3px;
    font-size: 0.85rem;
    box-sizing: border-box;
    line-height: 1.6;
}

.login-container .info-message p {
    margin: 0;
}

.login-container .info-message strong {
    color: #1e3a8a;
}

.login-container .error-message {
    width: 320px;
    padding: 0.75rem;
    margin: 0 0 1rem 0;
    background-color: #fee2e2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
    border-radius: 3px;
    font-size: 0.85rem;
    box-sizing: border-box;
}

.login-container .form-group {
    margin-bottom: 1rem;
}

.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background-color: white;
    color: var(--text-primary);
    box-sizing: border-box;
}

.login-container input[type="text"]:focus,
.login-container input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.login-container button[type="submit"] {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.5rem;
}
