/* Studio CRM v2 – Stil im Look gängiger CRM-Tools (Sidebar-Layout, Karten, Kacheln) */

:root {
    --crm-bg: #f4f5f7;
    --crm-sidebar-bg: #1c2230;
    --crm-sidebar-fg: #c7cbd6;
    --crm-sidebar-fg-active: #ffffff;
    --crm-accent: #4f6df5;
    --crm-accent-dark: #3952c4;
    --crm-text: #1f2430;
    --crm-text-muted: #6b7280;
    --crm-border: #e3e6ec;
    --crm-card-bg: #ffffff;
    --crm-success: #1f9d55;
    --crm-error: #d6493c;
    --crm-radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--crm-bg);
    color: var(--crm-text);
}

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

/* --- Layout: Sidebar + Content ------------------------------------------- */
.crm-shell {
    display: flex;
    min-height: 100vh;
}

.crm-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--crm-sidebar-bg);
    color: var(--crm-sidebar-fg);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
}

.crm-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 22px;
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
}
.crm-brand-mark { font-size: 1.4rem; }

.crm-nav { display: flex; flex-direction: column; gap: 2px; }
.crm-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--crm-radius);
    color: var(--crm-sidebar-fg);
    font-size: 0.92rem;
    font-weight: 500;
}
.crm-nav-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.crm-nav-link.is-active { background: var(--crm-accent); color: #fff; }
.crm-nav-icon { font-size: 1.05rem; width: 22px; text-align: center; }

.crm-sidebar-foot {
    margin-top: auto;
    font-size: 0.75rem;
    color: #8189a0;
    line-height: 1.4;
    padding: 14px 12px 4px;
}

/* --- Content area --------------------------------------------------------- */
.crm-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.crm-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 28px;
    background: var(--crm-card-bg);
    border-bottom: 1px solid var(--crm-border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.crm-search { position: relative; flex: 1; max-width: 420px; }
.crm-search input {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--crm-border);
    border-radius: 999px;
    background: var(--crm-bg);
    font-size: 0.9rem;
}
.crm-search input:focus { outline: none; border-color: var(--crm-accent); background: #fff; }

#crm-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: 0 12px 28px rgba(20,24,40,0.14);
    max-height: 420px;
    overflow-y: auto;
    z-index: 20;
}
#crm-search-results.is-visible { display: block; }
#crm-search-results .group-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--crm-text-muted);
    padding: 10px 14px 4px;
}
#crm-search-results a {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px;
    color: var(--crm-text);
    font-size: 0.88rem;
}
#crm-search-results a:hover { background: var(--crm-bg); text-decoration: none; }
#crm-search-results .meta { color: var(--crm-text-muted); font-size: 0.8rem; }
#crm-search-results .empty { padding: 14px; color: var(--crm-text-muted); font-size: 0.88rem; }

.crm-user { display: flex; align-items: center; gap: 14px; }
.crm-user-info { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.crm-user-name { font-weight: 600; font-size: 0.88rem; }
.crm-user-role { font-size: 0.76rem; color: var(--crm-text-muted); }
.crm-logout { font-size: 0.82rem; color: var(--crm-text-muted); }

.crm-main { padding: 28px; max-width: none; }

/* --- Page head ------------------------------------------------------------ */
.crm-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}
.crm-page-head h1 { margin: 0 0 4px; font-size: 1.4rem; }
.crm-page-sub { margin: 0; color: var(--crm-text-muted); font-size: 0.88rem; }
.crm-breadcrumb { margin: 0 0 6px; font-size: 0.82rem; color: var(--crm-text-muted); }
.crm-breadcrumb span { margin: 0 4px; }

