* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; color: var(--cs-ink); background: var(--cs-bg);
  font-family: var(--cs-font-body); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow-x: hidden; /* wide tables scroll inside their own .table-scroll, never the page */
}
h1, h2, h3 { font-family: var(--cs-font-head); color: var(--cs-blue); letter-spacing: -.01em; }
a { color: var(--cs-blue); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--cs-ultramarine); outline-offset: 2px;
}

/* --- App shell --- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--cs-white);
  border-right: 1px solid var(--cs-border); display: flex; flex-direction: column;
}
.sidebar-brand { padding: 22px 18px 18px; margin-bottom: 6px; border-bottom: 1px solid var(--cs-border); }
.sidebar-brand img { display: block; width: 180px; max-width: 100%; height: auto; }
.sidebar-menu { display: flex; flex-direction: column; flex: 1; }
.nav-toggle { display: none; background: none; border: 1px solid var(--cs-border); border-radius: 8px; padding: 9px 10px; cursor: pointer; line-height: 0; }
.nav-toggle:hover { border-color: var(--cs-blue); }
.nav-toggle-bar { display: block; width: 22px; height: 2px; margin: 4px 0; background: var(--cs-blue); border-radius: 2px; }
.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a {
  display: block; padding: 10px 14px; text-decoration: none; color: var(--cs-ink);
  border-radius: 8px; margin: 2px 10px; font-weight: 500; font-size: .95rem;
  transition: background .15s ease, color .15s ease;
}
.sidebar nav a:hover { background: var(--cs-blue-050); color: var(--cs-blue); }
.sidebar nav a[aria-current="page"] { background: var(--cs-blue); color: var(--cs-white); box-shadow: 0 2px 6px rgba(0, 86, 157, .25); }
.logout-form { margin-top: auto; padding: 16px; }
.content { flex: 1; min-width: 0; padding: 24px; max-width: 1200px; }

/* --- Components --- */
.card {
  background: var(--cs-white); border: 1px solid #E5E7EB; border-radius: 12px;
  padding: 20px; box-shadow: 0 1px 3px rgba(31, 41, 55, .06); margin-bottom: 16px;
}
.btn {
  display: inline-block; padding: 9px 18px; border-radius: 8px; border: 1px solid var(--cs-gray);
  background: var(--cs-white); color: var(--cs-ink); cursor: pointer; font: inherit; font-weight: 500;
  text-decoration: none; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--cs-blue); }
.btn-primary { background: var(--cs-blue); border-color: var(--cs-blue); color: var(--cs-white); }
.btn-primary:hover { background: var(--cs-ultramarine); border-color: var(--cs-ultramarine); }
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash-error { background: #FDECEA; color: var(--cs-danger); border: 1px solid var(--cs-danger); }
.flash-success { background: #E6F3F4; color: var(--cs-teal); border: 1px solid var(--cs-teal); }
.form-field { margin-bottom: 16px; }
.form-field label { display: block; margin-bottom: 4px; font-weight: 500; }
.form-field input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--cs-gray); border-radius: 8px; font: inherit;
}
.form-error { color: var(--cs-danger); font-size: .9rem; margin-top: 4px; }

