/* ============================================
   Policy Summarizer — Jupyter Notebook Theme
   Colors: White + Orange (#F37626)
   Typography: Source Sans 3 + Source Code Pro
   ============================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --orange: #F37626;
    --orange-light: #FDEAD2;
    --orange-hover: #E56517;
    --orange-bg: #FFF7F0;
    --gray-50: #FAFAFA;
    --gray-100: #F5F5F5;
    --gray-200: #EEEEEE;
    --gray-300: #E0E0E0;
    --gray-400: #BDBDBD;
    --gray-500: #9E9E9E;
    --gray-600: #757575;
    --gray-700: #616161;
    --gray-800: #424242;
    --gray-900: #212121;
    --green: #4CAF50;
    --red: #E53935;
    --white: #FFFFFF;
    --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Source Code Pro', 'Menlo', 'Consolas', monospace;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius: 6px;
    --cell-border: 4px;
}

html {
    font-size: 15px;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.header {
    background: var(--white);
    border-bottom: 3px solid var(--orange);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
}

.header-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--orange);
    letter-spacing: -0.02em;
}

.header-subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-top: 0.1rem;
}

/* --- Main Layout --- */
.main {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 1.5rem;
    max-width: 1400px;
    width: 100%;
    margin: 1.5rem auto;
    padding: 0 2rem;
    flex: 1;
}

@media (max-width: 960px) {
    .main {
        grid-template-columns: 1fr;
    }
}

/* --- Panels --- */
.panel {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}

.panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gray-200);
}

/* --- Upload Area --- */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 1.2rem;
    text-align: center;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--orange);
    background: var(--orange-bg);
}

.upload-icon {
    font-size: 1.8rem;
    margin-bottom: 0.3rem;
}

.upload-text {
    font-size: 0.85rem;
    color: var(--gray-600);
}

.upload-or {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin: 0.3rem 0;
}

.upload-btn {
    display: inline-block;
    padding: 0.35rem 1rem;
    background: var(--orange);
    color: var(--white);
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.upload-btn:hover {
    background: var(--orange-hover);
}

/* --- Code Cell (Jupyter style) --- */
.cell {
    border: 1px solid var(--gray-200);
    border-left: var(--cell-border) solid var(--orange);
    border-radius: var(--radius);
    background: var(--gray-50);
    margin-bottom: 1rem;
    overflow: hidden;
}

.cell-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    padding: 0.4rem 0.8rem;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
}

.code-editor {
    width: 100%;
    min-height: 280px;
    padding: 0.8rem;
    border: none;
    background: var(--gray-50);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--gray-900);
    resize: vertical;
    outline: none;
}

.code-editor::placeholder {
    color: var(--gray-400);
}

/* --- Options --- */
.options-row {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.option-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.option-input {
    width: 70px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.option-input:focus {
    border-color: var(--orange);
}

/* --- Toggle Switch --- */
.toggle-wrap {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-wrap input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--gray-300);
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--white);
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-wrap input:checked+.toggle-slider {
    background: var(--orange);
}

.toggle-wrap input:checked+.toggle-slider::before {
    transform: translateX(16px);
}

/* --- Analyze Button --- */
.analyze-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--orange);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.analyze-btn:hover:not(:disabled) {
    background: var(--orange-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.analyze-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
    font-size: 1.2rem;
}

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

/* --- Error --- */
.error-msg {
    margin-top: 0.75rem;
    padding: 0.6rem 0.8rem;
    background: #FDECEA;
    border: 1px solid #F5C6CB;
    border-left: var(--cell-border) solid var(--red);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--red);
}

/* --- Results Placeholder --- */
.results-placeholder {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}

.placeholder-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.results-placeholder p {
    font-size: 0.9rem;
}