/* --- Buttons --------------------------------------------------------------- */
.crm-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--crm-radius);
    border: 1px solid var(--crm-border);
    background: #fff;
    color: var(--crm-text);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
}
.crm-btn:hover { text-decoration: none; border-color: var(--crm-accent); }
.crm-btn-primary { background: var(--crm-accent); border-color: var(--crm-accent); color: #fff; }
.crm-btn-primary:hover { background: var(--crm-accent-dark); border-color: var(--crm-accent-dark); }
.crm-btn-block { width: 100%; justify-content: center; margin-top: 18px; }

/* --- Dashboard tiles ------------------------------------------------------- */
.crm-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.crm-tile {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--crm-card-bg);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    color: var(--crm-text);
    transition: box-shadow .15s, border-color .15s;
}
.crm-tile:hover { text-decoration: none; box-shadow: 0 10px 26px rgba(20,24,40,0.08); border-color: var(--crm-accent); }
.crm-tile-icon { font-size: 1.8rem; }
.crm-tile-label { font-size: 0.85rem; color: var(--crm-text-muted); font-weight: 600; }
.crm-tile-count { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.crm-tile-meta { font-size: 0.76rem; color: var(--crm-text-muted); }
.crm-tile-error { color: var(--crm-error); font-size: 0.84rem; font-weight: 600; margin-top: 4px; }

/* --- Tables ---------------------------------------------------------------- */
.crm-table-wrap {
    background: var(--crm-card-bg);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    overflow: hidden;
    overflow-x: auto;
}
.crm-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.crm-table th, .crm-table td {
    padding: 11px 16px;
    text-align: left;
    border-bottom: 1px solid var(--crm-border);
    white-space: nowrap;
}
.crm-table th { color: var(--crm-text-muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: .03em; }
.crm-table tbody tr { cursor: pointer; }
.crm-table tbody tr:hover { background: var(--crm-bg); }
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table-meta { margin-top: 12px; color: var(--crm-text-muted); font-size: 0.82rem; }
.crm-empty { color: var(--crm-text-muted); }

/* --- Detail cards / forms --------------------------------------------------- */
.crm-card {
    background: var(--crm-card-bg);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    padding: 20px 22px;
    margin-bottom: 16px;
}
.crm-card-title { margin: 0 0 14px; font-size: 1rem; }
.crm-field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px 22px;
}
.crm-field-label { display: block; font-size: 0.74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--crm-text-muted); margin-bottom: 5px; }
.crm-field-value { font-size: 0.92rem; }
.crm-field input[type="text"], .crm-field input[type="password"] {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
    cursor: text;
    transition: border-color .15s, box-shadow .15s;
}
.crm-field input:hover { border-color: var(--crm-accent); }
.crm-field input:focus { outline: none; border-color: var(--crm-accent); background: #fff; box-shadow: 0 0 0 3px rgba(91,108,255,0.12); }
.crm-form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* --- Flash messages ---------------------------------------------------------- */
.crm-flash { padding: 12px 16px; border-radius: var(--crm-radius); margin-bottom: 18px; font-size: 0.88rem; }
.crm-flash-error { background: #fdecea; color: var(--crm-error); border: 1px solid #f6c4bd; }
.crm-flash-success { background: #e9f9ef; color: var(--crm-success); border: 1px solid #bfe9cf; }

/* --- Login / Error pages ----------------------------------------------------- */
.crm-login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1c2230, #4f6df5);
}
.crm-login-card {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 16px;
    padding: 32px 30px;
    box-shadow: 0 30px 60px rgba(10,14,30,0.35);
    display: flex;
    flex-direction: column;
}
.crm-login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.crm-login-sub { margin: 6px 0 20px; color: var(--crm-text-muted); font-size: 0.86rem; }
.crm-login-card label { margin-top: 4px; }
.crm-login-card input { padding: 10px 12px; border: 1px solid var(--crm-border); border-radius: 8px; margin-bottom: 4px; font-size: 0.92rem; }

@media (max-width: 860px) {
    .crm-shell { flex-direction: column; }
    .crm-sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
    .crm-brand { padding: 0 14px 0 0; }
    .crm-nav { flex-direction: row; }
    .crm-sidebar-foot { display: none; }
    .crm-main { padding: 18px; }
}

/* --- Long-Text-Felder (z.B. "Auszug", "Bemerkung") ------------------------- */
.crm-field-wide { grid-column: 1 / -1; }
.crm-field-textarea {
    width: 100%;
    min-height: 150px;
    padding: 9px 12px;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    background: #fff;
    cursor: text;
    font: inherit;
    line-height: 1.5;
    resize: vertical;
    transition: border-color .15s, box-shadow .15s;
}
.crm-field-textarea:hover { border-color: var(--crm-accent); }
.crm-field-textarea:focus { outline: none; border-color: var(--crm-accent); background: #fff; box-shadow: 0 0 0 3px rgba(91,108,255,0.12); }
.crm-field-value-long {
    white-space: pre-wrap;
    line-height: 1.6;
    min-height: 60px;
}

/* --- Auswahldialog für Link-Felder (z.B. "Komponist", "Main Vocals") ------- */
.crm-link-filter {
    width: 100%;
    margin-bottom: 6px;
    padding: 7px 10px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: #fff;
}
.crm-link-filter:focus { outline: none; border-color: var(--crm-accent); }
.crm-link-select {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    background: #fff;
    font: inherit;
}
.crm-link-select:focus { outline: none; border-color: var(--crm-accent); }
.crm-hint { font-size: 0.78rem; color: #888; margin-top: 4px; }

/* --- Datei-Anlagen (z.B. "Partitur", "Sheet") als Linkliste ---------------- */
.crm-file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.crm-file-list li { padding: 8px 12px; border: 1px solid var(--crm-border); border-radius: 8px; background: #fff; }
.crm-file-list a { color: var(--crm-accent); text-decoration: none; font-weight: 500; }
.crm-file-list a:hover { text-decoration: underline; }
.crm-file-size { color: #888; font-size: 0.82rem; }

.crm-link-picker {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
}
.crm-link-col {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.crm-link-col-label {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--crm-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.crm-link-arrows {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.5rem;
}
.crm-link-arrows button {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0.5rem;
    border: 1px solid var(--crm-border, #d1d5db);
    background: var(--crm-surface, #fff);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}
.crm-link-arrows button:hover {
    background: var(--crm-accent-soft, #eef2ff);
}
.crm-link-select.crm-link-available,
.crm-link-select.crm-link-selected {
    flex: 1;
}

.crm-link-picker {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.crm-link-add {
    border: 1px solid var(--crm-border, #d1d5db);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--crm-surface, #fff);
}
.crm-link-add summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--crm-accent, #4f46e5);
    list-style: none;
}
.crm-link-add summary::-webkit-details-marker { display: none; }
.crm-link-add[open] summary {
    margin-bottom: 0.5rem;
}
.crm-link-col-selected .crm-link-select {
    width: 100%;
}

.crm-field-picker {
    grid-column: span 2;
    min-width: 260px;
}
@media (max-width: 720px) {
    .crm-field-picker { grid-column: 1 / -1; }
}

.crm-select {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    background: #fff;
}
.crm-select-multi { height: auto; }
.crm-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
}
.crm-checkbox-label input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
}

.crm-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
}
.crm-checkbox-chip {
    border: 1px solid var(--crm-border);
    border-radius: 999px;
    padding: 5px 12px;
    font-weight: 400;
    font-size: 0.92rem;
}
.crm-checkbox-chip:has(input:checked) {
    background: var(--crm-accent-soft, #eef2ff);
    border-color: var(--crm-accent, #4f46e5);
}
.crm-field-value-readonly {
    color: #6b7280;
    font-style: italic;
}

.crm-table thead th.crm-sortable {
    cursor: pointer;
    user-select: none;
}
.crm-table thead th.crm-sortable:hover {
    background: rgba(0, 0, 0, 0.04);
}
.crm-sort-arrow {
    display: inline-block;
    margin-left: 0.25em;
    font-size: 0.8em;
    opacity: 0.7;
}
.crm-sort-arrow-idle {
    opacity: 0.35;
}
.crm-sort-arrow-active {
    opacity: 1;
    font-weight: bold;
}
.crm-sort-hint {
    margin: 0 0 0.5em;
}
/* ── Tag-Dropdown (Multi-Select) ───────────────────────────────────────────── */
.crm-tag-select { position: relative; }
.crm-tag-select-box {
    display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center;
    border: 1px solid #d1d5db; border-radius: 6px;
    padding: 0.35em 0.5em; min-height: 2.4em;
    cursor: text; background: #fff;
}
.crm-tag-select-box:focus-within { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,.15); }
.crm-tag {
    display: inline-flex; align-items: center; gap: 0.2em;
    background: #6366f1; color: #fff;
    border-radius: 4px; padding: 0.15em 0.35em 0.15em 0.5em;
    font-size: 0.85em; white-space: nowrap;
}
.crm-tag-remove {
    background: none; border: none; color: inherit;
    cursor: pointer; padding: 0; font-size: 1em; line-height: 1; opacity: 0.8;
}
.crm-tag-remove:hover { opacity: 1; }
.crm-tag-input {
    border: none; outline: none; background: transparent;
    font: inherit; min-width: 7em; flex: 1; padding: 0;
}
.crm-tag-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 200;
    background: #fff; border: 1px solid #d1d5db;
    border-radius: 0 0 6px 6px; box-shadow: 0 4px 12px rgba(0,0,0,.1);
    list-style: none; margin: 0; padding: 0.25em 0;
    max-height: 12em; overflow-y: auto;
}
.crm-tag-option {
    padding: 0.4em 0.75em; cursor: pointer; font-size: 0.9em;
}
.crm-tag-option:hover { background: rgba(99,102,241,.08); }
/* File-Manager (Upload + Löschen) */
.crm-file-manager { display: flex; flex-direction: column; gap: 10px; }
.crm-file-list li { display: flex; align-items: center; gap: 8px; }
.crm-file-delete { margin-left: auto; background: none; border: none; color: #999; font-size: 1.1rem; cursor: pointer; padding: 0 4px; line-height: 1; }
.crm-file-delete:hover { color: #c00; }
.crm-file-add-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.crm-file-input { display: none; }
.crm-file-chosen { font-size: .85em; color: #555; font-style: italic; }
.crm-btn-sm { font-size: .85rem; padding: 4px 12px; background: var(--crm-accent); color: #fff; border-radius: 6px; border: none; cursor: pointer; }
.crm-filter-badge { background: #c00; color: #fff; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 12px; }
.crm-btn-danger { background: #c00; color: #fff; border: none; } .crm-btn-danger:hover { background: #900; }

/* Sticky Detail-Header */
.crm-page-head-sticky { position: sticky; top: 0; z-index: 50; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.07); padding-bottom: 12px; justify-content: space-between; align-items: center; }
.crm-page-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* --- Sum-Bar (Kostenkalkulation) --- */
.crm-sum-bar {
    display: flex;
    gap: 32px;
    padding: 10px 16px;
    background: #f0f4ff;
    border: 1px solid #c8d4f0;
    border-radius: 6px;
    margin: 12px 0 4px;
    font-size: 0.95rem;
}
.crm-sum-bar strong { color: #1a3a8f; }

/* --- Sum-Head im Sticky-Header --- */
.crm-sum-head {
    display: flex;
    gap: 20px;
    font-size: 0.85rem;
    color: #555;
    align-items: center;
}
.crm-sum-head div { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.crm-sum-head strong { color: #1a3a8f; font-size: 1.05rem; }

/* --- DAW-Projektdateien Panel --- */
.crm-daw-panel{margin:24px 0 8px;padding:16px 20px;background:#f8f8f8;border:1px solid #ddd;border-radius:8px}
.crm-daw-title{margin:0 0 12px;font-size:1rem;font-weight:600;color:#333}
.crm-daw-group{margin-bottom:12px}
.crm-daw-group strong{font-size:.8rem;color:#666;text-transform:uppercase;letter-spacing:.04em}
.crm-daw-group ul{margin:4px 0 0;padding:0;list-style:none}
.crm-daw-group li{display:flex;align-items:center;gap:8px;padding:4px 0;border-bottom:1px solid #eee}
.crm-daw-link{color:#1a3a8f;text-decoration:none;display:flex;align-items:center;gap:6px;flex:1}
.crm-daw-link:hover{text-decoration:underline}
.crm-daw-badge{background:#e8eef8;color:#1a3a8f;font-size:.7rem;font-weight:700;padding:1px 6px;border-radius:4px;white-space:nowrap}
.crm-daw-meta{font-size:.75rem;color:#999;margin-left:auto;white-space:nowrap}
.crm-daw-loading,.crm-daw-empty{font-size:.9rem;color:#888;font-style:italic}

/* DAW-Panel – History & Rang */
.crm-daw-group-title { margin-bottom: 4px; }
.crm-daw-item { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border-light, #eee); }
.crm-daw-rank { font-size: .75rem; color: #999; min-width: 22px; font-weight: 600; }
.crm-daw-history-toggle {
    margin-top: 6px; background: none; border: 1px solid var(--border-light, #ccc);
    border-radius: 4px; padding: 2px 10px; font-size: .78rem; cursor: pointer; color: #666;
}
.crm-daw-history-toggle:hover { background: #f5f5f5; }

/* DAW-Panel inline in Eckdaten-Section */
.crm-card:has(.crm-daw-inline) {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-start;
}
.crm-card:has(.crm-daw-inline) .crm-field-grid {
    flex: 1 1 55%;
    min-width: 300px;
}
.crm-daw-inline {
    flex: 0 0 280px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: .82rem;
}
.crm-daw-title-inline {
    font-size: .85rem;
    font-weight: 600;
    color: #555;
    margin: 0 0 8px 0;
}

.crm-daw-list-badge {
    font-size: .72rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
    display: inline-block;
}

.crm-daw-list-link { color: inherit; text-decoration: none; }
.crm-daw-list-link:hover { text-decoration: underline; color: #4a6cf7; }
