/* Shared surfaces (Components/Shared/Surfaces, agreement gemeinsame-bedienlogik.md): side panel, panel footer, inline question,
   „+“ section, „+“ bar, field message. Colours only from the tokens in app.css :root; measures from the approved
   Kontakt-Panel design (.panel-head, .sec-head, .cloud, .msg-*, .confirm). Own class names (cx-sidepanel-*,
   cx-s-btn, …) so nothing collides with the legacy .contact-sidebar / .sidebar-* rules or Bootstrap's .btn. */

/* ── Buttons used by the surfaces ─────────────────────────────────────── */

.cx-s-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: var(--cx-radius-control);
    padding: 9px 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cx-s-btn:focus-visible { outline: none; box-shadow: var(--cx-focus-ring); }
.cx-s-btn:disabled { opacity: .55; cursor: not-allowed; }
.cx-s-btn--sm { padding: 6px 12px; font-size: 13px; }
.cx-s-btn--text { background: transparent; color: var(--walnut); }
.cx-s-btn--text:hover:not(:disabled) { background: var(--sand); }
.cx-s-btn--outline { background: var(--cx-card-bg); border-color: var(--cx-input-border); color: var(--ink); }
.cx-s-btn--outline:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.cx-s-btn--primary { background: var(--copper); color: var(--cx-card-bg); }
.cx-s-btn--primary:hover:not(:disabled) { background: var(--copper-dark); }
.cx-s-btn--danger { background: var(--cx-danger); color: var(--cx-card-bg); }
.cx-s-btn--danger:hover:not(:disabled) { background: color-mix(in srgb, var(--cx-danger) 85%, var(--ink)); }
.cx-s-btn--danger-text { background: transparent; color: var(--cx-danger); }
.cx-s-btn--danger-text:hover:not(:disabled) { background: var(--danger-50); }

.cx-s-spinner {
    width: 14px;
    height: 14px;
    border-radius: var(--cx-radius-round);
    border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
    border-top-color: currentColor;
    animation: cx-s-spin .8s linear infinite;
}
@keyframes cx-s-spin { to { transform: rotate(360deg); } }

.cx-icon-btn {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--cx-radius-control);
    background: transparent;
    color: var(--stone);
    cursor: pointer;
}
.cx-icon-btn:hover:not(:disabled) { background: var(--sand); color: var(--ink); }
.cx-icon-btn:focus-visible { outline: none; box-shadow: var(--cx-focus-ring); }
.cx-icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.cx-icon-btn .material-icons-outlined { font-size: 20px; }

/* ── Side panel ───────────────────────────────────────────────────────── */

/* The dimmer covers the whole screen on every width, the app bar too: its menus would open beneath the dimmer, and a click
   on the app bar is a click beside the panel (close, or ask first with changes). The panel starts below the app bar. */
.cx-sidepanel-scrim {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: color-mix(in srgb, var(--ink) 34%, transparent);
    animation: cx-sidepanel-fade .18s ease-out;
}

.cx-sidepanel {
    position: fixed;
    top: calc(var(--cx-maintenance-banner-h, 0px) + var(--cx-topbar-h, 60px));
    right: 0;
    bottom: 0;
    width: clamp(480px, 40vw, 640px);
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    background: var(--cx-card-bg);
    border-radius: var(--cx-radius-surface) 0 0 var(--cx-radius-surface);
    box-shadow: -10px 0 28px color-mix(in srgb, var(--ink) 14%, transparent);
    overflow: hidden;
    outline: none;
    animation: cx-sidepanel-in .2s ease-out;
}
.cx-sidepanel--wide { width: clamp(560px, 55vw, 880px); }

/* Opened from inside a modal dialog („Beleg prüfen“): the dialog lies over the app bar, so the panel starts at the top of
   the screen as the dimmer does – which covers the dialog's own close button too, and a click there asks like any click
   beside the panel (cx-surfaces.js routes the dialog's Esc to the panel the same way). Below the maintenance banner, which
   lies over everything (app.css: every full-height region keeps --cx-maintenance-banner-h free). */
:is(.e-dialog, dialog) .cx-sidepanel { top: var(--cx-maintenance-banner-h, 0px); }

