:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e2e5ea;
    --border-light: #eef0f3;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-text: #3730a3;
    --success: #059669;
    --success-light: #ecfdf5;
    --success-text: #065f46;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --warning-text: #92400e;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0284c7;
    --info-light: #f0f9ff;
    --code-bg: #1e293b;
    --code-text: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-xs: 4px;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
}

/* ─── Header ─── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 36px;
    height: 36px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

header h1 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-ready { background: var(--success); box-shadow: 0 0 0 3px rgba(5,150,105,0.15); }
.status-working { background: var(--warning); box-shadow: 0 0 0 3px rgba(217,119,6,0.15); animation: pulse 1.5s infinite; }
.status-error { background: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }

.status-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ─── Layout ─── */
main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 28px;
}

.layout {
    display: grid;
    grid-template-columns: 540px 1fr;
    gap: 24px;
    align-items: start;
}

/* ─── Input Section ─── */
.input-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 80px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

/* ─── Ticket Picker ─── */

.ticket-count-label {
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 600;
    background: var(--surface);
    padding: 1px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

.ticket-picker {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    overflow: hidden;
    background: var(--surface);
}

.ticket-picker-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
}

.ticket-picker-header svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.ticket-picker-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.ticket-search {
    flex: 1;
    min-width: 0;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 11px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
}

.ticket-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79,70,229,0.1);
}

.ticket-list {
    max-height: 160px;
    overflow-y: auto;
    overflow-x: hidden;
}

.ticket-row {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.1s ease;
    overflow: hidden;
}

.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: var(--bg); }

.ticket-row.selected {
    background: var(--primary-light);
    box-shadow: inset 3px 0 0 var(--primary);
}

.ticket-row-top {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.ticket-id {
    font-weight: 700;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--primary);
    flex-shrink: 0;
}

.ticket-plt {
    padding: 0 4px;
    background: var(--bg);
    border-radius: var(--radius-xs);
    font-size: 9px;
    font-weight: 600;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.ticket-email {
    font-size: 10px;
    color: var(--text-secondary);
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ticket-subject {
    font-size: 11px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticket-body-preview {
    font-size: 10px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
}

.ticket-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 11px;
}

.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 18px;
    background: var(--bg);
    padding: 3px;
    border-radius: 8px;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.tab:hover { color: var(--text); background: var(--surface); }

.tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.tab svg { flex-shrink: 0; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.form-group { margin-bottom: 12px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
    letter-spacing: 0.01em;
}

.label-hint {
    font-weight: 400;
    color: var(--text-tertiary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: all 0.15s ease;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-tertiary);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.form-group textarea { resize: vertical; line-height: 1.6; }

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }
.form-group.flex-2 { flex: 2; }
.form-group.form-group-sm { flex: 0 0 80px; }

.form-divider {
    height: 1px;
    background: var(--border-light);
    margin: 14px 0;
}

.input-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.btn-primary {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
    padding: 10px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ─── Results Column ─── */
.results-column {
    min-height: 400px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--text-tertiary);
    text-align: center;
    gap: 12px;
}

.empty-state p { font-size: 14px; }
.empty-state strong { color: var(--text-secondary); }
.empty-hint { font-size: 12px; }

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    gap: 12px;
    color: var(--text-secondary);
}

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

.loading-state p { font-size: 14px; font-weight: 500; }
.loading-sub { font-size: 12px; color: var(--text-tertiary); font-weight: 400; }

/* Error State */
.error-state {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--danger-light);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--danger);
}

.error-state strong { font-size: 13px; }
.error-state p { font-size: 13px; margin-top: 2px; word-break: break-word; }

.hidden { display: none !important; }

/* ─── Confidence Banner ─── */
.confidence-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.confidence-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-exact { background: var(--success-light); color: var(--success-text); }
.badge-high { background: var(--primary-light); color: var(--primary-text); }
.badge-possible { background: var(--warning-light); color: var(--warning-text); }
.badge-none { background: var(--danger-light); color: var(--danger); }

