/* ==============================================
   POLYHISTOR WIDGET SCOPED CSS
   Designed to blend with the Heron-Allen Society WordPress theme
   ============================================== */

#polyhistor-widget-root {
    /* Fallback fonts if WordPress variables aren't present */
    --ph-font-heading: var(--wp--preset--font-family--source-serif-pro, 'Source Serif Pro', serif);
    --ph-font-body: var(--wp--preset--font-family--montserrat, 'Montserrat', sans-serif);
    
    /* Fallback colors if WordPress variables aren't present */
    --ph-color-primary: var(--wp--preset--color--1F4F70, #1F4F70);
    --ph-color-accent: var(--wp--preset--color--13607E, #13607E);
    --ph-color-text: var(--wp--preset--color--292929, #292929);
    --ph-color-muted: #5a5a5a;
    --ph-color-border: #ddd;
    --ph-color-bg: #ffffff;
    --ph-color-bg-alt: #faf7f8;

    font-family: var(--ph-font-body);
    color: var(--ph-color-text);
    line-height: 1.6;
    box-sizing: border-box;
}

#polyhistor-widget-root * {
    box-sizing: border-box;
}

/* Typography */
#polyhistor-widget-root h2, 
#polyhistor-widget-root h3, 
#polyhistor-widget-root h4 {
    font-family: var(--ph-font-heading);
    color: var(--ph-color-primary);
    margin-top: 0;
}

/* Tabs */
#polyhistor-widget-root .ph-tabs {
    display: flex;
    border-bottom: 2px solid var(--ph-color-border);
    margin-bottom: 20px;
}

#polyhistor-widget-root .ph-tab {
    padding: 10px 20px;
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--ph-font-body);
    font-weight: 600;
    color: var(--ph-color-muted);
    font-size: 1rem;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px; /* Pull down over border */
}

#polyhistor-widget-root .ph-tab:hover {
    color: var(--ph-color-primary);
}

#polyhistor-widget-root .ph-tab.active {
    color: var(--ph-color-primary);
    border-bottom: 2px solid var(--ph-color-primary);
}

/* Search Area */
#polyhistor-widget-root .ph-search-container {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
}

#polyhistor-widget-root .ph-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--ph-color-border);
    border-radius: 4px; /* Minimal border radius matching standard academic themes */
    font-family: var(--ph-font-body);
    font-size: 1rem;
}

#polyhistor-widget-root .ph-input:focus {
    outline: none;
    border-color: var(--ph-color-primary);
    box-shadow: 0 0 0 1px var(--ph-color-primary);
}

#polyhistor-widget-root .ph-btn {
    padding: 12px 24px;
    background-color: var(--ph-color-primary);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    font-family: var(--ph-font-body);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#polyhistor-widget-root .ph-btn:hover {
    background-color: var(--ph-color-accent);
}

#polyhistor-widget-root .ph-btn:disabled {
    background-color: var(--ph-color-muted);
    cursor: not-allowed;
}

/* Status / Loading */
#polyhistor-widget-root .ph-status {
    text-align: center;
    color: var(--ph-color-muted);
    font-style: italic;
    margin: 20px 0;
}

#polyhistor-widget-root .ph-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    border-top-color: var(--ph-color-primary);
    animation: spin 1s ease-in-out infinite;
    vertical-align: middle;
    margin-right: 10px;
}

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

/* Results Area */
#polyhistor-widget-root .ph-results-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Markdown Content (RAG Results) */
#polyhistor-widget-root .ph-markdown {
    background: var(--ph-color-bg-alt);
    padding: 25px;
    border-radius: 4px;
    border: 1px solid var(--ph-color-border);
}

#polyhistor-widget-root .ph-markdown p {
    margin-top: 0;
}

/* Cards (Document Results) */
#polyhistor-widget-root .ph-card {
    background: var(--ph-color-bg);
    border: 1px solid var(--ph-color-border);
    border-radius: 4px;
    overflow: hidden;
}

#polyhistor-widget-root .ph-card-header {
    background: var(--ph-color-bg-alt);
    padding: 15px 20px;
    border-bottom: 1px solid var(--ph-color-border);
}

#polyhistor-widget-root .ph-card-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.25rem;
}

#polyhistor-widget-root .ph-card-header .ph-meta {
    font-size: 0.85rem;
    color: var(--ph-color-muted);
    margin: 0;
}

#polyhistor-widget-root .ph-card-body {
    padding: 20px;
}

#polyhistor-widget-root .ph-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

#polyhistor-widget-root .ph-meta-item strong {
    display: block;
    color: var(--ph-color-primary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 3px;
}

/* Images */
#polyhistor-widget-root .ph-gallery {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    margin-top: 20px;
}

#polyhistor-widget-root .ph-image-wrapper {
    display: flex;
    flex-direction: column;
}

#polyhistor-widget-root .ph-gallery img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid var(--ph-color-border);
    cursor: pointer;
    transition: opacity 0.2s;
}

#polyhistor-widget-root .ph-gallery img:hover {
    opacity: 0.85;
}

#polyhistor-widget-root .ph-caption {
    font-size: 0.8rem;
    color: var(--ph-color-muted);
    text-align: center;
    margin-top: 8px;
    line-height: 1.3;
}

