/* Theme variables */
:root {
    --color-bg: #f9f9f9;
    --color-surface: #fff;
    --color-text: #333;
    --color-primary: #2a9d8f;
    --color-primary-hover: #21867a;
    --color-header-bg: var(--color-primary);
    --color-header-text: #fff;
    --color-accent: #28a745;
    --color-accent-hover: #1e7e34;
    --color-border: #ccc;
    --color-divider: #eee;
    --color-badge-bg: #2a9d8f;
    --color-message-error-bg: #ffd6d6;
    --color-message-error-text: #a10000;
    --color-message-success-bg: #d6ffd6;
    --color-message-success-text: #006600;
    --color-success: #006600;
    --color-danger: #a10000;
    --color-footer-text: #666;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #121212;
        --color-surface: #1e1e1e;
        --color-text: #eee;
        --color-primary: #55c8be;
        --color-primary-hover: #3aa49a;
        --color-header-bg: var(--color-primary);
        --color-header-text: #fff;
        --color-accent: #28a745;
        --color-accent-hover: #1e7e34;
        --color-border: #555;
        --color-divider: #444;
        --color-badge-bg: #55c8be;
        --color-message-error-bg: #6e2e2e;
        --color-message-error-text: #ffd6d6;
        --color-message-success-bg: #2e6e2e;
        --color-message-success-text: #d6ffd6;
        --color-success: #d6ffd6;
        --color-danger: #ffd6d6;
        --color-footer-text: #aaa;
    }
}

/* Global styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    margin: 0;
    padding: 0;
    font-size: 18px;
    line-height: 1.6;
}

a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

header {
    background-color: var(--color-header-bg);
    color: var(--color-header-text);
    padding: 1rem 0;
    margin-bottom: 1rem;
    position: relative;
}

nav.nav-links {
    flex: 1;
}

.nav-links ul {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 1rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links a {
    color: var(--color-header-text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 1.125rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
}

.nav-links a[aria-current="page"] {
    background-color: var(--color-primary-hover);
}

.nav-links a:hover,
.nav-links a:focus {
    background-color: var(--color-primary-hover);
}

.nav-links a .badge {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(50%, -50%);
    padding: 0 0.3rem;
    border-radius: 999px;
    font-size: 0.75rem;
    margin: 0;
}


.bar-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem;
}

.brand {
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--color-header-text);
    text-decoration: none;
    white-space: nowrap;
}

.icon {
    width: 1rem;
    height: 1rem;
}

#song-search,
#member-search {
    display: block;
    margin-bottom: 1rem;
    max-width: 300px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background-color: var(--color-surface);
    color: var(--color-text);
}

.song-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.member-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.member-item {
    border-bottom: 1px solid var(--color-divider);
    padding: 0.5rem 0;
}

.member-name {
    font-size: 1.125rem;
    font-weight: bold;
}

.member-email {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: var(--color-text);
    text-decoration: none;
}

.member-email:hover,
.member-email:focus {
    text-decoration: underline;
}

.inline-edit {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}

.inline-edit input[type="text"],
.inline-edit select,
.inline-edit textarea {
    flex: 1;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background-color: var(--color-surface);
    color: var(--color-text);
}

@media (max-width: 600px) {
    #song-search,
    #member-search {
        max-width: 100%;
    }
}

.visually-hidden {
    position: absolute;
    left: -9999px;
}

/* menu toggle removed */

.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
    background: var(--color-primary);
    color: var(--color-header-text);
    padding: 0.5rem 1rem;
    z-index: 100;
}

.skip-link:focus {
    left: 0;
}

.container {
    max-width: 700px;
    background: var(--color-surface);
    margin: 2rem auto;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

h1, h2 {
    margin-top: 0;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group.drag {
    border: 2px dashed var(--color-primary);
    padding: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
}
.form-group input[type="checkbox"] {
    width: auto;
}
.form-group input[type="checkbox"] + label {
    display: inline-block;
    margin: 0 0 0 0.5rem;
    font-weight: normal;
}

.grow-textarea {
    width: 100%;
    min-height: 150px;
    max-height: 40vh;
    overflow-y: auto;
    resize: none;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
}

.btn {
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 4px;
    background-color: var(--color-primary);
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

.btn:hover,
.btn:focus {
    background-color: var(--color-primary-hover);
    color: #fff;
}

.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
    display: block;
}

.song-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-divider);
    padding: 0.5rem 0;
}

.hidden { display: none; }

.fab-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
}

