:root {
    --bg: #f5f4ef;
    --panel: #ffffff;
    --muted: #5f6d5b;
    --accent: #6f8063;
    --accent-2: #a0b091;
    --border: #d9dece;
    --text: #1d261c;
    --danger: #a14c40;
    --success: #4f7c56;
}
html[data-theme="dark"] {
    --bg: #141814;
    --panel: #1c221c;
    --muted: #a2ad9b;
    --accent: #88a27a;
    --accent-2: #b6c2a3;
    --border: #2a3228;
    --text: #eef4e8;
    --danger: #c77a6e;
    --success: #78a985;
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg: #141814;
        --panel: #1c221c;
        --muted: #a2ad9b;
        --accent: #88a27a;
        --accent-2: #b6c2a3;
        --border: #2a3228;
        --text: #eef4e8;
        --danger: #c77a6e;
        --success: #78a985;
    }
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: radial-gradient(circle at 20% 20%, rgba(160,176,145,0.25), transparent 38%), radial-gradient(circle at 80% 0%, rgba(111,128,99,0.18), transparent 30%), var(--bg);
    color: var(--text);
    font-family: "Work Sans", "Segoe UI", "Helvetica Neue", sans-serif;
    line-height: 1.5;
}
html[data-theme="dark"] body {
    background:
        radial-gradient(circle at 20% 20%, rgba(136,162,122,0.18), transparent 40%),
        radial-gradient(circle at 80% 0%, rgba(88,108,76,0.2), transparent 35%),
        var(--bg);
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) body {
        background:
            radial-gradient(circle at 20% 20%, rgba(136,162,122,0.18), transparent 40%),
            radial-gradient(circle at 80% 0%, rgba(88,108,76,0.2), transparent 35%),
            var(--bg);
    }
}
a { color: inherit; text-decoration: none; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: rgba(255,255,255,0.92);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 6px 25px rgba(98,112,93,0.15);
}
html[data-theme="dark"] .topbar {
    background: rgba(20,24,20,0.9);
    box-shadow: 0 6px 25px rgba(10,12,10,0.6);
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .topbar {
        background: rgba(20,24,20,0.9);
        box-shadow: 0 6px 25px rgba(10,12,10,0.6);
    }
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 50px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text a { font-weight: 700; color: var(--text); }
.brand-line { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.nav-links { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.nav-links a { padding: 8px 12px; border-radius: 999px; color: var(--muted); }
.nav-links a:hover { color: var(--text); background: rgba(111,128,99,0.12); }
.nav-links .pill { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fdfdf5; font-weight: 600; }
.nav-links form { margin: 0; }
.nav-user { color: var(--muted); font-size: 14px; }
.theme-toggle {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.theme-icon { font-size: 18px; }

.nav-item { position: relative; }
.submenu {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 12px 24px rgba(33,45,32,0.12);
    display: none;
    min-width: 180px;
    z-index: 20;
}
.submenu a { display: block; padding: 8px 12px; border-radius: 10px; }
.nav-item:hover .submenu,
.nav-item:focus-within .submenu { display: block; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px; }

.hero { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; margin-bottom: 16px; box-shadow: 0 15px 50px rgba(57,70,55,0.12); }
.hero h1 { margin: 8px 0; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; align-items: center; }
.hero-actions form { margin: 0; display: inline-flex; }
.hero-actions button { width: auto; }
.hero-action-form { display: inline-flex; }
.eyebrow { text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--muted); margin: 0; }
.muted { color: var(--muted); font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-top: 12px; }
.stat { background: rgba(111,128,99,0.08); padding: 12px; border-radius: 10px; border: 1px solid var(--border); }
.stat strong { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 16px; box-shadow: 0 10px 40px rgba(98,112,93,0.15); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-header h2 { margin: 0; font-size: 20px; }

.table { display: grid; gap: 6px; }
.table-head, .table-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; align-items: center; gap: 8px; padding: 10px; border-radius: 10px; }
.table-head { background: rgba(111,128,99,0.08); color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
.table-row { background: rgba(255,255,255,0.8); border: 1px solid var(--border); }
html[data-theme="dark"] .table-row { background: rgba(28,34,28,0.8); }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .table-row { background: rgba(28,34,28,0.8); }
}
.table-row:hover { border-color: rgba(111,128,99,0.5); box-shadow: 0 5px 20px rgba(33,45,32,0.08); }
.table.cols-5 .table-head, .table.cols-5 .table-row { grid-template-columns: 2fr 0.8fr 0.8fr 0.9fr 0.9fr; }
.table.cols-6 .table-head, .table.cols-6 .table-row { grid-template-columns: 2fr 1.1fr 0.7fr 0.7fr 0.9fr 0.9fr; }
.piece-files-table { overflow-x: auto; }
.piece-files-table .table-head, .piece-files-table .table-row {
    grid-template-columns: 15rem minmax(26rem, 1fr) 12rem;
    min-width: 62rem;
}
.piece-files-table .table-row { align-items: start; }
.piece-file-part {
    width: 100%;
    min-width: 0;
}
.title { font-weight: 600; }
.tag { display: inline-block; padding: 2px 6px; margin-left: 6px; border-radius: 8px; background: rgba(111,128,99,0.16); color: var(--accent); font-size: 12px; border: 1px solid rgba(111,128,99,0.35); vertical-align: middle; }

.split { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; align-items: start; }
@media (max-width: 900px) {
    .split { grid-template-columns: 1fr; }
    .table-head, .table-row { grid-template-columns: 1fr; }
}

.form-grid { display: grid; gap: 10px; }
.form-grid.compact { gap: 6px; }
.form-grid.compact label { font-size: 12px; }
.form-grid.compact input,
.form-grid.compact select,
.form-grid.compact button {
    padding: 8px 10px;
    font-size: 14px;
}
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea, select, button {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fdfdf9;
    color: var(--text);
    font-size: 15px;
}
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] button {
    background: #1a201a;
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) input,
    html:not([data-theme="light"]) textarea,
    html:not([data-theme="light"]) select,
    html:not([data-theme="light"]) button {
        background: #1a201a;
    }
}
button { cursor: pointer; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fdfdf5; font-weight: 700; border: none; }
button:hover { filter: brightness(1.05); }

.pill, .ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 600;
    border: 1px solid var(--border);
    text-align: center;
}
.pill { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fdfdf5; }
.ghost { color: var(--muted); background: transparent; }
.ghost:hover { color: var(--text); border-color: rgba(111,128,99,0.4); }
.ghost.danger { border-color: rgba(161,76,64,0.5); color: var(--danger); }
.ghost.danger:hover { border-color: rgba(161,76,64,0.7); color: #5b2019; }
button.ghost { border: 1px solid var(--border); background: transparent; cursor: pointer; }
button.ghost.danger { background: rgba(161,76,64,0.12); color: var(--danger); }
.wide { width: 100%; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid var(--border); }
.alert.success { background: rgba(79,124,86,0.12); color: #2f4e35; border-color: rgba(79,124,86,0.25); }
.alert.danger { background: rgba(161,76,64,0.15); color: #5b2019; border-color: rgba(161,76,64,0.25); }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; }
.page-header h1 { margin: 4px 0; }
.meta { display: flex; gap: 10px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.condensed { gap: 6px; }
.actions form { margin: 0; }
.piece-file-actions {
    margin-top: 8px;
    display: grid;
    gap: 6px;
}
.piece-file-actions-row {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
}
.piece-file-actions-row form {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    flex: 0 0 auto;
}
.piece-file-actions-row .pill,
.piece-file-actions-row .ghost,
.piece-file-actions-row button {
    width: auto;
    white-space: nowrap;
    flex: 0 0 auto;
}
.piece-file-actions-row-bottom {
    margin-top: 1px;
}
.piece-file-actions input[type="number"] {
    width: 5.5rem;
    min-width: 5.5rem;
}
.icon-button { width: 34px; height: 34px; padding: 0; font-size: 16px; }

.preview-frame { width: 100%; min-height: 520px; border: 1px solid var(--border); border-radius: 12px; background: #fdfdf9; }
html[data-theme="dark"] .preview-frame { background: #1a201a; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .preview-frame { background: #1a201a; }
}
.preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: rgba(111,128,99,0.08); color: var(--text); padding: 6px 10px; border-radius: 999px; cursor: pointer; }
.chip.danger { border-color: rgba(161,76,64,0.4); color: var(--danger); background: rgba(161,76,64,0.1); }
.assignment-summary strong {
    font-size: 18px;
    margin-right: 4px;
}

.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.form-inline label { flex: 1 1 200px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > details { width: 100%; }
.stack > details > summary { cursor: pointer; color: var(--muted); }
details { margin-top: 6px; }
details summary { cursor: pointer; }
.assignment-bulk {
    margin-top: 12px;
}
.assignment-bulk summary {
    color: var(--muted);
    font-weight: 600;
}
.assignment-matrix {
    margin-top: 12px;
}
.assignment-matrix summary {
    color: var(--muted);
    font-weight: 600;
}
.matrix-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 10px;
}
.matrix-toolbar label {
    flex: 1 1 220px;
}
.matrix-toolbar p {
    margin: 0;
}
.assignment-bulk select[multiple] {
    min-height: 180px;
}
.assignment-bulk-actions button {
    width: auto;
}
.assignment-matrix-actions button {
    width: auto;
}
.matrix-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    max-height: 65vh;
}
.matrix-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}
.matrix-table th,
.matrix-table td {
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
    text-align: center;
    vertical-align: middle;
}
.matrix-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: rgba(111,128,99,0.12);
}
.matrix-table th:first-child,
.matrix-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--panel);
    text-align: left;
}
.matrix-musician {
    min-width: 200px;
}
.matrix-cell input {
    width: 18px;
    height: 18px;
}
.matrix-cell.suggested {
    background: rgba(79,124,86,0.08);
}

