/* Global layout */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background-color: #f5f6f8;
    color: #1f2933;
}

a {
    color: #0d6efd;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    font-family: inherit;
}

/* Top navigation */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #dbeafe;
    color: #0f172a;
    padding: 14px 32px;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.15);
    position: sticky;
    top: 0;
    z-index: 1000;
    gap: 24px;
    flex-wrap: wrap;
}

.top-nav a {
    color: #0f172a;
    text-decoration: none;
    font-weight: 500;
}

.top-nav a:hover {
    text-decoration: underline;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.nav-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
    flex: 1;
}

.nav-title a {
    font-weight: 600;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.nav-user {
    font-size: 14px;
    color: #334155;
    background: #e2e8f0;
    padding: 6px 10px;
    border-radius: 999px;
}

.nav-logo {
    height: 42px;
    width: auto;
    object-fit: contain;
}

/* Hide the top-bar logo on small portrait mobile screens */
@media only screen and (max-width: 600px) and (orientation: portrait) {
    .nav-logo {
        display: none !important;
    }
    /* Reduce title size on mobile portrait to avoid line breaks */
    .image-title {
        font-size: 18px;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .video-title {
        font-size: 18px;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Also apply title tightening on slightly wider mobile/tablet in portrait */
@media only screen and (max-width: 800px) and (orientation: portrait) {
    .image-title {
        font-size: 18px;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .video-title {
        font-size: 18px;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Utility responsive visibility helpers */
.mobile-only { display: none !important; }
.hide-on-mobile { display: initial; }
/* Portrait-only helpers (default hidden/visible as appropriate) */
.mobile-portrait-only { display: none !important; }
.hide-on-mobile-portrait { display: initial; }

/* Sidebar and layout adjustments for mobile */
@media only screen and (max-width: 800px) {
    .sidebar {
        display: none !important;
    }
    .layout {
        flex-direction: column;
    }
    .main-content {
        padding: 16px;
    }
    .container {
        padding: 20px;
    }
    /* .mobile-only remains hidden in landscape to avoid redundancy with sidebar */
    .hide-on-mobile {
        display: none !important;
    }
    /* Ensure dropdown menus are scrollable on small screens */
    .nav-dropdown-menu {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* Apply portrait-only helpers and top-nav layout tweaks */
@media only screen and (max-width: 800px) and (orientation: portrait) {
    .mobile-portrait-only { display: flex !important; }
    .hide-on-mobile-portrait { display: none !important; }
    .mobile-only { display: inline-flex !important; }
    .nav-userline {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 10px;
        margin-top: -8px; /* pull closer to title */
        margin-bottom: 4px;
        flex-wrap: wrap;
    }
    .nav-userline .nav-user { margin-right: 6px; }
}

.nav-simple-link {
    color: #0f172a;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.nav-simple-link:hover,
.nav-simple-link:focus {
    background-color: rgba(59, 130, 246, 0.16);
    text-decoration: none;
    outline: none;
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    background: rgba(59, 130, 246, 0.12);
    border: none;
    color: #0f172a;
    font-size: 15px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-dropdown-toggle:hover,
.nav-dropdown-toggle:focus {
    background: rgba(59, 130, 246, 0.2);
    outline: none;
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #ffffff;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.22);
    border-radius: 12px;
    padding: 12px;
    min-width: 220px;
    display: none;
    flex-direction: column;
    gap: 8px;
    z-index: 1200;
}

.nav-dropdown-menu a {
    color: #1f2933;
    font-weight: 500;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-dropdown-menu a:hover {
    background-color: #eff6ff;
    color: #1d4ed8;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: flex;
}

.legal-wrapper {
    max-width: 960px;
    margin: 48px auto;
    padding: 0 24px 64px;
}

.legal-content {
    background-color: #ffffff;
    padding: 36px;
    border-radius: 16px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12);
    line-height: 1.6;
    color: #1f2933;
}

.legal-content h1,
.legal-content h2,
.legal-content h3 {
    color: #0f172a;
}

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.video-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px;
}

.video-wrapper video {
    border-radius: 8px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.15);
}

/* Authentication and form pages */
.form-page {
    max-width: 460px;
    margin: 80px auto;
    padding: 0 20px;
}

.card {
    background-color: #ffffff;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.card h1 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 26px;
}

.form-group {
    margin-bottom: 18px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #1f2933;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
textarea:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

textarea {
    min-height: 140px;
    resize: vertical;
    line-height: 1.5;
}

.primary-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #0d6efd, #3a7afe);
    color: #ffffff;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(13, 110, 253, 0.25);
}

.secondary-link {
    display: inline-block;
    text-align: center;
    width: 100%;
    margin-top: 16px;
    color: #6b7280;
}

/* Feedback messages */
.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
}

.alert-info {
    background: #e0f2fe;
    border: 1px solid #93c5fd;
    color: #1d4ed8;
}

.alert-success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #166534;
}

/* Sidebar layout (index) */
.layout {
    display: flex;
    min-height: calc(100vh - 88px);
}

.sidebar {
    width: 280px;
    background-color: #ffffff;
    padding: 24px;
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.08);
    position: sticky;
    top: 0;
}

.main-content {
    flex: 1;
    padding: 32px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #ffffff;
    padding: 32px;
    border-radius: 14px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.sidebar-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.user-links,
.info-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-links a,
.info-links a {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background-color: #f9fafb;
    color: #374151;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

.user-links a:hover,
.info-links a:hover {
    background-color: #eef2ff;
}

.session-timer {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    background: #e0f2fe;
    border: 1px solid #93c5fd;
    color: #1d4ed8;
}

.session-timer.warning {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #92400e;
}

.session-timer.danger {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #b91c1c;
}

.timer-refresh-btn {
    background-color: #22c55e;
    color: #ffffff;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    margin-top: 8px;
}

.timer-refresh-btn:hover {
    background-color: #16a34a;
}

.image-details {
    background-color: #f9fafb;
    padding: 18px;
    border-radius: 10px;
    border-left: 4px solid #22c55e;
}

.filename {
    display: block;
    font-family: 'Fira Code', Menlo, monospace;
    background-color: #e5e7eb;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    word-break: break-all;
}

.flash-messages {
    margin-bottom: 24px;
}

.flash-message {
    background-color: #e0f2fe;
    border: 1px solid #93c5fd;
    color: #1d4ed8;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 12px;
}

/* Second-line age display under page title */
.image-age-line {
    margin: 4px 0 12px;
    color: #64748b;
    font-size: 14px;
}

.image-container img {
    max-width: 100%;
    max-height: 800px;
    border-radius: 12px;
    box-shadow: 0 16px 30px rgba(15, 23, 42, 0.15);
}

/* Fullscreen presentation for image */
.image-container:fullscreen {
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.image-container:fullscreen img {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
}
/* Safari/legacy vendor prefixes */
.image-container:-webkit-full-screen { background: #000; display:flex; align-items:center; justify-content:center; }
.image-container:-webkit-full-screen img { max-width: 100vw; max-height: 100vh; border-radius: 0; box-shadow: none; }

.no-image {
    padding: 32px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 12px;
    color: #92400e;
    font-size: 18px;
}

/* TOTP secret page */
.totp-warning {
    background: #fff4e6;
    border: 1px solid #ffcd94;
    color: #8a6116;
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 24px;
}

.status-message {
    font-size: 16px;
    margin-bottom: 18px;
    color: #374151;
}

.qr-wrapper {
    display: flex;
    justify-content: center;
    margin: 28px 0;
}

.qr-wrapper img {
    border: 12px solid #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
}

.secret-display {
    font-family: 'Fira Code', Menlo, monospace;
    font-size: 20px;
    letter-spacing: 2px;
    background: #eef2f7;
    padding: 14px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 18px;
}

.provisioning-uri {
    word-break: break-all;
    font-family: 'Fira Code', Menlo, monospace;
    background: #f0f4f8;
    padding: 14px;
    border-radius: 8px;
    margin-top: 18px;
}

.footer-note {
    margin-top: 24px;
    font-size: 14px;
    color: #6b7280;
}

/* Utility */
.text-center {
    text-align: center;
}

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

/* Simple theming */
body.theme-dark {
    background-color: #0b1220;
    color: #e5e7eb;
}
html.theme-dark {
    background-color: #0b1220;
}
.theme-dark a { color: #60a5fa; }
.theme-dark a:hover { color: #93c5fd; }
.theme-dark a:visited { color: #93c5fd; }
.theme-dark .top-nav {
    background-color: #0f172a;
    color: #e5e7eb;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.theme-dark .top-nav a { color: #e5e7eb; }
.theme-dark .nav-title a { color: #ffffff; }
.theme-dark .nav-dropdown-toggle { background: rgba(99, 102, 241, 0.2); color: #e5e7eb; }
.theme-dark .nav-dropdown-toggle:hover,
.theme-dark .nav-dropdown-toggle:focus { background: rgba(99, 102, 241, 0.3); }
.theme-dark .nav-dropdown-menu { background: #111827; box-shadow: 0 14px 30px rgba(0,0,0,0.6); border: 1px solid #374151; }
.theme-dark .nav-dropdown-menu a { color: #e5e7eb; }
.theme-dark .nav-dropdown-menu a:hover { background-color: #1f2937; color: #93c5fd; }

/* Top bar inline user/session pills */
.theme-dark .nav-user { background: #1f2937; color: #ffffff; }
.theme-dark .nav-userline { color: #ffffff; }
.theme-dark .nav-session { color: #ffffff !important; }

.theme-dark .sidebar { background-color: #111827; color: #e5e7eb; box-shadow: 4px 0 16px rgba(0,0,0,0.5); }
.theme-dark .container { background: #0f172a; color: #e5e7eb; box-shadow: 0 12px 30px rgba(0,0,0,0.6); }
.theme-dark .card { background-color: #111827; color: #e5e7eb; box-shadow: 0 8px 20px rgba(0,0,0,0.5); }
.theme-dark .legal-content { background-color: #111827; color: #e5e7eb; box-shadow: 0 14px 32px rgba(0,0,0,0.5); }

.theme-dark .sidebar-section h4 { color: #e5e7eb; }
.theme-dark .user-links a, .theme-dark .info-links a { background-color: #1f2937; color: #e5e7eb; border-color: #374151; }
.theme-dark .user-links a:hover, .theme-dark .info-links a:hover { background-color: #374151; }

.theme-dark .flash-message { background-color: #111827; border-color: #374151; color: #cbd5e1; }
.theme-dark .alert-info { background: #0c4a6e; border-color: #38bdf8; color: #e0f2fe; }
.theme-dark .alert-error { background: #7f1d1d; border-color: #ef4444; color: #fee2e2; }
.theme-dark .alert-success { background: #064e3b; border-color: #10b981; color: #d1fae5; }

.theme-dark input[type="text"],
.theme-dark input[type="password"],
.theme-dark input[type="email"],
.theme-dark input[type="tel"],
.theme-dark textarea {
    background: #111827;
    color: #e5e7eb;
    border-color: #374151;
}
.theme-dark ::placeholder { color: #94a3b8; opacity: 1; }
.theme-dark input[type="text"]:focus,
.theme-dark input[type="password"]:focus,
.theme-dark input[type="email"]:focus,
.theme-dark input[type="tel"]:focus,
.theme-dark textarea:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.theme-dark .primary-btn { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.theme-dark .filename { background-color: #374151; color: #e5e7eb; }
.theme-dark .image-details { background-color: #1f2937; border-left-color: #22c55e; }
.theme-dark .image-title { color: #e5e7eb; }
.theme-dark .image-age-line { color: #cbd5e1; }
.theme-dark .no-image { background: #1f2937; border-color: #374151; color: #e5e7eb; }