/* ============================================
   Church Worship App — Stylesheet
   Font: Source Sans 3 (body), JetBrains Mono (chords)
   Palette: Warm neutral with deep blue accent
   ============================================ */

:root {
    --font-body: 'Source Sans 3', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;

    --color-bg: #faf9f7;
    --color-surface: #ffffff;
    --color-border: #e2ddd5;
    --color-border-light: #f0ece6;
    --color-text: #2c2a26;
    --color-text-muted: #7a746a;
    --color-text-light: #a39d93;

    --color-primary: #2b4c7e;
    --color-primary-hover: #1d3a63;
    --color-primary-light: #e8eef5;
    --color-primary-bg: #f4f7fb;

    --color-accent: #8b6914;
    --color-accent-light: #fdf6e3;

    --color-danger: #9e2b25;
    --color-danger-light: #fdf0ef;
    --color-success: #2e6b3a;
    --color-success-light: #eef7f0;
    --color-warning: #8b6914;
    --color-warning-light: #fdf6e3;

    --radius: 6px;
    --radius-lg: 10px;
    --shadow-sm: 0 1px 3px rgba(44, 42, 38, 0.06);
    --shadow: 0 2px 8px rgba(44, 42, 38, 0.08);
    --shadow-lg: 0 4px 16px rgba(44, 42, 38, 0.1);

    --nav-height: 56px;
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ============================================
   LAYOUT
   ============================================ */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

main.container {
    flex: 1;
    padding-top: 2rem;
    padding-bottom: 3rem;
}

/* ============================================
   NAVIGATION
   ============================================ */
.main-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--nav-height);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    height: 100%;
    gap: 2rem;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text) !important;
    text-decoration: none !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.brand-icon {
    font-size: 1.3rem;
    color: var(--color-primary);
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-link {
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius);
    color: var(--color-text-muted) !important;
    font-weight: 500;
    font-size: 0.93rem;
    text-decoration: none !important;
    transition: all 0.15s;
}

.nav-link:hover {
    background: var(--color-primary-light);
    color: var(--color-primary) !important;
}

.nav-link.active {
    background: var(--color-primary-light);
    color: var(--color-primary) !important;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text);
}

.nav-link-small {
    font-size: 0.82rem;
    color: var(--color-text-muted) !important;
    text-decoration: none !important;
}

.nav-link-small:hover {
    color: var(--color-primary) !important;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text);
    border-radius: 1px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
}

h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.35rem; margin-bottom: 0.4rem; }
h3 { font-size: 1.1rem; margin-bottom: 0.3rem; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 { margin-bottom: 0; }

.subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-top: 0.15rem;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff !important;
    border-color: var(--color-primary);
}
.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: #fff !important;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text) !important;
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-bg);
    border-color: var(--color-text-light);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff !important;
    border-color: var(--color-danger);
}
.btn-danger:hover {
    background: #8a2420;
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.82rem;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted) !important;
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--color-bg);
    color: var(--color-text) !important;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
    color: var(--color-text);
}

.form-group .hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.93rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

textarea.chord-input {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.7;
    min-height: 200px;
    tab-size: 4;
}

select {
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.inline-select {
    width: auto;
    display: inline-block;
    padding: 0.3rem 0.5rem;
    font-size: 0.88rem;
}

/* ============================================
   CARDS & PANELS
   ============================================ */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.card-compact {
    padding: 1rem 1.25rem;
}

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.panel-header {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-bg);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-body {
    padding: 1.25rem;
}

/* ============================================
   TABLES (song list, user list)
   ============================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
}

.data-table th {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    background: var(--color-bg);
}

.data-table tr:hover td {
    background: var(--color-primary-bg);
}

.data-table .actions {
    text-align: right;
    white-space: nowrap;
}

.data-table .code-col {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-accent);
    width: 80px;
}

.data-table .key-col {
    font-family: var(--font-mono);
    font-weight: 500;
    width: 50px;
    text-align: center;
}

/* ============================================
   CHORD CHART DISPLAY
   ============================================ */
.chord-chart {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.8;
    padding: 1rem 0;
}

.chord-section {
    margin-bottom: 0.35rem;
}

.chord-section-label {
    display: inline-block;
    min-width: 60px;
    font-weight: 600;
    color: var(--color-primary);
    margin-right: 0.5rem;
}

.chord-section.style-italic {
    font-style: italic;
}

.chord-section.style-bold {
    font-weight: 700;
}

.chord-section.style-bold .chord-section-label {
    font-weight: 800;
}

.chord-section.style-underline {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.chord-section.style-normal {
    /* default */
}

.chord-line {
    white-space: pre-wrap;
    word-break: break-word;
}

.chord-note {
    font-style: italic;
    color: var(--color-text-muted);
    font-family: var(--font-body, sans-serif);
    font-size: 0.82rem;
}

.chord-annotation {
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

.bar-sep {
    color: var(--color-text-light);
}

/* ============================================
   SET BUILDER TWO-COLUMN LAYOUT
   ============================================ */
.set-builder-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.set-builder-form {
    min-width: 0;
}

.set-builder-items {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #f3f0eb;
    padding: 0.75rem;
}

.set-builder-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border-light);
}

/* Compact metadata fields inside set builder */
.set-meta-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.set-meta-field {
    flex: 1;
    min-width: 0;
}

.set-meta-field label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-light);
    margin-bottom: 0.15rem;
}

.set-meta-field input,
.set-meta-field select {
    width: 100%;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--color-border-light);
    border-radius: 3px;
    background: var(--color-bg);
    color: var(--color-text);
}

