/**
 * Modern CSS - HTML Living Standard 2026 Compliant
 * Path: /usr/local/lsws/zGuide/html/assets/css/modern-2026.css
 * 
 * Features:
 * - CSS Grid & Flexbox
 * - CSS Variables (Custom Keys)
 * - Modern color spaces
 * - Container queries
 * - Logical keys
 * - View transitions
 */

:root {
    /* Modern Color System */
    --color-primary: oklch(0.55 0.20 142);
    --color-primary-hover: oklch(0.50 0.20 142);
    --color-secondary: oklch(0.70 0.15 264);
    --color-success: oklch(0.60 0.18 142);
    --color-danger: oklch(0.55 0.22 29);
    --color-warning: oklch(0.75 0.15 85);
    --color-info: oklch(0.60 0.15 252);

    /* Neutral Colors */
    --color-text: oklch(0.20 0 0);
    --color-text-muted: oklch(0.50 0 0);
    --color-bg: oklch(0.98 0 0);
    --color-surface: oklch(1.00 0 0);
    --color-border: oklch(0.90 0 0);

    /* Spacing Scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --color-text: oklch(0.90 0 0);
        --color-text-muted: oklch(0.65 0 0);
        --color-bg: oklch(0.15 0 0);
        --color-surface: oklch(0.20 0 0);
        --color-border: oklch(0.30 0 0);
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    font-family: var(--font-sans);
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
}

body {
    margin: 0;
    min-block-size: 100dvh;
}

/* Modern Card Component */
.card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    padding-block: var(--space-lg);
    padding-inline: var(--space-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);

    &:hover {
        box-shadow: var(--shadow-md);
    }
}

/* Modern Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);

    padding-block: var(--space-sm);
    padding-inline: var(--space-lg);

    border: 0;
    border-radius: var(--radius-md);

    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.5;
    text-decoration: none;

    cursor: pointer;
    user-select: none;

    transition: all var(--transition-fast);

    &:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }
}

.btn-primary {
    background-color: var(--color-primary);
    color: white;

    &:hover {
        background-color: var(--color-primary-hover);
        transform: translateY(-1px);
        box-shadow: var(--shadow-md);
    }
}

/* Modern Grid Layout */
.grid {
    display: grid;
    gap: var(--space-lg);

    &.grid-2 {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }

    &.grid-3 {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }

    &.grid-4 {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* Responsive Container */
.container {
    inline-size: 100%;
    max-inline-size: 1280px;
    margin-inline: auto;
    padding-inline: var(--space-lg);
}

@media (min-width: 768px) {
    .container {
        padding-inline: var(--space-xl);
    }
}

/* Modern Infobox Styles */
.infobox {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);

    caption {
        padding-block: var(--space-lg);
        padding-inline: var(--space-lg);
        font-size: 1.25rem;
        font-weight: 600;
        text-align: start;
        background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
        color: white;
    }

    th {
        padding-block: var(--space-sm);
        padding-inline: var(--space-md);
        inline-size: 40%;
        text-align: start;
        font-weight: 500;
        color: var(--color-text-muted);
        vertical-align: top;
    }

    td {
        padding-block: var(--space-sm);
        padding-inline: var(--space-md);
        border-block-start: 1px solid var(--color-border);
    }

    tr:first-child td {
        border-block-start: 0;
    }
}

/* Gallery Modern Layout */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);

    @media (min-width: 768px) {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-md);

    img {
        inline-size: 100%;
        block-size: 100%;
        object-fit: cover;
        transition: transform var(--transition-slow);
    }

    &:hover img {
        transform: scale(1.05);
    }
}

/* Modern Form Controls */
.form-control {
    inline-size: 100%;
    padding-block: var(--space-sm);
    padding-inline: var(--space-md);

    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);

    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;

    background-color: var(--color-surface);
    color: var(--color-text);

    transition: border-color var(--transition-fast);

    &:focus {
        outline: 0;
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.1);
    }
}

/* Badge Component */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);

    padding-block: var(--space-xs);
    padding-inline: var(--space-sm);

    border-radius: var(--radius-sm);

    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;

    background-color: var(--color-primary);
    color: white;
}

