:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-text: #212529;
    --color-muted: #6c757d;
    --color-primary: #0d6efd;
    --color-primary-hover: #0b5ed7;
    --color-success: #198754;
    --color-danger: #dc3545;
    --color-warning: #f59e0b;
    --border-radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --max-width: 960px;

    /* Filter panel */
    --filter-control-height: 38px;
    --filter-border-radius: 6px;
    --filter-border: 1px solid #d0d0d0;
    --filter-label-color: #666;
    --filter-label-size: 12.5px;
    --filter-gap: 8px;
    --filter-group-gap: 24px;

    /* History table */
    --history-border-color: #eceef1;
    --history-zebra-bg: #f8f9fa;
    --history-hover-bg: #f3f4f6;
    --history-head-color: #6b7280;
    --history-secondary-color: #6b7280;
    --history-time-color: #9ca3af;
    --history-text-color: #111827;
    --history-link-hover: #2563eb;
    --history-cell-padding-y: 12px;
    --history-cell-padding-x: 16px;
    --history-actions-gap: 8px;
    --history-action-size: 32px;
    --history-action-color: #6b7280;
    --history-action-hover-bg: #f3f4f6;
    --history-verdict-bg: #e8f5ee;
    --history-verdict-color: #1e7e4a;
    --history-verdict-danger-bg: #fdecea;
    --history-verdict-danger-color: #b42318;
    --history-score-warning-bg: #fef3e2;
    --history-score-warning-color: #b45309;
    --history-dot-success: #16a34a;
    --history-dot-danger: #dc2626;
    --history-dot-warning: #d97706;
    --history-dot-muted: #9ca3af;
    --history-badge-min-width: 80px;
    --history-badge-font-size: 0.8rem;

    /* Bootstrap theme mapping */
    --bs-primary: var(--color-primary);
    --bs-primary-rgb: 13, 110, 253;
    --bs-body-bg: var(--color-bg);
    --bs-body-color: var(--color-text);
    --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

main {
    flex: 1;
    padding: 2rem 0;
}

/* Brand layout overrides: fixed content width and page structure */
.container {
    max-width: var(--max-width);
}

/* Markdown result rendering */
.markdown-body {
    line-height: 1.7;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.markdown-body p {
    margin-bottom: 0.75rem;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.25rem;
}

.markdown-body strong {
    font-weight: 700;
}

.markdown-body em {
    font-style: italic;
}

.markdown-body code {
    background: #f1f3f5;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.markdown-body pre {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
}

.markdown-body blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: 1rem;
    margin-left: 0;
    color: var(--color-muted);
}

.markdown-body hr {
    border: none;
    border-top: 1px solid #e9ecef;
    margin: 1.25rem 0;
}

.actions-cell {
    white-space: nowrap;
}

/* History table — grid, zebra, quiet pills, ghost actions */
.history-table {
    table-layout: fixed;
    margin-bottom: 0;
}

.history-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fff;
    border-bottom: 1px solid var(--history-border-color);
    padding: 8px var(--history-cell-padding-x);
    font-size: 12.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--history-head-color);
    white-space: nowrap;
}

.history-table tbody td {
    border-bottom: none;
    padding: var(--history-cell-padding-y) var(--history-cell-padding-x);
    color: var(--history-text-color);
    font-size: 14px;
    line-height: 1.5;
}

.history-table tbody tr:nth-child(even) {
    background: var(--history-zebra-bg);
}

.history-table tbody tr:hover {
    background: var(--history-hover-bg);
    transition: background-color 150ms;
}

.history-table tbody tr[data-href] {
    cursor: pointer;
}

.history-table tbody tr:focus-visible {
    outline: 2px solid var(--history-link-hover);
    outline-offset: -2px;
}

.history-col-date { width: 110px; }
.history-col-vacancy { width: auto; min-width: 320px; }
.history-col-verdict { width: 150px; }
.history-col-score { width: 90px; }
.history-col-response { width: 150px; }
.history-col-actions { width: 100px; }

/* Date: day on the first line, time small on the second */
.history-date {
    white-space: nowrap;
}

.history-date-day {
    display: block;
    font-size: 14px;
    line-height: 1.5;
}

.history-date-time {
    display: block;
    font-size: 12px;
    color: var(--history-time-color);
}

/* Vacancy: one-line name, small subtitle, quiet link, hover-only ext icon */
.history-vacancy-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-vacancy-name a {
    color: inherit;
    text-decoration: none;
}

.history-vacancy-name a:hover {
    color: var(--history-link-hover);
    text-decoration: underline;
}

