/*
   Das Stylesheet nennt keine einzige Markenfarbe. Alle Farben kommen als
   CSS-Variablen aus der Marken-Konfiguration (BrandOptions) und stehen am
   <body>. Eine zweite Marke braucht deshalb kein zweites Stylesheet.
*/

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    color: var(--c-text);
    background: #fbfaf6;
    line-height: 1.45;
}

h1, h2 { font-family: Constantia, "Iowan Old Style", Georgia, serif; color: var(--c-primary); font-weight: 400; margin: 0; }
h1 { font-size: 1.85rem; }
h1:focus { outline: none; } /* Ziel des Fokus nach einem Seitenwechsel, kein Bedienelement */
h2 { font-size: 1.25rem; margin-bottom: .6rem; }
a { color: var(--c-accent-dark); }
pre { font-family: inherit; white-space: pre-wrap; margin: 0; }
small { font-size: .82rem; }

.muted, .subtitle { color: var(--c-text-muted); }
.subtitle { margin: .25rem 0 0; }
.text-error { color: #9b2c2c; font-weight: 600; }
.eyebrow, .field-label, label, th {
    font-size: .7rem; font-weight: 600; letter-spacing: .06em; color: var(--c-accent-dark); text-transform: none;
}
.spacer { flex: 1; }

/* ---------------------------------------------------------------- Gerüst */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px; flex: none; display: flex; flex-direction: column;
    background: var(--c-surface); border-right: 1px solid var(--c-line);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { display: block; padding: 1.4rem 1.3rem 1rem; text-decoration: none; }
.brand img { width: 170px; max-width: 100%; display: block; }
.brand span { display: block; margin-top: .45rem; font-size: .68rem; letter-spacing: .22em; color: var(--c-accent-dark); font-weight: 600; }

nav { display: flex; flex-direction: column; padding: .4rem .7rem; gap: 2px; }
.nav-item {
    display: block; padding: .6rem .8rem; border-radius: 6px; text-decoration: none;
    color: var(--c-text); font-weight: 500;
}
.nav-item:hover { background: var(--c-line); }
.nav-item.active { background: var(--c-primary); color: #fff; }
.nav-primary { border: 1px solid var(--c-primary); color: var(--c-primary); margin: .3rem 0; }
.nav-divider { height: 1px; background: var(--c-line); margin: .6rem .4rem; }

.sidebar-foot { margin-top: auto; padding: 1rem 1.2rem; border-top: 1px solid var(--c-line); font-size: .85rem; }
.mode { padding: .5rem .7rem; border-radius: 6px; margin-bottom: .8rem; }
.mode strong { display: block; }
.mode-test { background: #fdf3d8; color: #6b4e00; }
.mode-live { background: #dcebe4; color: var(--c-primary-dark); }
.user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.user form { display: inline; }
.user a { margin-right: .8rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; gap: .8rem; padding: .7rem 1rem; background: var(--c-primary); color: #fff; }
.menu-button { background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 6px; font-size: 1.2rem; padding: .15rem .6rem; }

.banner { padding: .55rem 1.6rem; font-size: .9rem; }
.banner-test { background: #fdf3d8; color: #6b4e00; border-bottom: 1px solid #ecd9a0; }
.banner-error { background: #fbe4e4; color: #7a1f1f; border-bottom: 1px solid #efbcbc; }

.page { padding: 1.8rem 2rem 4rem; max-width: 1500px; width: 100%; }
.page-narrow { max-width: 980px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: .5rem; align-items: center; }
.draft-number { font-size: 1.05rem; letter-spacing: .08em; color: var(--c-text-muted); font-weight: 600; }

section { margin-top: 2rem; }

/* ---------------------------------------------------------------- Bausteine */

.card { background: #fff; border: 1px solid var(--c-line); border-radius: 8px; padding: 1.2rem 1.3rem; margin-bottom: 1.1rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--c-line); background: #fff;
    color: var(--c-text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--c-accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); }
.btn-accent { background: var(--c-accent-dark); border-color: var(--c-accent-dark); color: #fff; font-weight: 600; }
.btn-danger { background: #9b2c2c; border-color: #9b2c2c; color: #fff; }
.btn-danger-ghost { color: #9b2c2c; }
.btn-small { padding: .25rem .55rem; font-size: .82rem; }
.btn-wide { width: 100%; margin-top: 1rem; }
button.link { background: none; border: none; padding: 0; color: var(--c-accent-dark); text-decoration: underline; cursor: pointer; font: inherit; }

.actions { display: flex; gap: .6rem; align-items: center; margin: 1rem 0; }
.actions.wrap { flex-wrap: wrap; }

label { display: flex; flex-direction: column; gap: .3rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-size: .9rem; letter-spacing: 0; color: var(--c-text); font-weight: 400; }

input[type=text], input[type=search], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], select, textarea {
    font: inherit; font-size: 1rem; letter-spacing: 0; font-weight: 400; color: var(--c-text);
    padding: .5rem .6rem; border: 1px solid #cfc8b8; border-radius: 6px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 1px; }
input.invalid { border-color: #9b2c2c; background: #fdf0f0; }
input.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
input.short { max-width: 6rem; }
textarea { resize: vertical; }

.form-grid { display: grid; gap: .9rem 1rem; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }
.inline-fields { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.inline-fields input, .inline-fields select { width: auto; }
.inline-fields label { flex-direction: row; align-items: center; }

.segmented { display: inline-flex; border: 1px solid #cfc8b8; border-radius: 6px; overflow: hidden; margin-top: .3rem; }
.segmented button { border: none; background: #fff; padding: .4rem .9rem; font: inherit; cursor: pointer; border-right: 1px solid #cfc8b8; }
.segmented button:last-child { border-right: none; }
.segmented button.on { background: var(--c-primary); color: #fff; }

.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.filters .grow, .grow { flex: 1; min-width: 220px; }

.notice { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.notice-ok { background: #e6f1ec; border-color: #b9d6c9; color: #173f34; }
.notice-warn { background: #fdf3d8; border-color: #ecd9a0; color: #6b4e00; }
.notice-error { background: #fbe4e4; border-color: #efbcbc; color: #7a1f1f; white-space: pre-wrap; }
.undo { display: flex; justify-content: space-between; }

.badge { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-draft { background: var(--c-line); color: var(--c-text); }
.badge-final { background: #dcebe4; color: var(--c-primary-dark); }
.badge-cancelled { background: #fbe4e4; color: #7a1f1f; }
.badge-cancellation { background: #f1e7d3; color: #5e4a1c; }

/* ---------------------------------------------------------------- Tabellen */

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--c-line); border-radius: 8px; }
.card .table-wrap { border: none; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: .6rem .8rem; background: var(--c-primary); color: var(--c-surface); white-space: nowrap; }
.table th.num { text-align: right; }
.table td { padding: .6rem .8rem; border-top: 1px solid var(--c-line); vertical-align: top; }
.table td.num, .table td:first-child { white-space: nowrap; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--c-surface); }
.table-tight td { padding: .35rem .4rem; }
.table a { text-decoration: none; }
.row-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
.description { color: var(--c-text-muted); font-size: .88rem; margin-top: .2rem; }

/* ---------------------------------------------------------------- Übersicht */

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.tile { background: #fff; border: 1px solid var(--c-line); border-radius: 8px; padding: 1rem 1.1rem; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: .3rem; }
a.tile:hover { border-color: var(--c-accent); }
.tile strong { font-size: 1.7rem; font-family: Constantia, Georgia, serif; font-weight: 400; color: var(--c-primary); }
.tile .tile-small { font-size: 1.25rem; }
.tile small { color: var(--c-text-muted); }
.tile-wide { grid-column: span 2; border-top: 3px solid var(--c-highlight); }

/* ---------------------------------------------------------------- Editor */

.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 40%); gap: 1.5rem; align-items: start; }
.preview { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; background: #e9e6dd; border-radius: 8px; padding: .9rem; }
.preview img { width: 100%; display: block; margin-top: .6rem; box-shadow: 0 1px 6px rgba(0,0,0,.18); background: #fff; }

.line { border: 1px solid var(--c-line); border-radius: 8px; padding: .8rem; margin-bottom: .8rem; background: #fdfcf9; }
.line-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; }
.line-pos { width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--c-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; flex: none; }
.line-name { font-weight: 600; }
.line-actions { display: flex; gap: .25rem; flex: none; }
.line-numbers { display: grid; grid-template-columns: 1fr 1fr 1.3fr .8fr 1.3fr; gap: .6rem; margin-top: .5rem; align-items: end; }
.line-total { text-align: right; display: flex; flex-direction: column; gap: .3rem; padding-bottom: .45rem; }
.add-line { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.add-line select { width: auto; flex: 1; min-width: 200px; }

.totals { display: flex; flex-direction: column; gap: .35rem; margin-left: auto; max-width: 460px; }
.totals > div { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.total-gross { border-top: 2px solid var(--c-primary); padding-top: .45rem; margin-top: .2rem; font-size: 1.2rem; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 42%); gap: 1.5rem; align-items: start; }
.pdf-pane { position: sticky; top: 1rem; }
.pdf-pane iframe { width: 100%; height: calc(100vh - 3rem); border: 1px solid var(--c-line); border-radius: 8px; background: #fff; }

dl.summary { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
dl.summary dt { color: var(--c-text-muted); text-transform: capitalize; }
dl.summary dd { margin: 0; }
.mail-body { background: var(--c-surface); padding: .8rem; border-radius: 6px; margin: .8rem 0; }
.worktime-result { background: var(--c-surface); padding: .8rem; border-radius: 6px; margin: .8rem 0; }
.worktime-result strong { display: block; font-size: 1.3rem; }

/* ---------------------------------------------------------------- Dialoge */

.dialog-backdrop { position: fixed; inset: 0; background: rgba(13, 41, 39, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.dialog { background: #fff; border-radius: 10px; padding: 1.5rem; width: 560px; max-width: 100%; max-height: 92vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog-wide { width: 980px; }
.dialog-body { margin: 1rem 0; display: flex; flex-direction: column; gap: .8rem; }
.dialog-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Anmeldung */

.plain { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--c-surface); padding: 1rem; }
.login-card { background: #fff; border: 1px solid var(--c-line); border-radius: 10px; padding: 2.2rem; width: 400px; max-width: 100%; }
.login-card form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.login-logo { width: 210px; display: block; margin-bottom: 1.4rem; }
.hint { color: var(--c-text-muted); font-size: .85rem; margin-top: 1.2rem; }
.validation-message { color: #9b2c2c; font-size: .85rem; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: #7a1f1f; color: #fff; padding: .8rem 1.4rem; z-index: 100; }
#blazor-error-ui a { color: #fff; margin-left: 1rem; }

/* ---------------------------------------------------------------- Schmal */

@media (max-width: 1150px) {
    .editor-grid, .detail-grid { grid-template-columns: 1fr; }
    .preview, .pdf-pane { position: static; max-height: none; }
    .pdf-pane iframe { height: 75vh; }
    .tiles { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
    .sidebar { position: fixed; z-index: 40; left: -270px; transition: left .15s; box-shadow: 0 0 30px rgba(0,0,0,.25); }
    .sidebar.open { left: 0; }
    .topbar { display: flex; }
    .page { padding: 1.1rem 1rem 3rem; }
    .form-grid.two { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .line-numbers { grid-template-columns: 1fr 1fr; }
    .line-head { flex-wrap: wrap; }
    .tile-wide { grid-column: span 2; }
    h1 { font-size: 1.5rem; }
}

@media print { .sidebar, .topbar, .banner, .actions { display: none; } }

/* ---------------------------------------------------------------- Verbindung */
#components-reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-paused,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex; position: fixed; inset: 0; z-index: 2000;
    align-items: center; justify-content: center;
    background: rgba(13, 41, 39, .35);
}
.reconnect-box {
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    padding: 24px 28px; max-width: 420px; margin: 16px; text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.reconnect-box p { display: none; margin: 0 0 12px; line-height: 1.5; }
.reconnect-box button { display: none; }
.components-reconnect-show .reconnect-when-trying,
.components-reconnect-retrying .reconnect-when-trying,
.components-reconnect-paused .reconnect-when-trying,
.components-reconnect-failed .reconnect-when-failed,
.components-reconnect-rejected .reconnect-when-rejected { display: block; }
.components-reconnect-failed .reconnect-box button,
.components-reconnect-paused .reconnect-box button { display: inline-block; }