/* --- Login (standalone page with wave) --- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: var(--cs-bg) url("/assets/img/wave.svg") bottom center / 100% auto no-repeat;
}
.login-card {
  width: min(400px, 92vw); background: var(--cs-white); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(31, 41, 55, .12); padding: 36px 32px;
  border-top: 4px solid var(--cs-blue);
}
.login-logo { display: block; width: 240px; max-width: 78%; height: auto; margin: 4px auto 6px; }
.login-logo-sm { width: 160px; margin: 0 auto 18px; }
.login-sub { text-align: center; color: var(--cs-muted); margin: 0 0 24px; }
.login-card h1 { margin-top: 0; }
.error-page { padding: 48px; }

/* --- Responsive: sidebar collapses --- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .content { overflow-x: hidden; }
  .sidebar { width: 100%; min-width: 0; }
  .sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; margin: 0; }
  .sidebar-brand img { width: 150px; }
  .nav-toggle { display: block; }
  .sidebar-menu { display: none; flex: none; padding-bottom: 8px; border-top: 1px solid var(--cs-border); }
  .sidebar-menu.open { display: flex; }
  .logout-form { margin: 8px 0 0; padding: 8px 16px; }
}

.qr-box { display: flex; justify-content: center; margin: 16px 0; }
.qr-box svg { width: 240px; height: 240px; }
.recovery-codes { columns: 2; list-style: none; padding: 0; }
.recovery-codes code { font-size: 1.05rem; }

/* --- Phase 2: customers --- */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.muted { color: var(--cs-gray); font-weight: 400; font-size: .8em; }
.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.filter-bar input[type="text"] { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--cs-gray); border-radius: 8px; font: inherit; }
.filter-bar select { padding: 9px 12px; border: 1px solid var(--cs-gray); border-radius: 8px; font: inherit; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #E5E7EB; }
.data-table thead th { position: sticky; top: 0; background: var(--cs-bg); }
.data-table tbody tr:nth-child(even) { background: #FBFBFC; }
.data-table a { text-decoration: none; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; }
.badge-ok { background: #E6F3F4; color: var(--cs-teal); }
.badge-muted { background: #EFEFEF; color: #6B7280; }
.badge-warn { background: #FBEBDA; color: var(--cs-warn); }
.badge-danger { background: #F8E2E0; color: var(--cs-danger); }
.btn-danger { background: var(--cs-danger); border-color: var(--cs-danger); color: var(--cs-white); }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: inline; }
.log-files { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.log-files a {
  display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--cs-gray);
  color: var(--cs-ink); text-decoration: none; font-size: .9rem;
}
.log-files a[aria-current="page"] { background: var(--cs-blue); border-color: var(--cs-blue); color: var(--cs-white); }
.log-content {
  background: #1F2937; color: #F7F8FA; padding: 16px; border-radius: 8px; overflow-x: auto;
  font-family: "Consolas", "SFMono-Regular", Menlo, monospace; font-size: .85rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
fieldset { border: 1px solid var(--cs-gray); border-radius: 10px; padding: 16px; margin: 0 0 16px; }
fieldset legend { padding: 0 8px; color: var(--cs-blue); font-weight: 600; }
fieldset textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--cs-gray); border-radius: 8px; font: inherit; }
fieldset select { width: 100%; padding: 9px 12px; border: 1px solid var(--cs-gray); border-radius: 8px; font: inherit; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--cs-gray); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a, .tabs .tab-disabled { padding: 10px 16px; text-decoration: none; color: var(--cs-ink); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs a.active { border-bottom-color: var(--cs-blue); color: var(--cs-blue); font-weight: 600; }
.tabs .tab-disabled { color: var(--cs-gray); cursor: default; }
.detail-grid { margin: 0; }
.detail-row { display: grid; grid-template-columns: 220px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid #F0F1F3; }
.detail-row dt { color: #6B7280; margin: 0; }
.detail-row dd { margin: 0; }

/* --- Phase 3: brand kit --- */
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.color-card { display: flex; gap: 12px; border: 1px solid #E5E7EB; border-radius: 10px; padding: 12px; }
.swatch { flex-shrink: 0; }
.color-vals { font-size: .85rem; }
.cval { margin: 2px 0; }
.cval-label { color: #6B7280; }
.cval code { background: var(--cs-bg); padding: 1px 5px; border-radius: 4px; }
.copy-btn { border: none; background: none; cursor: pointer; color: var(--cs-blue); font-size: 1rem; padding: 0 4px; }
.copy-btn.copied { color: var(--cs-teal); }
.editor summary, .asset-edit summary { cursor: pointer; color: var(--cs-blue); margin-top: 12px; }
.color-editor { width: 100%; border-collapse: collapse; margin: 12px 0; }
.color-editor th, .color-editor td { padding: 4px; }
.color-editor input { width: 100%; padding: 6px; border: 1px solid var(--cs-gray); border-radius: 6px; font: inherit; }
.hint { color: #6B7280; font-size: .85rem; }
.font-form, .upload-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.upload-form select, .upload-form input[type="file"] { padding: 8px; border: 1px solid var(--cs-gray); border-radius: 8px; }
.cat-filter { display: flex; gap: 4px; flex-wrap: wrap; margin: 16px 0; }
.cat-filter a { padding: 4px 10px; border-radius: 999px; text-decoration: none; color: var(--cs-ink); background: var(--cs-bg); font-size: .85rem; }
.cat-filter a.active { background: var(--cs-blue); color: var(--cs-white); }
.btn-small { padding: 4px 10px; font-size: .8rem; }

/* --- Brand-kit repeatable-row editors (colors, fonts) --- */
.editor-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0 4px; }
.btn-remove { color: var(--cs-danger); font-weight: 700; line-height: 1; min-width: 34px; text-align: center; }
.btn-remove:hover { border-color: var(--cs-danger); background: #FDECEA; }
.row-remove { width: 1%; white-space: nowrap; text-align: center; }
.row-radio { width: 1%; white-space: nowrap; text-align: center; }
.color-editor input[type="radio"], .color-editor input[type="checkbox"] { width: auto; padding: 0; }
.color-editor thead th:last-child { width: 1%; }
.font-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.font-item { border: 1px solid var(--cs-border); border-radius: 10px; padding: 8px 14px; background: var(--cs-white); }
.font-label { display: block; color: var(--cs-muted); font-size: .78rem; }
.font-value { font-weight: 600; }

/* --- Phase 5: dashboard --- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { margin-bottom: 0; border-top: 3px solid var(--cs-blue); }
.kpi-label { color: var(--cs-muted); font-size: .85rem; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-family: var(--cs-font-head); font-size: 1.7rem; font-weight: 700; color: var(--cs-blue); letter-spacing: -.02em; }
.kpi-sub { color: #6B7280; font-size: .8rem; margin-top: 2px; }
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid #F0F1F3; flex-wrap: wrap; }
.activity-list li:last-child { border-bottom: none; }
.activity-time { color: #6B7280; font-size: .85rem; min-width: 140px; }
.activity-action { font-weight: 500; }
.activity-user { color: #6B7280; font-size: .85rem; }

/* --- Phase 4: quote/invoice item editor --- */
.item-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.item-table th { text-align: left; padding: 6px 4px; color: #6B7280; font-weight: 500; font-size: .85rem; }
.item-table td { padding: 4px; }
.item-table input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--cs-gray); border-radius: 6px; font: inherit;
}
/* Trailing "Entfernen" column stays as narrow as its button. */
.item-table thead th:last-child { width: 1%; }
.item-total { text-align: right; font-size: 1.05rem; margin: 0 0 16px; }
.item-total strong { color: var(--cs-blue); }

/* --- Accounting year table: single-line rows on desktop (horizontal scroll when
       wide), stacked cards on mobile so nothing is crammed into two lines. --- */
.acct-table th, .acct-table td { white-space: nowrap; }
.acct-table th.num, .acct-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.acct-table tfoot th { border-top: 2px solid var(--cs-gray); background: var(--cs-bg); font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .acct-table thead { display: none; }
  .acct-table, .acct-table tbody, .acct-table tfoot, .acct-table tr, .acct-table td, .acct-table th { display: block; width: 100%; }
  .acct-table tr { border: 1px solid var(--cs-border); border-radius: 10px; padding: 6px 12px; margin-bottom: 14px; background: var(--cs-white); }
  .acct-scroll { overflow-x: visible; }
  .acct-table td, .acct-table tfoot th { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; text-align: right; white-space: normal; overflow-wrap: anywhere; border: none; border-bottom: 1px solid #F0F1F3; padding: 7px 0; }
  .acct-table tr > :last-child { border-bottom: none; }
  .acct-table td:empty, .acct-table .num-empty { display: none; }
  .acct-table td::before, .acct-table tfoot th[data-label]::before { content: attr(data-label); color: var(--cs-muted); font-weight: 500; text-align: left; }
  .acct-table .acct-sum-label { color: var(--cs-blue); font-family: var(--cs-font-head); font-weight: 700; }
  .acct-table tfoot tr { background: var(--cs-blue-050); border-color: var(--cs-blue); }
}

/* ===== Brand Board ===== */
.brandboard { display: flex; flex-direction: column; gap: 1.25rem; }
.bk-subnav {
    position: sticky; top: 0; z-index: 5;
    display: flex; flex-wrap: wrap; gap: .5rem;
    padding: .5rem; margin: -.25rem 0 .25rem;
    background: var(--cs-bg); border-bottom: 1px solid var(--cs-border);
}
.bk-subnav a {
    padding: .35rem .8rem; border-radius: 999px;
    background: var(--cs-white); border: 1px solid var(--cs-border);
    color: var(--cs-ink); text-decoration: none; font-weight: 500; font-size: .9rem;
}
.bk-subnav a:hover { border-color: var(--cs-blue); color: var(--cs-blue); }
.bk-section { scroll-margin-top: 4rem; }

/* Logo zone */
.logo-zone { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.logo-stage {
    flex: 1 1 320px; min-height: 220px; margin: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px; border: 1px solid var(--cs-border); padding: 1.5rem;
    position: relative;
}
.logo-stage img { max-width: 100%; max-height: 240px; object-fit: contain; }
.logo-stage figcaption {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .5rem .75rem; font-size: .85rem;
    background: rgba(0,0,0,.04); border-top: 1px solid var(--cs-border);
    border-radius: 0 0 12px 12px;
}
.logo-stage.bg-light { background: #FFFFFF; }
.logo-stage.bg-dark { background: #1F2937; color: #F7F8FA; }
.logo-stage.bg-dark figcaption { background: rgba(255,255,255,.08); border-top-color: rgba(255,255,255,.15); }
.logo-stage.bg-checker {
    background-color: #FFFFFF;
    background-image:
        linear-gradient(45deg, #E3E5E8 25%, transparent 25%),
        linear-gradient(-45deg, #E3E5E8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #E3E5E8 75%),
        linear-gradient(-45deg, transparent 75%, #E3E5E8 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.logo-controls { flex: 0 0 auto; display: flex; flex-direction: column; gap: .5rem; }
.bg-toggle { display: inline-flex; gap: .25rem; }
.bg-toggle .btn.is-active { background: var(--cs-blue); color: #fff; border-color: var(--cs-blue); }
.logo-variants { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.logo-variant {
    margin: 0; width: 170px; border: 1px solid var(--cs-border); border-radius: 10px;
    padding: .5rem; background: #fff; text-align: center;
}
.logo-variant img { width: 100%; height: 80px; object-fit: contain; }
.logo-variant figcaption { display: flex; align-items: center; justify-content: space-between; gap: .25rem; font-size: .75rem; margin-top: .35rem; }
.logo-variant figcaption > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Download/Löschen next to a logo — must not be squashed by the name's ellipsis rule. */
.logo-actions { flex: 0 0 auto; display: inline-flex; align-items: center; gap: .25rem; }

/* Color board (baseline; Task 5 refines) */
.color-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.color-tile { border: 1px solid var(--cs-border); border-radius: 12px; overflow: hidden; background: #fff; }
.color-swatch { display: block; width: 100%; height: 120px; border: 0; cursor: pointer; }
.color-body { padding: .6rem .7rem .8rem; }
.color-body strong { display: block; margin-bottom: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
    display: inline-flex; gap: .3rem; align-items: baseline;
    padding: .2rem .5rem; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--cs-border); background: var(--cs-blue-050); font-size: .78rem;
}
.chip:hover { border-color: var(--cs-blue); }
.chip-key { color: var(--cs-muted); font-weight: 600; }
.chip-val { font-family: ui-monospace, monospace; }
.chip.copied, .color-swatch.copied { outline: 2px solid var(--cs-teal); outline-offset: 1px; }

/* Toast (copy feedback) */
.toast {
    position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%) translateY(1rem);
    background: var(--cs-ink); color: #fff; padding: .6rem 1rem; border-radius: 8px;
    font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25);
    opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: opacity .18s ease; } }
.color-swatch:focus-visible, .chip:focus-visible { outline: 2px solid var(--cs-blue); outline-offset: 2px; }

/* Font specimens */
.specimen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.specimen { border: 1px solid var(--cs-border); border-radius: 12px; padding: 1rem; background: #fff; }
.specimen header { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.specimen-label { font-weight: 600; color: var(--cs-blue); }
.specimen-name { color: var(--cs-muted); font-size: .85rem; }
.specimen-badge {
    margin-left: auto; font-size: .7rem; padding: .1rem .45rem; border-radius: 999px;
    background: var(--cs-blue-050); color: var(--cs-muted); border: 1px solid var(--cs-border);
}
.specimen-sample { margin: .15rem 0; line-height: 1.25; overflow-wrap: anywhere; }
.specimen-big { font-size: 2rem; }
.specimen-fallback { font-family: var(--cs-font-head), system-ui, sans-serif; }

/* File dropzone + grid */
.dropzone {
    display: flex; align-items: center; justify-content: center; text-align: center;
    min-height: 120px; padding: 1rem; cursor: pointer;
    border: 2px dashed var(--cs-border); border-radius: 12px; background: var(--cs-blue-050);
    position: relative;
}
.dropzone.dragover { border-color: var(--cs-blue); background: #fff; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-hint { color: var(--cs-muted); pointer-events: none; }
.upload-row { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; margin-top: .75rem; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-top: 1rem; }
.asset-card { border: 1px solid var(--cs-border); border-radius: 12px; padding: .75rem; background: #fff; }
.asset-thumb { width: 100%; height: 130px; object-fit: contain; background: var(--cs-bg); border-radius: 8px; }
.asset-name { font-weight: 500; margin-top: .5rem; overflow-wrap: anywhere; }
.asset-note { font-size: .8rem; color: var(--cs-muted); }
.asset-meta { font-size: .75rem; color: var(--cs-muted); margin: .25rem 0 .5rem; }
.asset-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
/* Note + category editor, shared by the file grid and the logo zone. */
.asset-edit summary { font-size: .8rem; margin-top: .5rem; }
.asset-edit-form { display: flex; flex-direction: column; gap: .35rem; margin-top: .5rem; text-align: left; }
.asset-edit-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--cs-muted); }
.asset-edit-form input, .asset-edit-form select {
    width: 100%; padding: 5px 7px; border: 1px solid var(--cs-gray); border-radius: 6px;
    font: inherit; font-size: .8rem; color: var(--cs-ink); background: #fff;
}