.set-meta-field input[readonly] {
    background: var(--color-bg);
    cursor: not-allowed;
    opacity: 0.7;
}

.set-meta-divider {
    border: none;
    border-top: 1px solid var(--color-border-light);
    margin: 0.75rem 0;
}

@media (max-width: 900px) {
    .set-builder-columns {
        grid-template-columns: 1fr;
    }
    .set-builder-items {
        position: static;
        max-height: none;
    }
}

/* ============================================
   WORSHIP SET ITEMS
   ============================================ */
.set-items-list {
    list-style: none;
}

.set-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--color-surface);
    cursor: grab;
    transition: box-shadow 0.15s;
}

.set-item:hover {
    box-shadow: var(--shadow);
}

.set-item.sortable-ghost {
    opacity: 0.4;
    background: var(--color-primary-light);
}

.set-item-drag {
    color: var(--color-text-light);
    cursor: grab;
    padding: 0.2rem;
    font-size: 1.1rem;
    line-height: 1;
    user-select: none;
}

.set-item-content {
    flex: 1;
    min-width: 0;
}

.set-item-song-title {
    font-weight: 600;
}

.set-item-song-code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--color-accent);
    margin-right: 0.4rem;
}

.set-item-song-key {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.4rem;
}

.set-item-text {
    color: var(--color-text-muted);
    font-style: italic;
}

.set-item-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    border: 1px solid;
}

.alert-success {
    background: var(--color-success-light);
    border-color: #c3e0c8;
    color: var(--color-success);
}

.alert-error {
    background: var(--color-danger-light);
    border-color: #f0c6c4;
    color: var(--color-danger);
}

.alert-warning {
    background: var(--color-warning-light);
    border-color: #e8d9a8;
    color: var(--color-warning);
}

/* ============================================
   SONG SEARCH (autocomplete)
   ============================================ */
.search-wrapper {
    position: relative;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 250px;
    overflow-y: auto;
    z-index: 50;
    display: none;
}

.search-results.active { display: block; }

.search-result-item {
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.search-result-item:hover {
    background: var(--color-primary-bg);
}

/* ============================================
   KEY SELECTOR (transposition)
   ============================================ */
.key-selector {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.key-selector label {
    font-weight: 600;
    color: var(--color-text-muted);
}

.key-badge {
    font-family: var(--font-mono);
    font-weight: 600;
    background: var(--color-accent-light);
    color: var(--color-accent);
    padding: 0.15rem 0.55rem;
    border-radius: 3px;
    font-size: 0.88rem;
}

/* ============================================
   ATTACHMENTS
   ============================================ */
.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.attachment-icon {
    font-size: 1rem;
}

.attachment-name {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   FILE PREVIEW MODAL
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--color-border-light);
}

.modal-header h3 { margin-bottom: 0; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0.25rem;
    line-height: 1;
}

.modal-body {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.modal-body iframe,
.modal-body embed {
    width: 100%;
    height: 75vh;
    border: none;
}

.modal-body img {
    max-width: 100%;
    display: block;
    margin: 1rem auto;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .main-nav,
    .main-footer,
    .no-print,
    .btn,
    .set-item-actions,
    .set-item-drag {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 11pt;
        color: #000;
    }

    main.container {
        padding: 0;
        max-width: 100%;
    }

    .card, .panel {
        border: none;
        box-shadow: none;
        padding: 0;
    }

    .chord-chart {
        font-size: 9pt;
        line-height: 1.6;
    }

    .print-full .set-print-item {
        break-inside: avoid;
        margin-bottom: 0.5em;
    }

    .print-simple .set-print-item {
        padding: 0.2em 0;
        border-bottom: 1px dotted #ccc;
    }

    .print-header {
        text-align: center;
        margin-bottom: 1em;
        padding-bottom: 0.5em;
        border-bottom: 2px solid #000;
    }

    .print-header h1 {
        font-size: 14pt;
        margin-bottom: 0.2em;
    }

    .print-header .print-meta {
        font-size: 10pt;
        color: #555;
    }
}

/* ============================================
   EMPTY STATES
   ============================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.empty-state p {
    margin-bottom: 1rem;
}

/* ============================================
   UTILITIES
   ============================================ */
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: 0.85rem; }
.text-mono { font-family: var(--font-mono); }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ============================================
   AUTH PAGES (centered card)
   ============================================ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-height) - 100px);
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-card .auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .nav-links,
    .nav-user {
        display: none;
    }

    .main-nav.open .nav-links,
    .main-nav.open .nav-user {
        display: flex;
    }

    .main-nav.open {
        height: auto;
    }

    .main-nav.open .nav-inner {
        flex-wrap: wrap;
        height: auto;
        padding-bottom: 0.75rem;
    }

    .main-nav.open .nav-links {
        order: 3;
        width: 100%;
        flex-direction: column;
        gap: 0;
    }

    .main-nav.open .nav-user {
        order: 4;
        width: 100%;
        padding-top: 0.5rem;
        border-top: 1px solid var(--color-border-light);
        margin-top: 0.5rem;
    }

    .nav-toggle {
        display: flex;
        margin-left: auto;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .data-table {
        font-size: 0.88rem;
    }

    .data-table th:nth-child(n+3),
    .data-table td:nth-child(n+3) {
        display: none;
    }

    h1 { font-size: 1.4rem; }
}

/* ============================================
   DASHBOARD
   ============================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

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

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

.recent-list {
    list-style: none;
}

.recent-list li {
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.9rem;
}

.recent-list li:last-child {
    border-bottom: none;
}