.confidence-summary {
    font-size: 13px;
    color: var(--text-secondary);
}

.timing-pills {
    display: flex;
    gap: 6px;
}

.timing-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 11px;
    color: var(--text-secondary);
}

.timing-pill strong {
    color: var(--text);
    font-weight: 600;
    font-family: var(--font-mono);
}

/* ─── Panels ─── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
}

.panel-header h2 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.panel-header.clickable {
    cursor: pointer;
    transition: background 0.1s ease;
    user-select: none;
}

.panel-header.clickable:hover { background: var(--bg); }

.panel-summary {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 400;
}

.count-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    background: var(--bg);
    border-radius: 20px;
    color: var(--text-secondary);
}

.chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.panel-body { padding: 0 18px 18px; }

.panel-body.collapsed {
    display: none;
}

.panel.open .chevron { transform: rotate(180deg); }

/* ─── Candidates ─── */
.candidate-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px 18px;
    border-top: 1px solid var(--border-light);
    transition: background 0.1s ease;
}

.candidate-card:hover { background: #fafbfc; }
.candidate-card:first-child { border-top: none; }

.candidate-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.candidate-card:first-child .candidate-rank {
    background: var(--primary-light);
    color: var(--primary);
}

.candidate-details { flex: 1; min-width: 0; }

.candidate-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.candidate-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-secondary);
}

.candidate-meta-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--border);
}

.candidate-jobtitle {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.candidate-reasons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.reason-tag {
    padding: 2px 8px;
    background: var(--primary-light);
    border-radius: var(--radius-xs);
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--primary-text);
}

.candidate-score-col {
    text-align: right;
    flex-shrink: 0;
}

.candidate-score {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--primary);
    line-height: 1;
}

.candidate-score-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* ─── Location Resolution ─── */
.candidate-location {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.candidate-location svg { flex-shrink: 0; color: var(--text-tertiary); }

.location-section { margin-top: 8px; }

.location-resolved {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.location-resolved-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: var(--success-light);
    color: var(--success-text);
    border-radius: var(--radius-xs);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.location-resolved-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--success-text);
}

.location-match-reason {
    font-size: 10px;
    color: var(--text-tertiary);
    font-style: italic;
}

.location-unresolved {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--warning);
    font-weight: 500;
    margin-bottom: 6px;
}

.location-chips {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.location-chip {
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xs);
    font-size: 10px;
    color: var(--text-secondary);
}

.location-chip-match {
    background: var(--success-light);
    border-color: #a7f3d0;
    color: var(--success-text);
    font-weight: 600;
}

.no-candidates {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ─── Extracted Context ─── */
.context-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}

.context-item {
    padding: 6px 0;
}

.context-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.context-value {
    font-size: 13px;
    color: var(--text);
    word-break: break-word;
}

.context-value.empty {
    color: var(--text-tertiary);
    font-style: italic;
    font-size: 12px;
}

.context-value .tag {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg);
    border-radius: var(--radius-xs);
    font-size: 12px;
    margin: 1px 2px 1px 0;
}

/* ─── Search Queries ─── */
.query-item {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    overflow: hidden;
}

.query-item:last-child { margin-bottom: 0; }

.query-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s ease;
}

.query-header:hover { background: var(--bg); }

.query-name {
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text);
}

.query-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 11px;
}

.query-result-count {
    padding: 1px 8px;
    background: var(--bg);
    border-radius: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}

.query-skipped-label {
    color: var(--text-tertiary);
    font-style: italic;
    font-size: 11px;
}

.query-body {
    display: none;
}

.query-body.open {
    display: block;
}

.query-body pre {
    margin: 0;
    padding: 14px 16px;
    background: var(--code-bg);
    color: var(--code-text);
    font-size: 11px;
    font-family: var(--font-mono);
    overflow-x: auto;
    line-height: 1.5;
}

/* ─── Debug Info ─── */
.debug-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.debug-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.debug-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.debug-value {
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text);
}

/* ─── Animations ─── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-section { animation: fadeIn 0.25s ease; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .input-section {
        position: static;
    }
}
