/* Service Translator — shared styles for visitor + admin pages. */

/* Light is the standard theme; dark is opt-in via data-theme="dark" on <html>
   (persisted in localStorage by theme.js). */
:root {
    color-scheme: light;
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #d9dde5;
    --text: #171b26;
    --text-dim: #4d5468;
    --text-faint: #878ea1;
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --gold: #9a7b1f;
    --gold-soft: rgba(154, 123, 31, 0.12);
    --success: #059669;
    --success-hover: #047857;
    --success-contrast: #ffffff;
    --success-soft: rgba(5, 150, 105, 0.12);
    --warning: #b45309;
    --error: #dc2626;
    --error-soft: rgba(220, 38, 38, 0.1);
    --radius: 14px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b0d12;
    --surface: #14171f;
    --surface-2: #1a1e28;
    --border: #262b38;
    --text: #e8eaf0;
    --text-dim: #9aa1b2;
    --text-faint: #6b7280;
    --accent: #3b82f6;
    --accent-strong: #2563eb;
    --gold: #d4a843;
    --gold-soft: rgba(212, 168, 67, 0.14);
    --success: #34d399;
    --success-hover: #2bbd87;
    --success-contrast: #06281c;
    --success-soft: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --error: #f87171;
    --error-soft: rgba(248, 113, 113, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 1280px;
    margin: 0 auto;
    padding: max(0.75rem, env(safe-area-inset-top))
             max(1rem, env(safe-area-inset-right))
             max(0.75rem, env(safe-area-inset-bottom))
             max(1rem, env(safe-area-inset-left));
    gap: 0.75rem;
}

/* --- Focus visibility (keyboard access) ------------------------------------- */

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
.bible-ref-chip:focus-visible,
.session-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Top bar -------------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.brand .brand-mark {
    width: 1.65rem;
    height: 1.65rem;
    flex: none;
    border-radius: 7px;
}

.brand h1 {
    margin: 0;
    font-size: clamp(1.05rem, 2.5vw, 1.3rem);
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.brand .tag {
    font-size: 0.75rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-dim);
    max-width: 100%;
}

.status-pill::before {
    content: '';
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-faint);
}

.status-pill[data-level="success"]::before { background: var(--success); }
.status-pill[data-level="warning"]::before { background: var(--warning); }
.status-pill[data-level="error"]::before   { background: var(--error); }

/* --- Controls --------------------------------------------------------------- */

.controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.controls-step {
    flex: none;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    padding-right: 0.25rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.control-group.grow {
    flex: 1;
    min-width: 200px;
}

.control-group label {
    font-size: 0.78rem;
    color: var(--text-dim);
    white-space: nowrap;
}

select {
    appearance: none;
    background: var(--surface-2) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 0.7rem center;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 1.9rem 0.45rem 0.7rem;
    font-size: 0.85rem;
    font-family: inherit;
}

:root[data-theme="dark"] select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239aa1b2' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

select:disabled {
    opacity: 0.5;
}

.text-input {
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
    font-family: inherit;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    width: 100%;
}

.text-input::placeholder {
    color: var(--text-faint);
}

button {
    appearance: none;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1.1rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    background: var(--accent-strong);
    color: #fff;
    transition: background 0.15s, opacity 0.15s;
}

button:hover:not(:disabled) {
    background: var(--accent);
}

button.secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

button.secondary:hover:not(:disabled) {
    background: var(--border);
}

button.danger {
    background: var(--surface-2);
    color: var(--error);
    border: 1px solid var(--border);
}

button.danger:hover:not(:disabled) {
    background: var(--error-soft);
    border-color: var(--error);
}

/* Disabled state must win over the variant styles above. */
button:disabled {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-faint);
    cursor: not-allowed;
}

.admin-link {
    color: var(--text-faint);
    padding: 6px 8px;
    text-decoration: none;
    font-size: 0.8rem;
    white-space: nowrap;
}

.admin-link:hover {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --- Top nav (admin pages) ------------------------------------------------- */

.topnav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.topnav .navlink,
.navlink {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
}

.navlink:hover {
    background: var(--border);
}

.navlink.active {
    border-color: var(--accent);
    color: var(--accent);
    cursor: default;
}

.navlink.active:hover {
    background: var(--surface-2);
}

.topnav form {
    margin: 0;
}

/* --- Theme toggle ------------------------------------------------------------ */

.theme-toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.theme-toggle:hover:not(:disabled) {
    background: var(--border);
    color: var(--text);
}

.theme-toggle svg {
    width: 1.05rem;
    height: 1.05rem;
    display: block;
}

/* Show the theme you'd switch to: moon in light mode, sun in dark mode. */
.theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

.spacer {
    flex: 1;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 1rem;
    height: 1rem;
    margin: 0;
}

button[hidden] {
    display: none;
}

.viewer-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
}

.viewer-pill::before {
    content: '';
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--success);
}

.viewer-pill[hidden] {
    display: none;
}

button.audio-active {
    background: var(--success);
    color: var(--success-contrast);
}

button.audio-active:hover:not(:disabled) {
    background: var(--success-hover);
}

/* --- Mic level meter (admin) ------------------------------------------------ */