.floating-add {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    background-color: #006400;
    color: #fff;
    border: none;
    line-height: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    cursor: pointer;
    padding: 0;
}

.floating-add svg {
    width: 2.5rem;
    height: 2.5rem;
}

.floating-add:hover,
.floating-add:focus {
    background-color: #004d00;
}

.fab-menu {
    position: absolute;
    right: 0;
    bottom: 4.5rem;
    background: #006400;
    color: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    display: none;
    flex-direction: column;
    z-index: -1;
    overflow: hidden;
}

.fab-container:hover .fab-menu,
.fab-menu:hover {
    display: flex;
}

.fab-menu button {
    background: none;
    border: none;
    color: #fff;
    padding: 0.5rem 1rem;
    text-align: left;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
}

.fab-menu button:hover,
.fab-menu button:focus {
    background: rgba(0,0,0,0.2);
}

.add-tooltip {
    position: fixed;
    bottom: 6.5rem;
    right: 1rem;
    background: #006400;
    color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    display: none;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.fab-container:hover + .add-tooltip,
.fab-container:focus-within + .add-tooltip {
    display: block;
}

.song-item[draggable="true"] {
    cursor: move;
}

.song-list.drag {
    background-color: var(--color-divider);
}

.group-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.group-tile {
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: var(--color-surface);
}

.group-tile > summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    list-style: none;
}

.group-tile > summary::-webkit-details-marker { display: none; }

.group-tile[open] > summary {
    border-bottom: 1px solid var(--color-border);
}

.group-tile .group-name {
    font-size: 1.125rem;
    color: var(--color-text);
    text-decoration: none;
}

.group-tile .actions {
    display: flex;
    gap: 0.5rem;
}

.group-tile .song-list {
    padding: 0 1rem 1rem;
}

.empty-group {
    padding: 0 1rem 1rem;
    color: var(--color-muted);
}

.add-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.add-panel.hidden { display: none; }

.add-panel .panel-inner {
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    position: relative;
}

.add-panel .close {
    position: absolute;
    top: .5rem;
    right: .5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

.add-panel .step { display: none; }
.add-panel .step.active { display: block; }

.actions { display: flex; gap: 1rem; }
.actions button { flex: 1; }

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    background-color: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

.btn-small:hover,
.btn-small:focus {
    background-color: var(--color-primary-hover);
    color: #fff;
}

.song-item .actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    padding: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 44px;
    min-height: 44px;
    position: relative;
}

.icon-btn svg {
    width: 1rem;
    height: 1rem;
}

.icon-btn:hover,
.icon-btn:focus {
    background-color: var(--color-divider);
    border-radius: 4px;
}

.badge {
    display: inline-block;
    background: var(--color-badge-bg);
    color: var(--color-header-text);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.icon-btn .badge {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(50%, -50%);
    padding: 0 0.3rem;
    border-radius: 999px;
    font-size: 0.75rem;
    margin: 0;
}

.user-selector {
    max-width: 300px;
    margin-bottom: 1rem;
}

.user-card {
    display: none;
    border: 1px solid var(--color-border);
    padding: 1rem;
    border-radius: 4px;
    background-color: var(--color-surface);
    max-width: 300px;
}

.admin-spaced {
    margin-bottom: 1rem;
}

.user-card .user-email {
    font-weight: bold;
}

.user-card .user-role {
    margin-left: 0.5rem;
}

.user-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--color-surface);
    padding: 1rem;
    border-radius: 4px;
    max-width: 400px;
    width: 90%;
}

.modal-content textarea {
    width: 100%;
    margin-top: 0.5rem;
}

