/* ==========================================================================
   Base Styles
   ========================================================================== */
:root {
    --primary-color: #333;
    --secondary-color: #f1f1f1;
    --accent-color: #2196f3;
    --success-color: #4caf50;
    --error-color: #f44336;
    --link-color: #0066cc;
    --text-color: #333;
    --text-muted: #666;
    --border-color: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --top-bar-height: 45.6px;
    --logo-size: 24px;

    /* Mode indicator colors */
    --mode-cache-color: #f44336; /* red */
    --mode-live-color: #4caf50; /* green */
    --mode-error-color: #f44336; /* keeping existing error color */

    /* Base values for image sizing */
    --min-image-width: 75px;
    --max-image-width: 100px;

    /* Fluid typography variables */
    --min-vw: 360;       /* minimum viewport width in px */
    --max-vw: 1200;      /* maximum viewport width in px */
    --min-body: 18;      /* minimum body font size in px */
    --max-body: 20;      /* maximum body font size in px */
    --min-h1: 20;        /* minimum h1 font size in px */
    --max-h1: 28;        /* maximum h1 font size in px */

    /* Fluid font size calculations */
    --fluid-body: clamp(
        calc(var(--min-body) * 1px),
        calc(var(--min-body) * 1px + (var(--max-body) - var(--min-body)) * ((100vw - var(--min-vw) * 1px) / (var(--max-vw) - var(--min-vw)))),
        calc(var(--max-body) * 1px)
    );
    --fluid-h1: clamp(
        calc(var(--min-h1) * 1px),
        calc(var(--min-h1) * 1px + (var(--max-h1) - var(--min-h1)) * ((100vw - var(--min-vw) * 1px) / (var(--max-vw) - var(--min-vw)))),
        calc(var(--max-h1) * 1px)
    );

    /* Base font size for consistent scaling */
    --base-font-size: var(--fluid-body);
}

/* Body */
body {
  font-family: "Literata", Georgia, "Times New Roman", Times, serif;
  font-size: var(--fluid-body);
  line-height: 1.65;
  margin: 0;
  padding-top: 10px;
  overflow-x: auto; /* Allow horizontal scrolling for tables */
  color: var(--text-color);
  background-color: var(--bg-color);
  transition: background-color 0.3s ease;
  font-kerning: normal;
  font-feature-settings: "liga" 1, "clig" 1, "kern" 1;
}

/* Single heading used: h1 */
h1 {
  font-family: inherit;
  font-weight: 600;
  font-size: var(--fluid-h1);
  line-height: 1.2;
  margin-top: 0.5em;
  margin-bottom: 0;
}

main {
    margin: 30px auto 0;
    padding: 28px 28px 10px;
    max-width: min(90%, 900px);
    box-sizing: border-box;
    animation: pageTransition 0.3s ease-in-out;
}

main p {
    margin-top: 0;
}

main a {
    color: var(--link-color);
    text-decoration: none;
}
main p a {
    color: var(--link-color);
    text-decoration: none;
}

main p a:hover {
    font-weight: bold;
}

@media (min-width: 1200px) {
    main {
        max-width: min(90%, 1200px);
    }
}

@media (min-width: 1600px) {
    main {
        max-width: min(85%, 1400px);
    }
}

/* Special handling for references page to allow table overflow */
main[data-page-type='references'] {
    max-width: none;
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
}

@media (min-width: 768px) {
    main[data-page-type='references'] {
        padding-left: 28px;
        padding-right: 28px;
    }
}

@keyframes pageTransition {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* ==========================================================================
   Navigation
   ========================================================================== */
/* Top Bar Container */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    background-color: var(--primary-color);
    color: white;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: 0.75rem;
    padding: 0 1rem;
    z-index: 1000;
}

/* Top Bar Layout Sections */
.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    grid-column: 1;
}

.top-bar-left a {
    line-height: initial;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 2rem;
    min-width: 0;
    grid-column: 3;
    justify-self: end;
}

/* Logo and Icons */
.site-logo {
    height: var(--logo-size);
    width: auto;
}

.site-title {
    color: var(--secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}

/* Make logo + site title clickable home link */
.top-bar-left a.home-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: min(45vw, 360px);
    overflow: hidden;
    color: var(--secondary-color);
    text-decoration: none;
}