/* Alert Component */
.alert {
    padding-block: var(--space-md);
    padding-inline: var(--space-lg);

    border-inline-start: 4px solid;
    border-radius: var(--radius-md);

    &.alert-success {
        background-color: oklch(from var(--color-success) l c h / 0.1);
        border-color: var(--color-success);
        color: var(--color-success);
    }

    &.alert-danger {
        background-color: oklch(from var(--color-danger) l c h / 0.1);
        border-color: var(--color-danger);
        color: var(--color-danger);
    }
}

/* Loading Skeleton */
@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton {
    background: linear-gradient(90deg,
            var(--color-border) 25%,
            oklch(from var(--color-border) l c h / 0.5) 50%,
            var(--color-border) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

/* Sticky Header */
.sticky-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 1000;
    background-color: var(--color-surface);
    border-block-end: 1px solid var(--color-border);
    backdrop-filter: blur(8px);
}

/* View Transition API Support */
@supports (view-transition-name: auto) {

    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.3s;
    }
}

/* Container Queries */
@container (min-width: 600px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }

    .infobox {
        break-inside: avoid;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   MOBILE CONTENT OVERFLOW FIXES
   ========================================================================== */

/* Prevent horizontal scroll */
html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Prevent all elements from breaking layout */
* {
    max-width: 100%;
    box-sizing: border-box;
}

/* Headings word wrap */
h1,
h2,
h3,
h4,
h5,
h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Card overflow protection */
.biography-card,
.person-card,
.place-card,
.event-card,
.card,
.card-body {
    overflow: hidden;
    word-wrap: break-word;
}

/* Long URLs in infobox */
.infobox td {
    word-break: break-all;
    overflow-wrap: anywhere;
}

.infobox a {
    word-break: break-word;
}

/* ==========================================================================
   MOBILE FONT SIZES
   ========================================================================== */

@media (max-width: 576px) {

    /* Scale down display headings */
    .display-1 {
        font-size: 2.5rem !important;
    }

    .display-2 {
        font-size: 2.25rem !important;
    }

    .display-3 {
        font-size: 2rem !important;
    }

    .display-4 {
        font-size: 1.75rem !important;
    }

    .display-5 {
        font-size: 1.5rem !important;
    }

    /* Scale down lead text */
    .lead {
        font-size: 1rem !important;
        line-height: 1.5 !important;
    }

    /* Regular headings */
    h1 {
        font-size: 1.75rem !important;
    }

    h2 {
        font-size: 1.5rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    /* Reduce padding */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Cards */
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }
}

/* ==========================================================================
   STRETCHED-LINK FIX
   ========================================================================== */

/* Cards must be position-relative for stretched-link to work correctly */
.person-card,
.place-card,
.event-card,
.work-card,
.org-card {
    position: relative !important;
}

/* Grid containers should NOT be position-relative */
.person-card-grid,
.place-card-grid,
.event-card-grid,
.row {
    position: static !important;
}

/* Ensure stretched-link only affects the card */
.stretched-link::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    content: "";
}

/* ==========================================================================
   MOBILE COLUMN ORDERING (Overview before Infobox)
   ========================================================================== */

@media (max-width: 991px) {

    /* Infobox appears BEFORE content on mobile */
    .order-mobile-infobox {
        order: 1;
    }

    .order-mobile-content {
        order: 2;
    }
}

@media (min-width: 992px) {

    /* Desktop: Content before infobox */
    .order-mobile-content {
        order: 1;
    }

    .order-mobile-infobox {
        order: 2;
    }
}

/* ==========================================================================
   INFOBOX MOBILE OPTIMIZATIONS
   ========================================================================== */

@media (max-width: 576px) {
    .infobox {
        font-size: 0.8125rem;
        margin-bottom: 1.5rem;
    }

    .infobox caption {
        font-size: 0.95rem;
        padding: 0.75rem 0.5rem;
        word-break: break-word;
    }

    .infobox th[scope="row"] {
        width: 42%;
        font-size: 0.75rem;
        padding: 0.6rem 0.5rem;
    }

    .infobox td {
        font-size: 0.8125rem;
        padding: 0.6rem 0.5rem;
    }

    .infobox img {
        display: block;
        width: 100%;
        height: auto;
        max-height: 250px;
        object-fit: cover;
    }

    /* Metadata rows even smaller on mobile */
    .infobox tr.infobox-metadata th[scope="row"],
    .infobox tr.infobox-metadata td {
        padding: 0.4rem 0.5rem;
        font-size: 0.6875rem;
    }
}