/* ==============================================
   CSP COMPLIANT CLASSES (Migrated from JS inline styles)
   ============================================== */
#polyhistor-widget-root #ph-description-container {
    margin-bottom: 15px;
    color: var(--ph-color-muted);
    font-size: 0.95rem;
    line-height: 1.4;
}

#polyhistor-widget-root .ph-status.ph-status-error {
    color: #cf2e2e;
}

#polyhistor-widget-root .ph-inline-gallery {
    margin: 25px 0;
    display: block;
    text-align: center;
}

#polyhistor-widget-root .ph-inline-gallery .ph-image-wrapper {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    display: inline-block;
    text-align: left;
    background: transparent;
}

#polyhistor-widget-root .ph-inline-gallery img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid var(--ph-color-border);
    display: block;
    margin: 0 auto;
}

#polyhistor-widget-root .ph-inline-gallery .ph-caption {
    font-size: 0.85rem;
    line-height: 1.4;
}

#polyhistor-widget-root .ph-citation-badge {
    font-size: 0.75em;
    background: var(--ph-color-primary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    margin: 0 2px;
    cursor: help;
    display: inline-block;
}

#polyhistor-widget-root .ph-citations {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid var(--ph-color-border);
}

#polyhistor-widget-root .ph-citations h4 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--ph-color-text);
}

#polyhistor-widget-root .ph-citations ol {
    margin: 0;
    padding-left: 20px;
    font-size: 0.85em;
    color: var(--ph-color-muted);
}

#polyhistor-widget-root .ph-citations li {
    margin-bottom: 6px;
    line-height: 1.4;
}

#polyhistor-widget-root .ph-plates-header {
    margin-top: 30px;
}

#polyhistor-widget-root .ph-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    background: var(--ph-color-bg-alt);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--ph-color-border);
}

#polyhistor-widget-root .ph-controls .ph-btn {
    padding: 5px 10px;
    min-width: 70px;
}

#polyhistor-widget-root .ph-doc-select {
    flex: 1;
    min-width: 0; /* Fix flex item overflow for long select options */
    margin: 0 10px;
    padding: 6px;
    border-radius: 4px;
    border: 1px solid var(--ph-color-border);
    background: var(--ph-color-bg);
    color: var(--ph-color-text);
    font-size: 0.95rem;
    text-overflow: ellipsis;
}

#polyhistor-widget-root .ph-meta-item-spacer {
    margin-top: 20px;
}

/* ==============================================
   VIDEO GALLERY
   A separate #polyhistor-video-gallery container, not a descendant of
   #polyhistor-widget-root -- every variable and class above is scoped to
   that root and would not reach it, so this block redeclares the same
   fallback variables rather than assuming inheritance.
   ============================================== */
#polyhistor-video-gallery {
    --ph-font-heading: var(--wp--preset--font-family--source-serif-pro, 'Source Serif Pro', serif);
    --ph-font-body: var(--wp--preset--font-family--montserrat, 'Montserrat', sans-serif);
    --ph-color-primary: var(--wp--preset--color--1F4F70, #1F4F70);
    --ph-color-muted: #5a5a5a;
    --ph-color-border: #ddd;
    --ph-color-bg: #ffffff;
    --ph-color-bg-alt: #faf7f8;

    font-family: var(--ph-font-body);
    color: var(--ph-color-text, #292929);
    line-height: 1.6;
    box-sizing: border-box;
}

#polyhistor-video-gallery * {
    box-sizing: border-box;
}

#polyhistor-video-gallery h3 {
    font-family: var(--ph-font-heading);
    color: var(--ph-color-primary);
    margin-top: 0;
}

#polyhistor-video-gallery .ph-status {
    text-align: center;
    color: var(--ph-color-muted);
    font-style: italic;
    margin: 20px 0;
}

#polyhistor-video-gallery .ph-status.ph-status-error {
    color: #cf2e2e;
}

#polyhistor-video-gallery .ph-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    border-top-color: var(--ph-color-primary);
    animation: spin 1s ease-in-out infinite;
    vertical-align: middle;
    margin-right: 10px;
}

#polyhistor-video-gallery .ph-video-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

#polyhistor-video-gallery .ph-video-card {
    background: var(--ph-color-bg);
    border: 1px solid var(--ph-color-border);
    border-radius: 4px;
    overflow: hidden;
}

#polyhistor-video-gallery .ph-video-card .ph-card-header {
    background: var(--ph-color-bg-alt);
    padding: 15px 20px;
    border-bottom: 1px solid var(--ph-color-border);
}

#polyhistor-video-gallery .ph-video-card .ph-card-header h3 {
    margin: 0;
    font-size: 1.15rem;
}

#polyhistor-video-gallery .ph-video-card .ph-card-body {
    padding: 20px;
}

#polyhistor-video-gallery .ph-video {
    width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid var(--ph-color-border);
    display: block;
    background: #000;
}

#polyhistor-video-gallery .ph-video-card .ph-meta {
    font-size: 0.85rem;
    color: var(--ph-color-muted);
    margin: 10px 0 0 0;
    /* Descriptions can carry \n paragraph breaks (e.g. multi-paragraph
       historical notes); without this they collapse into one run-on block
       inside the single <p> the JS renders them into. */
    white-space: pre-line;
}