.cx-sidepanel-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--ink);
    background: var(--cx-card-bg);
    border-bottom: 1px solid var(--cx-input-border);
    position: relative;
    z-index: 2;
}
.cx-sidepanel-title {
    flex: 1 1 auto;
    display: flex;
    min-width: 0;
    margin: 0;
    font-size: 17px;
    font-weight: 650;
    color: var(--ink);
    white-space: nowrap;
}
/* The type word and number stay whole on a phone; only the name after them shortens. */
.cx-sidepanel-title-lead { flex: 0 0 auto; }
.cx-sidepanel-title-sep { flex: 0 0 auto; white-space: pre; }
.cx-sidepanel-title-detail { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cx-sidepanel-head-extra { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.cx-sidepanel-close {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: var(--cx-radius-control);
    cursor: pointer;
    color: var(--cx-text-secondary);
    background: transparent;
    border: 1px solid var(--cx-input-border);
}
.cx-sidepanel-close .material-icons-outlined { font-size: 18px; }
.cx-sidepanel-close:hover:not(:disabled) { background: var(--sand); color: var(--ink); }
/* While the form saves nothing closes the panel (CxSidePanel IsBusy): the × shows it is not available. */
.cx-sidepanel-close:disabled { opacity: .45; cursor: not-allowed; }
.cx-sidepanel-close:focus-visible { outline: none; box-shadow: var(--cx-focus-ring); }

.cx-sidepanel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 6px 20px 22px;
    background: var(--cx-card-bg);
    display: flex;
    flex-direction: column;
    gap: 0;
}
.cx-sidepanel-body > .cx-inline-confirm { margin: 10px 0 16px; }

.cx-sidepanel-foot {
    flex: 0 0 auto;
    padding: 14px 20px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    background: var(--cx-card-bg);
    border-top: 1px solid var(--cx-input-border);
    position: relative;
    z-index: 2;
}

/* The address search's suggestion list (AddressAutocompleteInput) closes on a click beside it through a backdrop over the
   whole screen (z-index 1000). In a panel that backdrop lies below the header and footer (z-index 2): a click on ×,
   „Speichern“ or „Abbrechen“ reaches its button at once instead of only closing the list; the
   list itself (z-index 1001) stays above the content. */
.cx-sidepanel .ac-backdrop { z-index: 1; }

@keyframes cx-sidepanel-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes cx-sidepanel-fade { from { opacity: 0; } to { opacity: 1; } }

/* Phone: both sizes fill the screen below the maintenance banner (shown only during a maintenance notice; it lies over
   everything and would cover the panel's title and ×), header and footer stay. */
@media (max-width: 600px) {
    .cx-sidepanel,
    .cx-sidepanel--wide {
        top: var(--cx-maintenance-banner-h, 0px);
        width: 100vw;
        height: calc(100dvh - var(--cx-maintenance-banner-h, 0px));
        border-radius: 0;
        box-shadow: none;
    }
    .cx-sidepanel-head { padding: 12px 16px; }
    .cx-sidepanel-body { padding: 6px 16px 22px; }
    .cx-sidepanel-foot { padding: 12px 16px max(12px, env(safe-area-inset-bottom, 0px)); }
}

/* ── Panel footer ─────────────────────────────────────────────────────── */

.cx-panel-footer {
    display: flex;
    align-items: center;
    gap: 10px;
}
.cx-panel-footer-end {
    margin-left: auto;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.cx-panel-footer .cx-s-btn { height: 38px; padding: 0 16px; border-radius: var(--cx-radius-control); font-weight: 600; white-space: nowrap; }
.cx-panel-footer .cx-s-btn--text { color: var(--ink); }
.cx-panel-footer .cx-s-btn--outline:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }

@media (max-width: 480px) {
    .cx-panel-footer, .cx-panel-footer-end { gap: 6px; }
    .cx-panel-footer .cx-s-btn { padding: 0 10px; font-size: 13px; }
}

/* ── Inline question ──────────────────────────────────────────────────── */

.cx-inline-confirm {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--cx-radius-surface);
    background: var(--danger-50);
    border-left: 3px solid var(--cx-danger);
    font-size: 13px;
    color: var(--ink);
    /* Brought into view on appearing (cxSurfaces.focusQuestion): not flush with the edge of a scrolled panel. */
    scroll-margin: 12px 0;
}
.cx-inline-confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* A question that loses nothing („Als versendet markieren?“): sand, copper edge; the answer on the dark copper for 4.5:1. */
.cx-inline-confirm--neutral { background: var(--sand); border-left-color: var(--copper); }
.cx-inline-confirm--neutral .cx-s-btn--primary { background: var(--copper-dark); }
.cx-inline-confirm--neutral .cx-s-btn--primary:hover:not(:disabled) { background: color-mix(in srgb, var(--copper-dark) 85%, var(--ink)); }

/* ── „+“ section ──────────────────────────────────────────────────────── */

.cx-add-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cx-add-section--new { animation: cx-add-section-flash 1.2s ease-out; }
@keyframes cx-add-section-flash { from { background: var(--sand); } to { background: transparent; } }

.cx-add-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 28px;
}
.cx-add-section-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
}
.cx-add-section-body { display: flex; flex-direction: column; gap: 12px; }
.cx-add-section-body:empty { display: none; }

/* ── „+“ bar ──────────────────────────────────────────────────────────── */

.cx-add-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
}
.cx-add-bar-label {
    flex-basis: 100%;
    margin-bottom: 2px;
    font-size: 12px;
    color: var(--stone);
}
.cx-add-bar-plus {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.cx-add-bar-plus:focus-visible { outline: none; box-shadow: var(--cx-focus-ring); border-radius: var(--cx-radius-control); }

/* Chips (K21): sand, dark text, a plain plus; they wrap and keep their text on a phone. */
.cx-add-bar--pills { gap: 8px; }
.cx-add-pill {
    padding: 7px 13px;
    border: 1px solid var(--hairline);
    border-radius: var(--cx-radius-control);
    background: var(--sand);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.cx-add-pill:hover { border-color: var(--cx-input-border); }
.cx-add-pill:focus-visible { outline: none; box-shadow: var(--cx-focus-ring); }

/* ── Field message ────────────────────────────────────────────────────── */

.cx-field-msg {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 7px 10px;
    border-radius: var(--cx-radius-surface);
    border-left: 3px solid var(--stone);
    background: var(--paper-2);
    color: var(--ink);
    font-size: 12px;
    line-height: 1.4;
}
.cx-field-msg .material-icons-outlined { font-size: 16px; margin-top: 1px; color: var(--stone); }
.cx-field-msg-text { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
.cx-field-msg--warning { background: var(--warning-50); border-left-color: var(--cx-warning); }
.cx-field-msg--warning .material-icons-outlined { color: var(--cx-warning); }
.cx-field-msg--error { background: var(--danger-50); border-left-color: var(--cx-danger); color: var(--cx-danger); }
.cx-field-msg--error .material-icons-outlined { color: var(--cx-danger); }

@media (prefers-reduced-motion: reduce) {
    .cx-sidepanel,
    .cx-sidepanel-scrim,
    .cx-add-section--new { animation: none; }
    .cx-s-spinner { animation-duration: 2s; }
}