.distribution-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.distribution-controls button {
    width: auto;
}
.distribution-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}
.distribution-checkbox input {
    width: 16px;
    height: 16px;
}
.distribution-summary {
    margin: 0 0 12px;
}
.distribution-row-actions {
    margin-top: 6px;
}
.distribution-count {
    font-weight: 600;
}
.distribution-progress {
    margin-top: 6px;
    height: 8px;
    width: 100%;
    border-radius: 999px;
    background: rgba(111,128,99,0.15);
    border: 1px solid var(--border);
    overflow: hidden;
}
.distribution-progress span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.distribution-preview {
    margin-top: 6px;
}
.distribution-details summary {
    color: var(--muted);
}

.list { margin: 0; padding-left: 18px; color: var(--muted); }
.footer { text-align: center; color: var(--muted); padding: 16px; font-size: 13px; }

@media (max-width: 720px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .brand { justify-content: center; }
    .brand-line { display: none; }
    .nav-links { justify-content: center; }
    .nav-links a,
    .nav-links button { flex: 1 1 auto; }
    .nav-user { width: 100%; text-align: center; }
    .page { padding: 16px; }
    .hero { padding: 18px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .table { gap: 10px; }
    .table-head { display: none; }
    .table-row { grid-template-columns: 1fr; }
    .actions { width: 100%; }
    .actions.condensed { justify-content: flex-start; }
    .piece-files-table .table-head, .piece-files-table .table-row {
        grid-template-columns: 15rem minmax(26rem, 1fr) 12rem;
    }
    .distribution-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .distribution-checkbox {
        width: 100%;
    }
    .preview-frame { min-height: 380px; }
}