/* ==========================================================================
   HERO SECTIONS MOBILE
   ========================================================================== */

@media (max-width: 768px) {

    .biography-hero,
    .places-hero,
    .events-hero {
        padding: 2rem 0 !important;
    }

    .portrait-frame {
        width: 150px !important;
        height: 150px !important;
        margin-bottom: 1rem;
    }

    .title-badge {
        font-size: 0.75rem;
        padding: 4px 12px;
    }
}

/* ==========================================================================
   BUTTON MOBILE SIZES
   ========================================================================== */

@media (max-width: 576px) {
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }

    .btn-lg {
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }

    /* Ensure touch targets are at least 44px */
    .btn,
    .btn-lg,
    .btn-sm {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ==========================================================================
   GALLERY MOBILE
   ========================================================================== */

@media (max-width: 576px) {

    .gallery-grid,
    .person-card-grid,
    .place-card-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
        gap: 0.75rem !important;
    }
}

/* ==========================================================================
   NAVIGATION MOBILE
   ========================================================================== */

@media (max-width: 991px) {

    /* Mobile navbar - use static positioning so it pushes content down */
    .navbar-collapse {
        max-height: 80vh;
        overflow-y: auto;
        background: white;
        /* Use static position - Bootstrap handles show/hide */
        z-index: 1050;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        padding: 1rem;
        border-radius: 0 0 8px 8px;
        margin-top: 0.5rem;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Mobile dropdown menus */
    .navbar-nav .dropdown-menu {
        position: static;
        float: none;
        width: 100%;
        box-shadow: none;
        border: none;
        background: rgba(0, 0, 0, 0.03);
    }

    /* Ensure toggler icon is visible */
    .navbar-toggler {
        border: 1px solid rgba(0, 0, 0, 0.1);
    }

    .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(0,0,0,0.7)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    }
}

/* ==========================================================================
   TABLE MOBILE (for data tables, not infobox)
   ========================================================================== */

@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table:not(.infobox) {
        font-size: 0.875rem;
    }
}

/* ==========================================================================
   FORM MOBILE
   ========================================================================== */

@media (max-width: 576px) {
    .form-control {
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    .input-group-lg .form-control {
        font-size: 16px;
    }
}

/* ==========================================================================
   BREADCRUMB MOBILE
   ========================================================================== */

@media (max-width: 576px) {
    .breadcrumb {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
    }

    .breadcrumb-item+.breadcrumb-item::before {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }
}

/* ==========================================================================
   MODAL MOBILE
   ========================================================================== */

@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1rem;
    }
}

/* ==========================================================================
   STICKY SIDEBAR MOBILE
   ========================================================================== */

@media (max-width: 991px) {
    .sticky-top {
        position: static !important;
        top: auto !important;
    }
}