.history-vacancy-subtitle {
    font-size: 12px;
    color: var(--history-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vacancy-ext-link {
    color: var(--color-muted);
    text-decoration: none;
    line-height: 1;
    padding-top: 2px;
    visibility: hidden;
}

tbody tr:hover .vacancy-ext-link,
tbody tr:focus-within .vacancy-ext-link {
    visibility: visible;
}

.vacancy-ext-link:hover {
    color: var(--color-primary);
}

/* Score pill by range */
.score-pill {
    display: inline-block;
    min-width: 44px;
    padding: 2px 10px;
    border-radius: 999px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.score-pill--success { background: var(--history-verdict-bg); color: var(--history-verdict-color); }
.score-pill--warning { background: var(--history-score-warning-bg); color: var(--history-score-warning-color); }
.score-pill--danger { background: var(--history-verdict-danger-bg); color: var(--history-verdict-danger-color); }

/* Verdict pill, muted */
.verdict-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.verdict-pill--success { background: var(--history-verdict-bg); color: var(--history-verdict-color); }
.verdict-pill--danger { background: var(--history-verdict-danger-bg); color: var(--history-verdict-danger-color); }

/* Response status: label with a colored dot */
.status-with-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot--success { background: var(--history-dot-success); }
.status-dot--danger { background: var(--history-dot-danger); }
.status-dot--warning { background: var(--history-dot-warning); }
.status-dot--muted { background: var(--history-dot-muted); }

/* Empty placeholder for score/verdict/status */
.history-empty {
    color: var(--history-time-color);
    font-size: 12px;
}

.history-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--history-action-size);
    height: var(--history-action-size);
}

.history-loader.htmx-request {
    opacity: 1;
}

/* Actions: ghost round buttons + <details> "more" menu */
.history-actions {
    display: flex;
    gap: var(--history-actions-gap);
    flex-wrap: nowrap;
    align-items: center;
}

.history-actions .btn {
    width: var(--history-action-size);
    height: var(--history-action-size);
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--history-action-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.history-actions .btn:hover {
    background: var(--history-action-hover-bg);
    color: var(--history-action-color);
}

.history-actions .btn:focus-visible {
    outline: 2px solid var(--history-link-hover);
    outline-offset: 2px;
}

.history-more {
    position: relative;
    display: inline-block;
}

.history-more > summary {
    list-style: none;
    width: var(--history-action-size);
    height: var(--history-action-size);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--history-action-color);
    cursor: pointer;
    user-select: none;
}

.history-more > summary::-webkit-details-marker {
    display: none;
}

.history-more > summary:hover,
.history-more[open] > summary {
    background: var(--history-action-hover-bg);
}

.history-more > summary:focus-visible {
    outline: 2px solid var(--history-link-hover);
    outline-offset: 2px;
}

.history-more-menu {
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--history-border-color);
    border-radius: 8px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    padding: 4px;
    margin-top: 4px;
}

@media (min-width: 1024px) {
    /* the grid fits without horizontal scrolling — let the dropdown overlay the table */
    .history-responsive {
        overflow: visible;
    }

    .history-more-menu {
        position: absolute;
        right: 0;
        top: calc(100% + 4px);
        z-index: 10;
        margin-top: 0;
    }
}

.history-more-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--history-text-color);
    font-size: 14px;
    text-align: left;
    white-space: nowrap;
}

.history-more-item:hover {
    background: var(--history-action-hover-bg);
}

/* Deleted rows keep a quiet red tint above zebra/hover */
.history-table tbody tr.table-danger {
    background: #fdf2f3;
}

.history-table tbody tr.table-danger:hover {
    background: #fbe7e9;
}

/* Ellipsis containers need a shrinkable flex basis */
.history-table td .flex-grow-1,
.history-card-name {
    min-width: 0;
}