.modal-buttons {
    margin-top: 0.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.message {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.message.error {
    background-color: var(--color-message-error-bg);
    color: var(--color-message-error-text);
}

.message.success {
    background-color: var(--color-message-success-bg);
    color: var(--color-message-success-text);
}

details.collapse {
    margin-bottom: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    background-color: var(--color-surface);
}

details.collapse summary {
    cursor: pointer;
    font-weight: bold;
    margin: 0;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

footer {
    text-align: center;
    padding: 1rem 0;
    color: var(--color-footer-text);
}


.form-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.save-btn {
    color: var(--color-primary);
}
.collapse .content {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
    padding: 0 0.5rem 0.5rem;
}

.file-item summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.file-item .file-name {
    flex: 1;
}

.pdf-frame {
    width: 100%;
    height: 80vh;
    border: 1px solid var(--color-border);
    margin-top: 0.5rem;
}

.voice-part {
    margin-bottom: 1rem;
}

.voice-part h4 {
    margin: 0 0 0.25rem;
    font-size: 1rem;
}

.voice-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.voice-controls audio {
    flex: 1;
}

.variant-label {
    font-size: 0.875rem;
    white-space: nowrap;
}

.song-top h1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.song-top p {
    margin: 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.account-section {
    margin-top: 1rem;
}

.account-section summary {
    cursor: pointer;
    font-weight: 600;
}

.account-section[open] summary {
    margin-bottom: 0.5rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: var(--color-primary);
}

.edit-page-btn {
    display: inline-block;
    background: var(--color-primary);
    color: var(--color-header-text);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    margin-bottom: 1rem;
}

.edit-page-btn:hover,
.edit-page-btn:focus {
    background: var(--color-primary-hover);
}

.password-req {
    list-style: none;
    padding-left: 1rem;
    font-size: 0.9rem;
}
.password-req li {
    color: var(--color-danger);
}
.password-req li.valid {
    color: var(--color-success);
}
.password-error {
    color: var(--color-danger);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}


body.no-page-scroll {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.no-page-scroll main.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    max-width: 700px;
    padding: 1rem;
    overflow: hidden;
}

.messages-page {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.chat-date {
    text-align: center;
    margin: 1rem 0;
    position: relative;
    font-size: 0.85rem;
    color: var(--color-footer-text);
}
.chat-date::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px solid var(--color-divider);
}
.chat-date span {
    background: var(--color-bg);
    padding: 0 0.5rem;
    position: relative;
}

.chat-message {
    padding: 0.5rem;
    border-bottom: 1px solid var(--color-divider);
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    color: var(--color-footer-text);
}

.message-form {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--color-divider);
    padding-top: 0.5rem;
}

#message-input {
    flex: 1;
    resize: none;
}

@media (max-width: 600px) {
    .btn {
        font-size: 1rem;
    }
}

/* Large song selection dropdown */
details.song-dropdown summary {
    cursor: pointer;
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background-color: var(--color-surface);
}

details.song-dropdown[open] .song-options {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-top: 0.5rem;
    max-height: 20rem;
    overflow: auto;
    padding: 0.5rem;
    background-color: var(--color-surface);
    width: 100%;
}

details.song-dropdown[open] #song-search {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.song-options label {
    display: block;
    margin-bottom: 0.25rem;
}

/* Login page background */
body.login-page {
    background: #333 url('/uploads/placeholder/vox-bg.jpg') center/cover no-repeat;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.login-page main.login-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.9);
    margin: 2rem auto;
    max-width: 400px;
}

@media (prefers-color-scheme: dark) {
    body.login-page main.login-main {
        background: rgba(30,30,30,0.9);
    }
}


/* ===== Add Song wizard layout (scoped) ===== */
section.wizard {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden; /* was: overflow: hidden */
  overflow-y: visible;
}

/* Always visible title bar */
.wizard-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-surface);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-divider);
  backdrop-filter: saturate(120%) blur(6px);
  -webkit-backdrop-filter: saturate(120%) blur(6px);
}

/* Scrollable middle */
.wizard-body {
  flex: 1 1 auto;
  min-height: 0;         /* keeps flex child shrinkable */
  overflow: visible;     /* vertical scroll is on section.wizard */
  padding-bottom: 1rem;
}


/* Always visible action bar */
.wizard-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--color-surface);
  padding: 0.75rem 0;
  border-top: 1px solid var(--color-divider);
  backdrop-filter: saturate(120%) blur(6px);
  -webkit-backdrop-filter: saturate(120%) blur(6px);
}
.wizard-footer .btn-row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Step 2: horizontal scroll strip for the MP3 fieldsets */
.uploads-strip {
  width: 100%;
  overflow-x: auto !important;  /* horizontal scroll lives here */
  overflow-y: hidden;
  padding-bottom: 0.25rem;
  /* subtle fade on edges to hint scroll */
  mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
}

.uploads-inner {
  display: inline-flex;     /* single row */
  gap: 1rem;
  padding: 0.25rem 0;
  min-width: 100%;
}

