:root {
    color-scheme: light;
    --ink: #111827;
    --muted: #6b7280;
    --line: #d9e1ec;
    --line-strong: #c8d3e2;
    --surface: #ffffff;
    --soft: #f3f6fa;
    --soft-strong: #e8eef6;
    --brand: #245c9f;
    --brand-dark: #183f70;
    --brand-soft: #eaf2fc;
    --gold: #c3912f;
    --gold-soft: #fff7e8;
    --danger: #b42318;
    --success: #18794e;
    --shadow: 0 16px 40px rgba(17, 24, 39, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--soft);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 6px;
    padding: 11px 16px;
    color: #ffffff;
    background: var(--brand);
    cursor: pointer;
    font-weight: 700;
    transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}

button:hover {
    background: var(--brand-dark);
    box-shadow: 0 10px 24px rgba(36, 92, 159, 0.18);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

button.secondary {
    background: var(--gold);
}

button.ghost {
    color: var(--brand);
    background: transparent;
    border: 1px solid var(--line);
}

button.ghost:hover {
    color: var(--brand-dark);
    background: var(--brand-soft);
    border-color: #b8cce5;
    box-shadow: none;
}

button.danger {
    background: var(--danger);
}

label {
    display: grid;
    gap: 7px;
    color: #374151;
    font-size: 14px;
    font-weight: 700;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--ink);
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(36, 92, 159, 0.14);
    outline: none;
}

input[type="color"] {
    width: 52px;
    min-width: 52px;
    height: 44px;
    padding: 3px;
    cursor: pointer;
}

input[type="number"] {
    max-width: 150px;
}

.color-control {
    display: flex;
    gap: 10px;
    align-items: center;
}

.font-size-control {
    display: grid;
    grid-template-columns: 1fr 92px;
    gap: 10px;
    align-items: center;
}

.color-control input:not([type="color"]) {
    font-family: Consolas, monospace;
    text-transform: uppercase;
}

textarea {
    min-height: 180px;
    resize: vertical;
    line-height: 1.45;
}

.hidden {
    display: none !important;
}

.login-screen {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    background: linear-gradient(145deg, #f7f8fb 0%, #dde7f2 100%);
}

.login-panel {
    display: grid;
    gap: 18px;
    width: min(420px, 100%);
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 18px 50px rgba(22, 32, 51, 0.12);
}

.login-brand {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding-bottom: 8px;
    text-align: center;
}

.login-brand img {
    width: 122px;
    height: 122px;
    border: 1px solid var(--line);
    border-radius: 8px;
    object-fit: cover;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(22, 32, 51, 0.14);
}

.login-panel h1,
.topbar h1,
.sidebar h2,
.settings-panel h2 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--gold);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.feedback {
    min-height: 20px;
    margin: 0;
    color: #b42318;
}

.shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 22px;
    min-height: 100vh;
    padding: 24px 22px;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.system-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.system-brand img {
    width: 56px;
    height: 56px;
    border: 1px solid var(--line);
    border-radius: 8px;
    object-fit: cover;
    background: #ffffff;
}

.main-nav {
    display: grid;
    gap: 10px;
}

.nav-button {
    width: 100%;
    text-align: left;
    color: var(--ink);
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.03);
}

.nav-button.active,
.nav-button:hover {
    color: #ffffff;
    background: var(--brand);
    border-color: var(--brand);
}

.main-area {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-width: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0)),
        var(--soft);
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 78px;
    padding: 14px 26px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
}

.app-header strong,
.user-copy strong {
    display: block;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 50%;
    color: #ffffff;
    background: linear-gradient(145deg, var(--brand), var(--brand-dark));
    font-weight: 800;
}

.user-copy {
    min-width: 130px;
}

.user-copy span {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 13px;
}

button.compact {
    padding: 9px 13px;
}

.song-list {
    display: grid;
    align-content: start;
    gap: 8px;
    overflow: auto;
}

.song-item {
    display: grid;
    gap: 4px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    text-align: left;
    color: var(--ink);
    background: #ffffff;
}

.song-item.active {
    border-color: var(--brand);
    background: #eef5ff;
}

.song-item strong,
.song-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-item span {
    color: var(--muted);
    font-size: 13px;
}

.workspace {
    min-width: 0;
    padding: 28px;
}