.top-bar-left a.home-link:hover {
    opacity: 0.9;
}

/* Center the current page title */
.top-bar-center {
    grid-column: 2;
    justify-self: stretch;
    min-width: 0;
    overflow: hidden;
}

.page-title {
    color: var(--secondary-color);
    display: block;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.hamburger-icon {
    cursor: pointer;
    font-size: 22px;
    color: var(--secondary-color);
}

/* Responsive adjustments for header layout */
@media (max-width: 768px) {
    .top-bar-left .home-link {
        max-width: 38vw;
        gap: 0.5rem;
    }
    .top-bar-right {
        gap: 1rem;
    }
}

@media (max-width: 420px) {
    .top-bar-center {
        display: none;
    }
    :root {
        --logo-size: 20px;
    }
}

@media (max-width: 220px) { 
    .site-title {
        display: none;
    }
}


/* Vertical Menu */
.vertical-menu {
    width: 200px;
    position: fixed;
    top: var(--top-bar-height, 60px);
    right: 0;
    height: calc(100vh - var(--top-bar-height, 60px));
    background-color: var(--secondary-color);
    overflow-x: hidden;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 999;
    transform: translateX(100%); /* Changed from -100% to 100% */
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
}

/* Menu States */
.vertical-menu.show {
    transform: translateX(0);
}

/* Menu List Styles */
.vertical-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.vertical-menu li {
    border-bottom: 1px solid var(--border-color);
}

.vertical-menu li.menu-group-label,
.vertical-menu li.menu-separator {
    border-bottom: none;
}

.vertical-menu li a {
    text-decoration: none;
    color: var(--text-color);
    display: block;
    padding: 4px 16px;
}

.vertical-menu li a:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Menu Group Styles */
.menu-group-label {
    padding: 16px 16px 4px;
    font-weight: bold;
    color: var(--text-color);
    font-size: calc(var(--base-font-size) * 0.72); /* 0.9em * 0.8 (if base is 16px) */
    text-transform: uppercase;
    opacity: 0.7;
}

.menu-separator {
    height: 1px;
    background-color: var(--border-color);
    margin: 4px 16px 4px;
}

/* ==========================================================================
   Live Mode Controls
   ========================================================================== */
.live-mode-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-mode-label {
    color: white;
    font-size: calc(var(--base-font-size) * 0.75); /* match language label size */
}

@media (max-width: 768px) {
    /* Navigation adjustments */
    .live-mode-control {
        margin-right: 10px;
    }
}

/* ==========================================================================
   Language Switcher
   ========================================================================== */
.language-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-button {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: white;
    padding: 4px 8px;
    cursor: pointer;
    font-size: calc(var(--base-font-size) * 0.8);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.language-button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.language-flag {
    font-size: calc(var(--base-font-size) * 0.9);
}

.language-code {
    font-weight: 500;
    font-size: calc(var(--base-font-size) * 0.75);
}

/* New label for language slider */
.language-label {
    color: white;
    font-weight: 500;
    font-size: calc(var(--base-font-size) * 0.75);
    min-width: 24px;
    text-align: center;
}

/* Neutral slider colors for language switcher (remove red/green) */
.language-switcher .slider {
    background-color: rgba(255, 255, 255, 0.35);
}
.language-switcher input:checked + .slider {
    background-color: rgba(255, 255, 255, 0.60);
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px var(--shadow-color);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 1001;
    min-width: 120px;
}

.language-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.language-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: calc(var(--base-font-size) * 0.85);
    transition: background-color 0.2s ease;
}

.language-option:hover {
    background-color: var(--secondary-color);
}

.language-option.active {
    background-color: var(--accent-color);
    color: white;
}

.language-option .language-flag {
    font-size: calc(var(--base-font-size) * 0.9);
}

.language-option .language-name {
    font-weight: 500;
}

/* Top bar controls container adjustments */
.top-bar-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

@media (max-width: 768px) {
    .language-switcher {
        margin-right: 8px;
    }
    
    .language-button {
        padding: 3px 6px;
        font-size: calc(var(--base-font-size) * 0.75);
    }
    
    .language-dropdown {
        min-width: 100px;
    }
}


/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--mode-cache-color);
    transition: 0.4s;
}