.mic-meter {
    width: 90px;
    height: 8px;
    flex: none;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.mic-meter[hidden] {
    display: none;
}

#mic-meter-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--success), #a7f3d0);
    transition: width 0.12s linear;
}

/* --- Session identity (viewer, after joining) ------------------------------- */

.session-info {
    min-width: 0;
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-info strong {
    color: var(--text);
    font-weight: 600;
}

.session-info[hidden] {
    display: none;
}

/* --- Session list (viewer landing) ------------------------------------------ */

#session-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 0;
    overflow-y: auto;
}

.session-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s;
}

.session-card:hover {
    border-color: var(--accent);
}

.session-card .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.session-card .title {
    font-weight: 600;
}

.session-card .sub {
    font-size: 13px;
    color: var(--text-dim);
}

.badge {
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}

.badge.live {
    background: var(--success-soft);
    color: var(--success);
}

.badge.idle {
    background: var(--surface-2);
    color: var(--text-dim);
}

.empty {
    color: var(--text-dim);
    padding: 24px 12px;
    text-align: center;
}

#back-btn {
    margin-right: 8px;
}

/* --- Auth (login) ------------------------------------------------------------ */

.auth-card {
    width: 100%;
    max-width: 380px;
    margin: 12vh auto;
    padding: 24px;
    flex: none;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-card .text-input {
    font-size: 16px; /* prevents iOS zoom-on-focus */
}

.auth-error {
    color: var(--error);
    font-size: 14px;
    min-height: 18px;
}

/* --- Settings (super admin) --------------------------------------------------- */

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    overflow-y: auto;
}

@media (max-width: 720px) {
    .grid {
        grid-template-columns: 1fr;
    }
}

.grid .panel form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 14px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-dim);
    font-weight: 600;
}

.msg {
    font-size: 13px;
    min-height: 16px;
}

.msg.err { color: var(--error); }
.msg.ok  { color: var(--success); }

/* --- Main layout ------------------------------------------------------------ */

/* Visitor's chosen-session view wraps <main> in a div. It must itself be a
   flex column that fills the app, otherwise the .app height:100dvh constraint
   never reaches <main> and its panels can't become scroll containers — the
   whole page scrolls instead and live text drifts below the fold (broken
   auto-scroll, most visible on tablets). :not([hidden]) keeps it display:none
   while on the session list. */
#session-view:not([hidden]) {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-label {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
}

.panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.6rem 1.1rem 1rem;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* Verse panel */

#verse-panel {
    flex: none;
}

#verse-panel .panel-label {
    color: var(--gold);
}

#presentation-bible-verse {
    font-size: clamp(1.05rem, 2.6vw, 1.45rem);
    line-height: 1.55;
    transition: opacity 0.4s ease;
}

#presentation-bible-verse:empty::before {
    content: attr(data-empty);
    font-size: 0.85rem;
    color: var(--text-faint);
}

.verse-reference {
    display: block;
    font-size: 0.8em;
    font-weight: 650;
    color: var(--gold);
    margin-bottom: 0.25rem;
}

#presentation-bible-verse a {
    color: inherit;
    text-decoration: none;
}

#presentation-bible-verse a:hover .verse-text {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

/* Verse history chips */

#bible-history-strip {
    flex: none;
    display: flex;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 0.25rem;
    min-height: 2.4rem;
}

#bible-history-strip::-webkit-scrollbar {
    display: none;
}

#bible-history {
    display: flex;
    gap: 0.5rem;
}

#bible-history:empty {
    display: none;
}

.bible-ref-chip {
    flex: none;
    padding: 0.32rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.82rem;
    color: var(--text-dim);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.bible-ref-chip:hover {
    color: var(--text);
    border-color: var(--text-faint);
}

.bible-ref-chip.newest {
    background: var(--gold-soft);
    border-color: var(--gold);
    color: var(--gold);
    font-weight: 600;
}

/* Translation panel */

#translation-panel {
    flex: 1;
}

#presentation-history {
    font-size: clamp(1.15rem, 3vw, 1.6rem);
    line-height: 1.65;
    color: var(--text);
    overflow-anchor: none;
}

#presentation-history:empty::before {
    content: attr(data-empty);
    font-size: 0.85rem;
    color: var(--text-faint);
}

#presentation-history .interim-stable {
    color: var(--text-faint);
}

/* --- Wide screens (iPad landscape / laptop): two columns -------------------- */

@media (min-width: 900px) {
    main {
        display: grid;
        grid-template-columns: 5fr 7fr;
        grid-template-rows: 1fr auto;
        grid-template-areas:
            "verse history"
            "chips history";
    }

    #verse-panel {
        grid-area: verse;
        min-height: 0;
    }

    #bible-history-strip {
        grid-area: chips;
    }

    #translation-panel {
        grid-area: history;
    }
}

/* Compact phones: tighten paddings */

@media (max-width: 480px) {
    .app {
        gap: 0.5rem;
    }

    .panel-body {
        padding: 0.5rem 0.85rem 0.85rem;
    }

    .controls {
        padding: 0.6rem 0.85rem;
    }
}

/* Scrollbars */

.panel-body::-webkit-scrollbar {
    width: 8px;
}

.panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.panel-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}
