/* SummarAIzer Application Styles */

/* Local font faces (files should be placed under static/assets/fonts/) */
@font-face {
    font-family: 'Work Sans';
    src: url('../assets/fonts/WorkSans-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    /* variable weight range */
    font-style: normal;
    font-display: swap;
}

/* Main layout and container styles */
.main,
gradio-app {
    align-items: center;
    justify-content: center;
}

.container,
.gradio-container {
    max-width: 1200px !important;
    width: inherit;
    padding-left: 16px;
    padding-right: 16px;
}

main.container {
    margin: auto;
}

/* === Public Site Enhancements === */
/* Public site header */
.site-header {
    background: linear-gradient(35deg, #f49631 20%, #ab87a1 100%);
    color: white;
    padding: 24px 0;
    margin-bottom: 16px;
    border-radius: 10px;
}

.site-header .top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-header .brand {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.site-header .nav-link {
    color: #eaf4ff;
    text-decoration: none;
}

.site-header .page-title {
    margin-top: 12px;
}

.site-header .page-title h1 {
    margin: 0 0 4px;
}

.site-header .meta {
    opacity: .9;
}

/* Two-column layout for talk page */
.two-col {
    display: grid;
    grid-template-columns: 3fr 1.3fr;
    gap: 20px;
}

.content {
    min-width: 0;
}

.sidebar {
    min-width: 0;
}

.card {
    display: block;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    margin-bottom: 20px;
}

.mb-2 {
    margin-bottom: 20px;
}

.cards a.card {
    text-decoration: none;
    color: inherit;
}

.card .card-body {
    padding: 12px 14px;
}

.card-title {
    margin: 0 0 6px;
    font-size: 1.05rem;
}

.card-image img {
    display: block;
    width: 100%;
    height: 160px;
    object-fit: cover;
}

.meta-list,
.resource-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.meta-list li,
.resource-list li {
    padding: 6px 0;
    border-bottom: 1px dotted #eee;
}

.meta-list li:last-child,
.resource-list li:last-child {
    border-bottom: 0;
}

.meta {
    color: #687386;
    font-size: 0.92rem;
}

.lead {
    opacity: .95;
    font-size: 1.05rem;
}

/* AI content warning banner */
.content-warning {
    background: #fff8e6;
    color: #6b4f00;
    border: 1px solid #ffe1a6;
    border-left: 4px solid #f49631;
    padding: 10px 12px;
    border-radius: 8px;
    margin: 12px 0 18px;
}

/* Hero cover image */
.hero {
    margin-bottom: 20px;
    border-radius: 10px;
}

/* Hero cover image */
.hero.hero-image {
    background: #000;
}

.hero.hero-image img {
    display: block;
    width: 100%;
    height: 380px;
    object-fit: cover;
    object-position: center;
    border-radius: 10px;
}

/* Cards grid for index */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    justify-items: stretch;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    display: inline-block;
    background: #eef3f8;
    color: #f49631;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
}

/* Search bar */
.search-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 12px 0 18px;
}

.search-bar input[type="search"] {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
}

.search-bar select {
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #fff;
}

.count {
    color: #666;
    font-size: 14px;
}

/* Buttons */
.btn {
    display: inline-block;
    background: #f49631;
    color: #fff !important;
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none;
    border: none;
    cursor: pointer;
}

.btn-light {
    padding: 4px 8px;
    font-size: 14px;
}

.btn:hover {
    filter: brightness(1.05);
}

.btn-small {
    padding: 6px 10px;
    font-size: 14px;
}

/* Footer */
.site-footer {
    margin-top: 40px;
    padding: 16px 16px;
    border-top: 1px solid #e5e7eb;
    color: #666;
    background: #fafafa;
}

/* Header styles */
.main-header {
    position: relative;
    text-align: center;
    padding: 25px;
    background: linear-gradient(90deg, #667eea, #ba5645) !important;
    color: white;
    border-radius: 15px;
    margin-bottom: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 1;
}

.main-header .app-logo {
    margin: auto;
}

/* Navigation links styles */
.nav-link {
    transition: all 0.3s ease !important;
}

/* Mermaid diagram styles */
.mermaid {
    text-align: center;
    margin: 20px 0;
    background: #fafafa;
    border: none;
    border-radius: 5px;
    padding: 20px;
    min-height: 50px;
    overflow: auto;
}

.mermaid-container {
    text-align: center;
    margin: 20px 0;
}

.mermaid-error {
    text-align: center;
    margin: 20px 0;
    background: #ffe6e6;
    border: 1px solid #ffcccc;
    border-radius: 5px;
    padding: 20px;
    color: #cc0000;
}

/* Tab and content styles */

.component-section {
    background: #f49631;
    padding: 20px;
    border-radius: 10px;
    margin: 10px 0;
    border-left: 4px solid #ab87a1;
}

/* Custom CSS for vertical radio buttons */
.file-radio-vertical .wrap {
    flex-direction: column !important;
    align-items: flex-start !important;
}

.file-radio-vertical .wrap>label {
    width: 100% !important;
    margin: 2px 0 !important;
    padding: 8px 12px !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 4px !important;
    background: #f8f9fa !important;
    cursor: pointer !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    color: #212529 !important;
    /* Force dark text for readability */
}

.file-radio-vertical .wrap>label:hover {
    background: #e9ecef !important;
    border-color: #f49631 !important;
    color: #212529 !important;
    /* Force dark text on hover */
}

.file-radio-vertical .wrap>label input[type="radio"]:checked+span {
    color: black !important;
    border-radius: 3px !important;
    padding: 2px 6px !important;
}

.file-radio-vertical .wrap>label span {
    font-family: monospace !important;
    font-size: 0.9em !important;
    word-break: break-all !important;
    max-width: 100% !important;
    color: #212529 !important;
    /* Force dark text in labels */
}

/* Custom CSS for vertical checkbox group */
.file-checkbox-vertical .wrap {
    flex-direction: column !important;
    align-items: flex-start !important;
}

.file-checkbox-vertical .wrap>label {
    width: 100% !important;
    margin: 2px 0 !important;
    padding: 8px 12px !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 4px !important;
    background: #f8f9fa !important;
    cursor: pointer !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    color: #212529 !important;
    /* Force dark text for readability */
}

.file-checkbox-vertical .wrap>label:hover {
    background: #e9ecef !important;
    border-color: #28a745 !important;
    color: #212529 !important;
    /* Force dark text on hover */
}

.file-checkbox-vertical .wrap>label input[type="checkbox"]:checked+span {
    background: #28a745 !important;
    color: white !important;
    border-radius: 3px !important;
    padding: 2px 6px !important;
}

.file-checkbox-vertical .wrap>label span {
    font-family: monospace !important;
    font-size: 0.9em !important;
    word-break: break-all !important;
    max-width: 100% !important;
    color: #212529 !important;
    /* Force dark text in labels */
}

textarea {
    line-height: 1.6 !important;
}

/* Summary editor styling */
.summary-editor textarea {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
}

/* Raw output editor styling */
.raw-output-editor textarea {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
    background-color: #f8f9fa !important;
    color: #212529 !important;
    /* Force dark text for readability */
}

/* HTML preview styling */
.html-preview.block {
    color: #2c3e50 !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
    padding: 20px !important;
    background-color: #ffffff !important;
    min-height: 400px !important;
    max-height: 600px !important;
    overflow-y: auto !important;
}

.html-preview h1,
.html-preview h2,
.html-preview h3,
.html-preview h4,
.html-preview h5,
.html-preview h6 {
    color: #2c3e50 !important;
    margin-top: 1.5em !important;
    margin-bottom: 0.5em !important;
}

.html-preview p {
    color: #2c3e50 !important;
    margin-bottom: 1em !important;
    line-height: 1.6 !important;
}

.html-preview ul,
.html-preview ol {
    color: #2c3e50 !important;
    margin-bottom: 1em !important;
    padding-left: 2em !important;
}

.html-preview blockquote {
    border-left: 4px solid #f49631 !important;
    margin: 1em 0 !important;
    padding-left: 1em !important;
    font-style: italic !important;
    color: #555 !important;
}

.html-preview code {
    color: #2c3e50 !important;
    background-color: #f4f4f4 !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

.html-preview pre {
    color: #2c3e50 !important;
    background-color: #f8f9fa !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 5px !important;
    padding: 1em !important;
    overflow-x: auto !important;
}

.html-preview .prose * {
    color: #2c3e50 !important;
}

/* Responsive */
@media (max-width: 900px) {
    .two-col {
        grid-template-columns: 1fr;
    }

    .hero.hero-image img {
        height: 240px;
    }

    /* Center header content and avoid overflow on small screens */
    .site-header .top-nav {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }

    .site-header .page-title {
        text-align: center;
    }

    .site-header .page-title h1 {
        font-size: 1.5rem;
        line-height: 1.2;
        word-break: break-word;
    }
}

/* Narrow screens: ensure cards and review form are mobile-friendly */
@media (max-width: 680px) {

    /* Cards grid: single column, centered, no overflow */
    .cards {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .cards .card {
        width: 100%;
        max-width: 600px;
    }

    /* Review form: stack label over control to let Likert use full width */
    .form-row {
        grid-template-columns: 1fr;
        align-items: start;
        gap: 8px;
    }

    .form-label {
        margin-bottom: 2px;
    }

    .likert {
        width: 100%;
        justify-content: space-between;
    }

    .likert label {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        flex: 1 1 auto;
        min-width: 48px;
    }

    .likert-anchor {
        white-space: nowrap;
    }
}

/* Prompt configuration accordion */
.prompt-config .gradio-accordion {
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
}

.mermaid svg {
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
}

/* Remove fixed width/height constraints */
.mermaid svg[width] {
    width: auto !important;
}

.mermaid svg[height] {
    height: auto !important;
}

.html-preview .mermaid {
    max-width: 100% !important;
    overflow-x: auto !important;
}

.html-preview .mermaid svg {
    max-width: 100% !important;
    height: auto !important;
}

/* Mermaid diagram styles */
pre.mermaid {
    background-color: white !important;
    border: 1px solid #ddd !important;
    border-radius: 8px !important;
    padding: 20px !important;
    margin: 20px 0 !important;
    text-align: center !important;
    overflow: visible !important;
}

.mermaid svg {
    max-width: 100% !important;
    height: auto !important;
}

/* Ensure mermaid diagrams display properly in HTML preview */
.html-preview pre.mermaid {
    background: white !important;
    border: 2px solid #e0e0e0 !important;
    border-radius: 10px !important;
    padding: 25px !important;
    margin: 25px 0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Mermaid diagram styles */
.html-preview .mermaid {
    text-align: center !important;
    margin: 20px auto !important;
    background: white !important;
    border: 1px solid #ddd !important;
    border-radius: 8px !important;
    padding: 20px !important;
    max-width: 100% !important;
    overflow-x: auto !important;
}

.html-preview .mermaid svg {
    max-width: 100% !important;
    height: auto !important;
}

.gdpr-highlight {
    cursor: help;
}

/** Resource Browser Styles **/

body {
    font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
}

/* Use condensed font for headings */
h1,
h2,
h3,
h4,
h5,
h6,
.page-title h1,
.component-header h2 {
    font-family: 'Work Sans', Arial, sans-serif;
}

.main {
    width: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

table {
    border-collapse: collapse;
    width: 100%;
    margin: 20px 0;
}

th,
td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

th {
    background: #f5f5f5;
    font-weight: 600;
}

tr:hover {
    background: #f9f9f9;
}

a {
    color: #f49631;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.header {
    border-bottom: 2px solid #eee;
    margin-bottom: 30px;
    padding-bottom: 20px;
}

.breadcrumb {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
}

.breadcrumb a {
    color: #f49631;
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.actions-col {
    width: 260px;
}

.back-button {
    display: inline-block;
    margin-top: 30px;
    padding: 10px 20px;
    background: #f49631;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 14px;
}

.back-button:hover {
    background: #f49631;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-left: 10px;
}

.copy-btn {
    position: relative;
    top: -4px;
    margin-left: 0px;
}

/* Dark mode compatibility - Force dark text on light backgrounds */
/* These styles ensure readability regardless of theme */

/* Force dark text in elements with light backgrounds in dark mode */
.dark .file-radio-vertical .wrap>label,
.dark .file-radio-vertical .wrap>label span,
.dark .file-checkbox-vertical .wrap>label,
.dark .file-checkbox-vertical .wrap>label span {
    color: #212529 !important;
}

/* Ensure hover states maintain dark text */
.dark .file-radio-vertical .wrap>label:hover,
.dark .file-checkbox-vertical .wrap>label:hover {
    color: #212529 !important;
}

/* Force dark text in raw output editor in dark mode */
.dark .raw-output-editor textarea {
    color: #212529 !important;
    background-color: #f8f9fa !important;
}

/* Mermaid diagrams should maintain white background and dark text in both modes */
.dark .mermaid,
.dark .html-preview .mermaid,
.dark pre.mermaid,
.dark .html-preview pre.mermaid {
    background: white !important;
    color: #000000 !important;
}

/* Ensure code blocks maintain proper contrast */
.dark .html-preview code {
    background-color: #f4f4f4 !important;
    color: #212529 !important;
}

.dark .html-preview pre {
    background-color: #f8f9fa !important;
    color: #212529 !important;
}

/* Summary editor - maintain good readability */
.dark .summary-editor textarea {
    color: inherit;
    /* Use default text color for this */
}

/* HTML preview should maintain white background and dark text */
.dark .html-preview.block {
    background-color: #ffffff !important;
    color: #212529 !important;
}

/* Component sections should adapt to dark mode */
.dark .component-section {
    background: #6c4a37;
    /* Darker orange for dark mode */
    color: white;
    border-left-color: #8b6a8b;
    /* Darker purple for dark mode */
}

/* Additional dark mode compatibility for different implementations */
/* Support for data-theme="dark" and other common dark mode patterns */
[data-theme="dark"] .file-radio-vertical .wrap>label,
[data-theme="dark"] .file-radio-vertical .wrap>label span,
[data-theme="dark"] .file-checkbox-vertical .wrap>label,
[data-theme="dark"] .file-checkbox-vertical .wrap>label span,
html.dark .file-radio-vertical .wrap>label,
html.dark .file-radio-vertical .wrap>label span,
html.dark .file-checkbox-vertical .wrap>label,
html.dark .file-checkbox-vertical .wrap>label span {
    color: #212529 !important;
}

[data-theme="dark"] .raw-output-editor textarea,
html.dark .raw-output-editor textarea {
    color: #212529 !important;
    background-color: #f8f9fa !important;
}

[data-theme="dark"] .html-preview.block,
html.dark .html-preview.block {
    background-color: #ffffff !important;
    color: #212529 !important;
}

[data-theme="dark"] .mermaid,
[data-theme="dark"] .html-preview .mermaid,
html.dark .mermaid,
html.dark .html-preview .mermaid {
    background: white !important;
    color: #000000 !important;
}

/* Media query for system dark mode preference */
@media (prefers-color-scheme: dark) {

    /* Only apply if no explicit theme is set */
    body:not(.light):not([data-theme="light"]) .file-radio-vertical .wrap>label,
    body:not(.light):not([data-theme="light"]) .file-radio-vertical .wrap>label span,
    body:not(.light):not([data-theme="light"]) .file-checkbox-vertical .wrap>label,
    body:not(.light):not([data-theme="light"]) .file-checkbox-vertical .wrap>label span {
        color: #212529 !important;
    }

    body:not(.light):not([data-theme="light"]) .raw-output-editor textarea {
        color: #212529 !important;
        background-color: #f8f9fa !important;
    }

    body:not(.light):not([data-theme="light"]) .html-preview.block {
        background-color: #ffffff !important;
        color: #212529 !important;
    }

    body:not(.light):not([data-theme="light"]) .mermaid,
    body:not(.light):not([data-theme="light"]) .html-preview .mermaid {
        background: white !important;
        color: #000000 !important;
    }
}

/* Talk display components - maintain readability in all modes */
.talk-display {
    color: #212529 !important;
}

.talk-display h4 {
    color: #212529 !important;
}

.talk-display strong {
    color: #212529 !important;
}

.talk-display-warning {
    background: #f8f9fa !important;
    color: #212529 !important;
}

.talk-display-warning p {
    color: #6c757d !important;
}

.talk-display-warning strong {
    color: #212529 !important;
}

.talk-display-error {
    background: #f8f9fa !important;
    color: #212529 !important;
}

.talk-display-error p {
    color: #dc3545 !important;
}

.talk-display-error strong {
    color: #212529 !important;
}

.talk-display-success {
    background: #e8f5e8 !important;
    color: #212529 !important;
}

.talk-display-success div {
    color: #212529 !important;
}

.talk-display-success strong {
    color: #212529 !important;
}

/* Component header - ensure visibility in all modes */
.component-header {
    background: linear-gradient(90deg, #667eea, #ba5645) !important;
}

.component-header h2,
.component-header p {
    color: white !important;
}

/* Dark mode overrides for talk displays */
.dark .talk-display,
[data-theme="dark"] .talk-display,
html.dark .talk-display {
    color: #212529 !important;
}

.dark .talk-display h4,
[data-theme="dark"] .talk-display h4,
html.dark .talk-display h4 {
    color: #212529 !important;
}

.dark .talk-display strong,
[data-theme="dark"] .talk-display strong,
html.dark .talk-display strong {
    color: #212529 !important;
}

.dark .talk-display-warning,
[data-theme="dark"] .talk-display-warning,
html.dark .talk-display-warning {
    background: #f8f9fa !important;
    color: #212529 !important;
}

.dark .talk-display-warning strong,
[data-theme="dark"] .talk-display-warning strong,
html.dark .talk-display-warning strong {
    color: #212529 !important;
}

.dark .talk-display-error,
[data-theme="dark"] .talk-display-error,
html.dark .talk-display-error {
    background: #f8f9fa !important;
    color: #212529 !important;
}

.dark .talk-display-error strong,
[data-theme="dark"] .talk-display-error strong,
html.dark .talk-display-error strong {
    color: #212529 !important;
}

.dark .talk-display-success,
[data-theme="dark"] .talk-display-success,
html.dark .talk-display-success {
    background: #e8f5e8 !important;
    color: #212529 !important;
}

.dark .talk-display-success strong,
[data-theme="dark"] .talk-display-success strong,
html.dark .talk-display-success strong {
    color: #212529 !important;
}

.section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.form-row {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 12px;
    align-items: center;
    margin: 10px 0;
}

.form-label {
    font-weight: 600;
}

.likert {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.likert label {
    margin-right: 2px;
}

.likert-anchor {
    font-size: 12px;
    color: #eaeff6;
    background: #f49631;
    padding: 2px 6px;
    border-radius: 4px;
}

.muted {
    color: #666;
    font-size: 14px;
}

fieldset {
    border: 0;
    padding: 0;
    margin: 0;
}

legend {
    font-weight: 700;
    margin-bottom: 8px;
}

.editor-tabs {
    margin-top: 20px;
}

.tab-buttons {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    border-bottom: 1px solid #d0d7de;
    position: relative;
}

.tab-buttons button {
    background: #f6f8fa;
    border: 1px solid #d0d7de;
    border-bottom: none;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 14px;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    font-weight: 500;
    color: #24292f;
    position: relative;
    top: 1px;
}

.tab-buttons button:not(.active):hover {
    background: #eef2f5;
}

.tab-buttons button.active {
    background: #fff;
}

.tab-buttons button.save-btn {
    margin-left: auto;
    background: #28a745;
    color: #fff;
    border: 1px solid #248a37;
    top: 0;
}

.tab-buttons button.save-btn:hover {
    filter: brightness(1.05);
    background: #28a745;
}

.tab-buttons button.save-btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

#editor {
    width: 100%;
    min-height: 60vh;
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 14px;
    padding: 12px;
    border: 1px solid #d0d7de;
    border-radius: 0 6px 6px 6px;
    background: #fafafa;
    box-sizing: border-box;
    line-height: 1.5;
}

#tab-preview {
    border: 1px solid #d0d7de;
    border-radius: 0 6px 6px 6px;
}

#previewArea {
    min-height: 60vh;
    padding: 16px;
    background: #fff;
    border-radius: 0 6px 6px 6px;
    overflow: auto;
}

.status-ok {
    color: #2d7a36;
}

.status-error {
    color: #c0392b;
    position: absolute;
    top: 4px;
    right: 94px;
}

@media (max-width:700px) {
    .tab-buttons button {
        font-size: 13px;
        padding: 5px 10px;
    }
}