.slider:before {
    position: absolute;
    content: '';
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: 0.4s;
}

input:checked + .slider {
    background-color: var(--mode-live-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}

/* ==========================================================================
   Settings Modal
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: none; /* toggled to flex by JS when opened */
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000; /* above top bar (1000) and menu (999) */
}

.modal {
    background: #fff;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-color);
    width: 90%;
    max-width: 420px;
    overflow: hidden;
}

/* Modal sections layout (Settings + Connections) */
.modal-sections {
    display: grid;
    gap: 16px;
}

/* Default stack (portrait) */
@media (orientation: portrait) {
    .modal-sections {
        grid-template-columns: 1fr;
    }
}

/* Side-by-side on landscape: widen modal and use 2 columns */
@media (orientation: landscape) {
    .modal {
        max-width: 760px;
    }
    .modal-sections {
        grid-template-columns: 1fr 1fr;
        column-gap: 20px;
    }
}

/* Section headings inside modal */
.modal-section h3 {
    margin: 0 0 8px 0;
    font-size: calc(var(--base-font-size) * 1.0);
    color: var(--text-color);
    font-weight: 600;
}

/* Connections section: read-only status switches with red/green */
.connections-section .status-switch .slider {
    background-color: var(--mode-cache-color); /* red for "off" */
}
.connections-section .status-switch input:checked + .slider {
    background-color: var(--mode-live-color);  /* green for "on" */
}
.connections-section .status-switch input[disabled] + .slider {
    cursor: default;
    opacity: 0.95;
}

/* Timestamp under connections */
.connections-check-time {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: calc(var(--base-font-size) * 0.85);
}
.connections-check-time .cached-indicator {
    color: var(--text-muted);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    font-size: calc(var(--base-font-size) * 1.1);
}

.modal-close {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}
.modal-close:hover {
    color: var(--primary-color);
}

.modal-body {
    padding: 12px 16px 16px;
    display: grid;
    row-gap: 14px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
}

.setting-label {
    font-weight: 600;
    color: var(--text-color);
    min-width: 120px;
}

.setting-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-control .option-left,
.setting-control .option-right {
    color: var(--text-muted);
    font-size: calc(var(--base-font-size) * 0.9);
}

/* Small screens: allow wrapping */
@media (max-width: 420px) {
    .setting-row {
        align-items: flex-start;
        flex-direction: column;
    }
    .setting-label {
        min-width: 0;
    }
}

/* Neutral slider colors inside Settings modal (Settings section only) */
.modal .slider {
    background-color: rgba(0, 0, 0, 0.35);
}
.modal input:checked + .slider {
    background-color: rgba(0, 0, 0, 0.60);
}

/* Override for connections section to use red/green status colors */
.modal .connections-section .status-switch .slider {
    background-color: var(--mode-cache-color);
}
.modal .connections-section .status-switch input:checked + .slider {
    background-color: var(--mode-live-color);
}
 
/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
    font-size: var(--base-font-size);
    width: 100%;
    background-color: #333;
    color: white;
    text-align: left;
    padding: 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    gap: 1rem;
}

.site-footer .copyright {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.site-footer .connectivity-status {
    flex: 0 0 auto;
    white-space: nowrap;
}

.connectivity-status {
    color: #aaa;
    font-size: calc(var(--base-font-size) * 0.64); /* 0.8em */
}

.connectivity-status small {
    margin-right: 2em;
}

.connectivity-status .check-time {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #f5f5f5;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: calc(var(--base-font-size) * 0.72); /* 0.9em */
    white-space: nowrap;
    margin-bottom: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: black;
}

.check-time::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #f5f5f5;
}

.services-status:hover .check-time {
    display: block;
}

.services-status {
    position: relative;
}

.connectivity-status .services-status:hover + .check-time {
    display: inline;
}

@media (max-width: 600px) {
    .site-footer {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        text-align: left;
    }
}



/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    .top-bar,
    .vertical-menu,
    .search-controls,
    .modal-overlay {
        display: none !important;
    }

    .tabulator-row {
        page-break-inside: avoid;
    }

    .book {
        page-break-inside: avoid;
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
}