/* Mobile card view (<768px) */
.history-cards {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.history-card {
    background: var(--color-surface);
    border: 1px solid var(--history-border-color);
    border-radius: var(--border-radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-card--deleted {
    border-color: #f5c2c7;
    background: #fdf2f3;
}

.history-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.history-card-name {
    font-weight: 600;
    min-width: 0;
}

.history-card-name a {
    color: inherit;
    text-decoration: none;
}

.history-card-name a:hover {
    color: var(--history-link-hover);
    text-decoration: underline;
}

.history-card-name .history-vacancy-name {
    font-weight: 600;
}

.history-card-meta {
    font-size: 12px;
    color: var(--history-secondary-color);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.history-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

/* Adaptivity: compact table on tablets, cards on phones */
@media (max-width: 1023.98px) {
    .history-date-time {
        display: none;
    }

    .history-table {
        min-width: 720px;
    }

    .history-table tbody td {
        padding: 10px 12px;
    }

    tbody tr .vacancy-ext-link {
        visibility: visible;
    }
}

@media (max-width: 767.98px) {
    .history-table-wrapper {
        display: none;
    }

    .history-cards {
        display: flex;
    }
}

/* HTMX loading states */
.htmx-request {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.htmx-request .btn::after,
.htmx-request.btn::after {
    content: "";
    position: absolute;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: htmx-spinner 0.75s linear infinite;
}

@keyframes htmx-spinner {
    to {
        transform: rotate(360deg);
    }
}

.htmx-request .form-select,
.htmx-request.form-select {
    background-image: none;
}

/* HTMX swap/indicator helpers */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

/* History filter panel — CSS Grid layout */
.filter-card {
    border: var(--filter-border);
    border-radius: var(--border-radius);
    background: var(--color-surface);
    padding: 16px 20px;
}

.filter-card > summary {
    cursor: pointer;
}

.filter-panel {
    display: grid;
    grid-template-columns: 4fr 5fr 3fr;
    gap: var(--filter-group-gap);
    margin-top: 12px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--filter-gap);
    min-width: 0;
}

.filter-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.filter-label {
    font-size: var(--filter-label-size);
    color: var(--filter-label-color);
    margin-bottom: 4px;
    text-align: left;
    font-weight: 400;
    line-height: 1.2;
}

/* Group: options (checkboxes) */
.filter-options {
    justify-content: center;
}

.filter-options .form-check {
    display: flex;
    align-items: baseline;
    gap: var(--filter-gap);
    margin-bottom: 0;
    padding-left: 0;
}

.filter-options .form-check-input {
    width: 16px;
    height: 16px;
    margin-top: 0;
    margin-left: 0;
    flex-shrink: 0;
}

.filter-options .form-check-label {
    font-size: var(--filter-label-size);
    color: var(--filter-label-color);
}

/* Group: search (two fields in a row) */
.filter-search {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--filter-gap);
    align-content: start;
}

/* Group: score + buttons */
.filter-actions {
    align-content: start;
}

.filter-buttons {
    display: flex;
    gap: var(--filter-gap);
    justify-content: flex-end;
    margin-top: auto;
}

/* Uniform control sizing inside the panel */
.filter-panel .form-control,
.filter-panel .form-select,
.filter-panel .btn {
    height: var(--filter-control-height);
    min-height: var(--filter-control-height);
    border-radius: var(--filter-border-radius);
    border: var(--filter-border);
    font-size: 0.875rem;
}

.filter-panel .ts-control {
    min-height: var(--filter-control-height);
    border-radius: var(--filter-border-radius);
    border: var(--filter-border);
    font-size: 0.875rem;
}

/* Page-size selector moved out of the filter panel */
.page-size-bar {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.page-size-form {
    display: flex;
    align-items: flex-end;
    gap: var(--filter-gap);
}

.page-size-form .form-select {
    width: auto;
    min-width: 70px;
}

/* Mobile: stack groups, full-width buttons */
@media (max-width: 767.98px) {
    .filter-card {
        padding: 12px 14px;
    }

    .filter-panel {
        grid-template-columns: 1fr;
        gap: var(--filter-gap);
    }

    .filter-search {
        grid-template-columns: 1fr;
    }

    .filter-buttons {
        flex-direction: column;
        width: 100%;
    }

    .filter-buttons .btn {
        width: 100%;
    }

    .page-size-bar {
        justify-content: stretch;
    }

    .page-size-form {
        width: 100%;
    }

    .page-size-form .form-select {
        flex: 1;
    }
}

/* Inline response-status editor on history page */
.status-editable {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.status-editable:hover,
.status-editable:focus {
    color: inherit;
    text-decoration: none;
}

.status-editable .edit-icon {
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}

.status-editable:hover .edit-icon,
.status-editable:focus .edit-icon,
.status-editable:focus-within .edit-icon {
    opacity: 1;
}

.status-edit-form {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.status-edit-form .form-select,
.status-edit-form .ts-control {
    width: auto;
    min-width: 160px;
    max-width: 220px;
}

.status-edit-form .ts-control {
    min-height: auto;
    padding-top: 0.125rem;
    padding-bottom: 0.125rem;
}

.history-card-status-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