.uploads-inner fieldset.form-group {
  flex: 0 0 auto;           /* don’t shrink */
  min-width: 14rem;         /* tweak as you like (14–18rem works well) */
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.uploads-inner legend { font-weight: 600; margin-bottom: 0.25rem; }
.uploads-inner label { display: block; margin-top: 0.5rem; }

/* Keep buttons usable on small screens */
@media (max-width: 520px) {
  .wizard-footer .btn-row { justify-content: space-between; }
}


/* --- Mobile-friendly topbar: keep everything accessible --- */
.topbar { position: sticky; top: 0; z-index: 10; }

.bar-inner {
  max-width: 100%;
  padding: 0 .5rem;
  gap: .5rem;
}

.nav-links ul {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  gap: .5rem;
  padding-bottom: .25rem; /* thumb room */
}
.nav-links a {
  flex: 0 0 auto;         /* prevent squish, allow scroll */
  padding: .4rem .6rem;
}

/* Hide text labels on very narrow screens (icons remain, badges stay) */
@media (max-width: 480px) {
  .nav-links a span:not(.visually-hidden) { display: none; }
  .nav-links a { padding: .5rem; }          /* tighter hit area */
}

/* Keep message badge visible and positioned on tiny screens */
.nav-links a .badge {
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
}

/* Optional: subtle fade edges to hint horizontal scroll */
.nav-links ul {
  mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
}

/* Respect iOS safe areas for topbar on notched phones */
.topbar { padding-left: calc(1rem + env(safe-area-inset-left, 0px));
          padding-right: calc(1rem + env(safe-area-inset-right, 0px)); }


/* --- Global, gentle fluid type and media scaling --- */
html { -webkit-text-size-adjust: 100%; }
body { font-size: clamp(16px, 1.6vw + 0.2rem, 18px); }
img, video, canvas, iframe { max-width: 100%; height: auto; }

/* Container, buttons, and forms on small screens */
@media (max-width: 600px) {
  .container { margin: .75rem auto; padding: 1rem; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
  header { padding: .5rem 0; margin-bottom: .5rem; }
  .btn { font-size: 1rem; padding: .65rem 1rem; }
  .btn-small { font-size: .95rem; padding: .5rem .75rem; }
}

/* FAB size + safe-area */
.fab-container { 
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  right: calc(1rem + env(safe-area-inset-right, 0px));
}
@media (max-width: 600px) {
  .floating-add { width: 3.5rem; height: 3.5rem; }
  .floating-add svg { width: 1.75rem; height: 1.75rem; }
  .fab-menu { bottom: 3.25rem; }
}
.fab-container:focus-within .fab-menu { display: flex; }

/* Sticky wizard bars: safe-area padding */
.wizard-header, .wizard-footer {
  padding-left: calc(.75rem + env(safe-area-inset-left, 0px));
  padding-right: calc(.75rem + env(safe-area-inset-right, 0px));
}
.wizard-footer { padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px)); }

/* Inline edits wrap on very small screens */
@media (max-width: 420px) {
  .inline-edit { flex-wrap: wrap; }
  .inline-edit input[type="text"], .inline-edit select, .inline-edit textarea { min-width: 100%; }
}

/* PDF frame a bit shorter on phones */
@media (max-width: 600px) { .pdf-frame { height: 65vh; } }

/* Lists and tiles a touch lighter on phones */
@media (max-width: 600px) {
  .group-tile > summary { padding: .75rem; }
  .song-item { padding: .5rem 0; }
  .song-item .actions { gap: .25rem; }
}

/* Song dropdown: comfy on phones */
@media (max-width: 600px) {
  details.song-dropdown summary { padding: .5rem; }
  details.song-dropdown[open] .song-options { max-height: 60vh; }
}

/* Messages page spacing */
@media (max-width: 600px) {
  .message-form { padding: .5rem 0; }
  .chat-list { margin-bottom: .5rem; }
}

/* Login page on phones */
@media (max-width: 600px) {
  body.login-page main.login-main { margin: 1rem; max-width: none; }
}

/* Prevent horizontal jiggle from long strings */
* { min-width: 0; }
.container, .group-tile, .song-item, .inline-edit, .voice-controls { overflow-wrap: anywhere; }

/* --- Mobile-friendly topbar: keep everything accessible --- */
.topbar { position: sticky; top: 0; z-index: 10; }

.bar-inner {
  max-width: 100%;
  padding: 0 .5rem;
  gap: .5rem;
}

.nav-links ul {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  gap: .5rem;
  padding-bottom: .25rem; /* thumb room */
}
.nav-links a {
  flex: 0 0 auto;         /* prevent squish, allow scroll */
  padding: .4rem .6rem;
}