/* --- Loading --- */
.results-loading {
    text-align: center;
    padding: 3rem 1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--gray-200);
    border-top-color: var(--orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.results-loading p {
    font-size: 0.9rem;
    color: var(--gray-600);
}

/* --- Bucket Card (Jupyter output cell) --- */
.bucket-card {
    border: 1px solid var(--gray-200);
    border-left: var(--cell-border) solid var(--orange);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    background: var(--white);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.bucket-card:hover {
    box-shadow: var(--shadow-sm);
}

.bucket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.8rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    user-select: none;
}

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

.bucket-toggle {
    font-size: 0.7rem;
    color: var(--gray-500);
    transition: transform 0.2s;
    margin-right: 0.5rem;
}

.bucket-card.expanded .bucket-toggle {
    transform: rotate(90deg);
}

.bucket-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    flex: 1;
}

.bucket-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    background: var(--orange-light);
    color: var(--orange);
}

.bucket-body {
    display: none;
    padding: 0.8rem;
}

.bucket-card.expanded .bucket-body {
    display: block;
}

/* --- Bucket Body Sections --- */
.bucket-section {
    margin-bottom: 0.75rem;
}

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

.section-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.3rem;
}

.section-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 0.5rem 0.7rem;
    word-break: break-all;
    line-height: 1.5;
    color: var(--gray-800);
}

.section-value.simplified {
    background: var(--orange-bg);
    border-color: var(--orange-light);
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--orange-hover);
}

/* --- Regex Toggle --- */
.regex-toggle {
    font-size: 0.75rem;
    color: var(--orange);
    cursor: pointer;
    border: none;
    background: none;
    font-family: var(--font-sans);
    font-weight: 600;
    padding: 0;
    margin-top: 0.2rem;
}

.regex-toggle:hover {
    text-decoration: underline;
}

.regex-full {
    display: none;
}

.regex-full.visible {
    display: block;
}

/* --- Verified Paths --- */
.path-list {
    list-style: none;
}

.section-hint {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-bottom: 0.4rem;
    font-style: italic;
}

.path-item {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.path-item:last-child {
    border-bottom: none;
}

.path-icon {
    flex-shrink: 0;
    font-size: 0.85rem;
}

.path-text {
    word-break: break-all;
    color: var(--gray-700);
}

.perm-pattern {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 3px;
    padding: 0.1rem 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--gray-800);
}

/* --- Results Summary --- */
.results-summary {
    margin-top: 1rem;
    padding: 0.8rem;
    background: var(--orange-bg);
    border: 1px solid var(--orange-light);
    border-left: var(--cell-border) solid var(--orange);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--gray-700);
}

.summary-stat {
    display: inline-block;
    margin-right: 1.5rem;
    font-weight: 600;
}

.summary-stat span {
    color: var(--orange);
}

/* --- Actions List --- */
.actions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.2rem;
}

.action-tag {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.15rem 0.45rem;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    color: var(--gray-700);
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 1rem 2rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    border-top: 1px solid var(--gray-200);
    background: var(--white);
    margin-top: auto;
}

.footer strong {
    color: var(--orange);
}

/* --- Time Badge --- */
.time-badge {
    font-size: 0.7rem;
    color: var(--gray-400);
    font-family: var(--font-mono);
    margin-left: 0.5rem;
}

/* --- Stage Indicator --- */
.stage-indicator {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    animation: fadeIn 0.3s ease;
}

.stage-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--orange);
    animation: pulse 1s ease infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Path Entry Animation --- */
.path-item-enter {
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.path-item-enter.path-item-visible {
    opacity: 1;
    transform: translateX(0);
}

/* --- Bucket Card Entry Animation --- */
.bucket-card {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Jaccard Similarity --- */
.jaccard-score-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.3rem;
}

.jaccard-bar-bg {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.jaccard-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.jaccard-bar-fill.jaccard-high {
    background: linear-gradient(90deg, #43A047, #66BB6A);
}

.jaccard-bar-fill.jaccard-mid {
    background: linear-gradient(90deg, #F9A825, #FFD54F);
}

.jaccard-bar-fill.jaccard-low {
    background: linear-gradient(90deg, #E53935, #EF5350);
}

.jaccard-value {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    min-width: 50px;
    text-align: right;
}

.jaccard-value.jaccard-high {
    color: #2E7D32;
}

.jaccard-value.jaccard-mid {
    color: #F57F17;
}

.jaccard-value.jaccard-low {
    color: #C62828;
}

.jaccard-na {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--gray-400);
}