/* ==========================================================================
   ACCESSIBILITY IMPROVEMENTS
   ========================================================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 3px solid #198754;
    outline-offset: 2px;
}

/* Touch target size enforcement */
a,
button,
input,
select,
textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {

    .no-print,
    .navbar,
    .footer,
    .btn,
    .alert {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .infobox {
        break-inside: avoid;
    }

    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ==========================================================================
   DARK MODE SUPPORT
   ========================================================================== */

/* Manual dark mode via .dark-mode class (toggle button) */
body.dark-mode {
    --color-text: #e4e4e7;
    --color-text-muted: #a1a1aa;
    --color-bg: #18181b;
    --color-surface: #27272a;
    --color-border: #3f3f46;

    background-color: var(--color-bg);
    color: var(--color-text);
}

body.dark-mode .navbar,
body.dark-mode .site-header {
    background-color: #1f1f23 !important;
    border-color: var(--color-border);
}

body.dark-mode .navbar-brand,
body.dark-mode .nav-link {
    color: var(--color-text) !important;
}

body.dark-mode .card,
body.dark-mode .biography-card,
body.dark-mode .person-card,
body.dark-mode .event-card,
body.dark-mode .place-card-modern {
    background-color: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

body.dark-mode .card-body,
body.dark-mode .modal-content {
    background-color: var(--color-surface);
    color: var(--color-text);
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
    color: var(--color-text);
}

body.dark-mode .text-dark {
    color: var(--color-text) !important;
}

body.dark-mode .text-muted {
    color: var(--color-text-muted) !important;
}

body.dark-mode .form-control,
body.dark-mode .form-select {
    background-color: #3f3f46;
    border-color: #52525b;
    color: var(--color-text);
}

body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
    background-color: #3f3f46;
    border-color: #10b981;
    color: var(--color-text);
}

body.dark-mode .dropdown-menu {
    background-color: var(--color-surface);
    border-color: var(--color-border);
}

body.dark-mode .dropdown-item {
    color: var(--color-text);
}

body.dark-mode .dropdown-item:hover {
    background-color: #3f3f46;
}

body.dark-mode .infobox {
    background-color: var(--color-surface);
    border-color: var(--color-border);
}

body.dark-mode .infobox th[scope="row"] {
    background-color: #1f1f23;
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

body.dark-mode .infobox td {
    color: var(--color-text);
}

body.dark-mode .infobox caption {
    background: linear-gradient(135deg, #374151, #1f2937);
}

body.dark-mode .footer,
body.dark-mode footer {
    background-color: #1f1f23 !important;
}

body.dark-mode a {
    color: #10b981;
}

body.dark-mode a:hover {
    color: #34d399;
}

body.dark-mode .btn-outline-success {
    color: #10b981;
    border-color: #10b981;
}

body.dark-mode .btn-outline-primary {
    color: #60a5fa;
    border-color: #60a5fa;
}

body.dark-mode .alert-info {
    background-color: #1e3a5f;
    border-color: #2563eb;
    color: #93c5fd;
}

body.dark-mode .alert-danger {
    background-color: #450a0a;
    border-color: #dc2626;
    color: #fca5a5;
}

body.dark-mode .alert-success {
    background-color: #052e16;
    border-color: #10b981;
    color: #86efac;
}

/* Dark mode for Bootstrap bg-* classes */
body.dark-mode .bg-white,
body.dark-mode .bg-light {
    background-color: var(--color-surface) !important;
}

body.dark-mode .main-content,
body.dark-mode main,
body.dark-mode #main-content {
    background-color: var(--color-bg) !important;
}

body.dark-mode .container,
body.dark-mode .container-fluid {
    background-color: transparent;
}

body.dark-mode .hero-section,
body.dark-mode .biography-hero,
body.dark-mode .places-hero {
    background: linear-gradient(135deg, #1f1f23, #27272a) !important;
}

body.dark-mode .list-group-item {
    background-color: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

body.dark-mode .table {
    color: var(--color-text);
}

body.dark-mode .table th,
body.dark-mode .table td {
    border-color: var(--color-border);
}

body.dark-mode .table-striped>tbody>tr:nth-of-type(odd)>* {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--color-text);
}

body.dark-mode .breadcrumb {
    background-color: transparent;
}

body.dark-mode .breadcrumb-item a {
    color: #10b981;
}

body.dark-mode .breadcrumb-item.active {
    color: var(--color-text-muted);
}

body.dark-mode .badge {
    background-color: #3f3f46;
}

body.dark-mode .border,
body.dark-mode [class*="border"] {
    border-color: var(--color-border) !important;
}

body.dark-mode .shadow,
body.dark-mode .shadow-sm,
body.dark-mode .shadow-lg {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5) !important;
}

body.dark-mode .btn-light {
    background-color: #3f3f46;
    border-color: #52525b;
    color: var(--color-text);
}

body.dark-mode .btn-outline-secondary {
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

body.dark-mode ::placeholder {
    color: #71717a;
}

/* Make sure body HTML has dark background */
html.dark-mode,
body.dark-mode {
    background-color: #18181b !important;
}

/* Auto dark mode via OS preference */
@media (prefers-color-scheme: dark) {
    /* Handled via CSS custom keys in :root */
}

/* ==========================================================================
   LANDSCAPE MOBILE OPTIMIZATIONS
   ========================================================================== */

@media (max-width: 896px) and (orientation: landscape) {

    .biography-hero,
    .places-hero {
        padding: 1.5rem 0 !important;
    }

    .portrait-frame {
        width: 120px !important;
        height: 120px !important;
    }
}