/* Hide text labels on very narrow screens (icons remain, badges stay) */
@media (max-width: 480px) {
  .nav-links a span:not(.visually-hidden) { display: none; }
  .nav-links a { padding: .5rem; }
}

/* Keep message badge visible */
.nav-links a .badge {
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
}

/* Subtle fade edges for scroll hint */
.nav-links ul {
  mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
}

/* Respect iOS safe areas */
.topbar {
  padding-left: calc(1rem + env(safe-area-inset-left, 0px));
  padding-right: calc(1rem + env(safe-area-inset-right, 0px));
}

/* --- Global, gentle fluid type and media scaling --- */
html { -webkit-text-size-adjust: 100%; }
body { font-size: clamp(16px, 1.6vw + 0.2rem, 18px); }
img, video, canvas, iframe { max-width: 100%; height: auto; }

/* Container, buttons, and forms on small screens */
@media (max-width: 600px) {
  .container { margin: .75rem auto; padding: 1rem; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
  header { padding: .5rem 0; margin-bottom: .5rem; }
  .btn { font-size: 1rem; padding: .65rem 1rem; }
  .btn-small { font-size: .95rem; padding: .5rem .75rem; }
}

/* FAB size + safe-area */
.fab-container { 
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  right: calc(1rem + env(safe-area-inset-right, 0px));
}
@media (max-width: 600px) {
  .floating-add { width: 3.5rem; height: 3.5rem; }
  .floating-add svg { width: 1.75rem; height: 1.75rem; }
  .fab-menu { bottom: 3.25rem; }
}
.fab-container:focus-within .fab-menu { display: flex; }

/* Sticky wizard bars: safe-area padding */
.wizard-header, .wizard-footer {
  padding-left: calc(.75rem + env(safe-area-inset-left, 0px));
  padding-right: calc(.75rem + env(safe-area-inset-right, 0px));
}
.wizard-footer { padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px)); }

/* Inline edits wrap on very small screens */
@media (max-width: 420px) {
  .inline-edit { flex-wrap: wrap; }
  .inline-edit input[type="text"], .inline-edit select, .inline-edit textarea { min-width: 100%; }
}

/* PDF frame a bit shorter on phones */
@media (max-width: 600px) { .pdf-frame { height: 65vh; } }

/* Lists and tiles a touch lighter on phones */
@media (max-width: 600px) {
  .group-tile > summary { padding: .75rem; }
  .song-item { padding: .5rem 0; }
  .song-item .actions { gap: .25rem; }
}

/* Song dropdown: comfy on phones */
@media (max-width: 600px) {
  details.song-dropdown summary { padding: .5rem; }
  details.song-dropdown[open] .song-options { max-height: 60vh; }
}

/* Login page on phones */
@media (max-width: 600px) {
  body.login-page main.login-main { margin: 1rem; max-width: none; }
}

/* Prevent horizontal jiggle from long strings */
* { min-width: 0; }
.container, .group-tile, .song-item, .inline-edit, .voice-controls { overflow-wrap: anywhere; }

/* === Messages page polished chat layout (keeps 700px width like other tabs) === */
section.messages-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 700px;   /* same width as other tabs */
  margin: 0 auto;
  padding: 1rem;
  gap: 1rem;
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Chat list scrolls with spacing */
.chat-list {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  padding: 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Generic bubble style */
.chat-message {
  max-width: 80%;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  word-wrap: break-word;
}

/* Messages from others (left, light background) */
.chat-message.other {
  align-self: flex-start;
  background: var(--color-bg);
  color: var(--color-text);
  border-bottom-left-radius: 0;
}

/* Messages from me (right, primary color) */
.chat-message.mine {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 0;
}

/* Meta info (name + time) */
.chat-meta {
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  display: flex;
  justify-content: space-between;
  opacity: 0.8;
}

/* Date separators */
.chat-date {
  text-align: center;
  margin: 1rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--color-footer-text);
  position: relative;
}
.chat-date::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  border-top: 1px solid var(--color-divider);
}
.chat-date span {
  background: var(--color-surface);
  padding: 0 0.5rem;
  position: relative;
}

/* Message form */
.message-form {
  display: flex;
  align-items: flex-end;
  width: 100%;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
  border-radius: 0 0 8px 8px;
}

/* Input box */
#message-input {
  flex: 1;
  min-height: 2.5rem;
  max-height: 30vh;
  resize: none;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1.4;
}

/* Send button */
.message-form .btn {
  flex-shrink: 0;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border-radius: 6px;
}