.panel {
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.topbar h1 {
    font-size: 30px;
    line-height: 1.08;
}

.actions,
.fields-row {
    display: flex;
    gap: 12px;
}

.fields-row > * {
    flex: 1;
}

.editor-grid,
.order-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 380px);
    gap: 22px;
}

.editor-panel,
.settings-panel,
.order-panel,
.quick-panel {
    display: grid;
    align-content: start;
    gap: 18px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
}

.quick-panel h2 {
    margin: 0;
}

.muted {
    margin: 0;
    color: var(--muted);
}

.library-grid,
.order-list {
    display: grid;
    gap: 12px;
}

.library-card,
.order-item,
.sermon-reference-card {
    display: grid;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: #ffffff;
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.03);
}

.library-card:hover,
.order-item:hover,
.sermon-reference-card:hover {
    border-color: var(--line-strong);
}

.library-card {
    grid-template-columns: minmax(0, 1fr) auto;
}

.saved-sermon-card {
    grid-template-columns: 1fr;
    align-items: stretch;
}

.saved-sermon-card .card-actions {
    justify-content: flex-start;
}

.saved-sermon-card .card-actions button {
    flex: 1 1 110px;
}

.card-main {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.status-pill {
    width: fit-content;
    border-radius: 999px;
    padding: 4px 9px;
    color: var(--brand);
    background: var(--brand-soft);
    font-size: 12px;
    font-weight: 800;
}

.status-pill.is-active {
    color: var(--success);
    background: #eaf7f1;
}

.status-pill.is-muted {
    color: var(--muted);
    background: #eef1f5;
}

.sermon-reference-list {
    display: grid;
    gap: 10px;
}

.sermon-reference-card {
    grid-template-columns: minmax(0, 1fr) auto;
}

.library-card strong,
.order-item strong,
.sermon-reference-card strong {
    display: block;
}

.library-card span,
.order-item span,
.sermon-reference-card span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
    max-height: 42px;
    overflow: hidden;
}

.card-actions,
.order-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.card-actions button,
.order-actions button {
    min-height: 38px;
}

.order-item {
    grid-template-columns: 42px minmax(0, 1fr) auto;
}

.position {
    display: grid !important;
    width: 34px;
    height: 34px;
    place-items: center;
    margin: 0 !important;
    border-radius: 50%;
    color: #ffffff !important;
    background: var(--brand);
    font-weight: 800;
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check input {
    width: auto;
}

.slide-preview-list,
.mini-preview-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.slide-thumb {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    align-items: stretch;
}

.slide-thumb-number {
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: #ffffff;
    background: var(--brand);
    font-weight: 800;
}

.slide-thumb-screen {
    min-height: 74px;
    border-radius: 6px;
    padding: 10px;
    overflow: hidden;
    white-space: pre-wrap;
    line-height: 1.2;
    font-size: 12px;
    font-weight: 800;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.slide-thumb.clickable {
    cursor: pointer;
}

.slide-thumb.clickable:hover .slide-thumb-screen {
    outline: 3px solid var(--gold);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.56);
}

.modal-panel {
    display: grid;
    gap: 16px;
    width: min(860px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    overflow: auto;
    padding: 22px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.3);
}

.presentation {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 48px;
    background: #111827;
    overflow: hidden;
}

.presentation #closePresentationButton {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 2;
    background: rgba(0, 0, 0, 0.5);
}

.presentation-controls {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 8px;
}

.presentation-controls button {
    background: rgba(0, 0, 0, 0.5);
}

.presentation-controls span {
    min-width: 70px;
    color: #ffffff;
    text-align: center;
    font-weight: 800;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}

.slide {
    width: min(1400px, 100%);
    max-height: calc(100vh - 150px);
    overflow: hidden;
    white-space: pre-wrap;
    line-height: 1.25;
    font-weight: 800;
    text-shadow: 0 4px 22px rgba(0, 0, 0, 0.42);
}

.chord-line {
    opacity: 0.9;
}

@media (max-width: 980px) {
    .shell,
    .editor-grid,
    .order-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .main-area {
        min-height: auto;
    }
}

@media (max-width: 640px) {
    .workspace,
    .sidebar {
        padding: 16px;
    }

    .app-header,
    .user-menu {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar,
    .actions,
    .fields-row,
    .library-card,
    .order-item,
    .sermon-reference-card {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }
}
