/* ========================= Theme ========================= */
:root {
  --bg: #0f1115; --card: #171a21; --card2: #1d2230; --text: #e9edf5;
  --muted: #9aa4b2; --line: #2a3140; --green: #1f9d55; --green-hover: #188448;
  --danger: #c23b3b; --active: #3a5a8a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Arial, sans-serif; background: var(--bg); color: var(--text); }
.wrap { max-width: 1400px; margin: 24px auto; padding: 0 16px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
@media (max-width: 768px) {
  .top { gap: 8px; justify-content: flex-start; }
  .top h1 { font-size: 18px; flex: 1 1 auto; min-width: 0; }
  .search-btn { flex: 0 0 auto; padding: 4px 10px; font-size: 12px; }
  .top-right { flex: 0 0 auto; gap: 8px; font-size: 12px; }
  .top-right .btn-ctx { padding: 3px 8px; font-size: 11px; }
  .top-right a[href="/logout"] { font-size: 16px; padding: 3px 6px; }
  .table-scroll { min-height: calc(3 * 2.4em + 2.6em) !important; }
}
h1 { margin: 0; font-size: 24px; color: #0055CC; }
a { color: var(--muted); text-decoration: none; }
a:hover { color: #fff; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.nav-tabs { display: flex; gap: 10px; margin-bottom: 12px; }
.nav-tab { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card2); color: var(--text); text-decoration: none; }
.nav-tab.active { background: #4a7bc8; border-color: #7aa5f0; color: #fff; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15), 0 0 0 2px rgba(122,165,240,.45); }
.nav-tab:hover { border-color: #5b8bd9; background: #2a4570; color: #fff; }
.search-row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search-row input[type="text"] { width: 100%; max-width: 400px; min-width: 200px; }
.btn-all { background: #2f4f7f; color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.btn-all:hover { background: #4a7bc8; color: #fff; }

/* ── ListView Search-Row Action Buttons (Suchen / Alle / +Neu) ── */
.btn-lv { display: inline-flex !important; align-items: center !important; justify-content: center !important; height: 26px !important; padding: 0 11px !important; margin-top: 0 !important; margin-bottom: 0 !important; font-size: 12px !important; font-weight: normal !important; border-radius: 6px !important; border: none !important; text-decoration: none !important; cursor: pointer !important; font-family: inherit !important; color: #fff !important; box-sizing: border-box !important; line-height: 1 !important; transition: filter 0.15s; vertical-align: middle !important; }
.btn-lv:hover { filter: brightness(1.2) !important; color: #fff !important; }
.btn-lv-search { background: var(--green) !important; }
.btn-lv-all    { background: #2f4f7f !important; }
.btn-reset { background: var(--danger); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.btn-reset:hover { background: #d44; color: #fff; }
.reset-link { font-size: 12px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
input, textarea, button, select { font-family: inherit; }
input, textarea, select { border: 1px solid var(--line); background: var(--card2); color: var(--text); border-radius: 6px; padding: 10px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: #3b82f6; }
select option { background: var(--card2); color: var(--text); }
.w-kdnr { max-width: 140px; } .w-artnr { width: 20ch; max-width: none; } .w-kbez { max-width: 320px; }
.w-name { max-width: 420px; } .w-strasse { max-width: 420px; } .w-land { width: 50px; }
.w-plz { width: 80px; } .w-ort { width: 270px; }
.row-3 { display: flex; gap: 10px; align-items: flex-end; max-width: 420px; }
/* ── Standard-Button-klein (Dokumentlisten: ansehen / eMail / speichern) ── */
.btn-klein {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 26px; padding: 0 11px; font-size: 12px; border-radius: 6px;
  border: none; text-decoration: none; cursor: pointer;
  transition: filter 0.15s; font-family: inherit; color: #fff;
  box-sizing: border-box; line-height: 1; margin-right: 8px;
}
.btn-auftraege-detail { height: 26px; padding: 0 11px; font-size: 12px; line-height: 1; }
.btn-klein:hover { filter: brightness(1.2); }
.btn-klein-view  { background: #e67e22; }
.btn-klein-email { background: #007bff; }
.btn-klein-email.sent { background: #1e1e1e; color: #555; }
.btn-klein-copy  { background: #1a2a3a; color: #7ab8f5; border: 1px solid #2a4a6a; }
.btn-klein-save  { background: #28a745; }
.btn-save { background: var(--green); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.btn-save:hover { background: var(--green-hover); }
.btn-save:disabled { opacity: .5; cursor: not-allowed; }
.btn-del { background: var(--danger); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.btn-edit { background: #2f4f7f; color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.btn-edit:hover { background: #4a7bc8; }
.perm-matrix th, .perm-matrix td { text-align: center; padding: 5px 8px; font-size: 12px; }
.perm-matrix .perm-v { color: var(--green); } .perm-matrix .perm-r { color: var(--danger); }
.perm-matrix thead th { border-bottom: 1px solid var(--border); }
.perm-edit-table { border-collapse: collapse; margin-top: 4px; }
.perm-edit-table th, .perm-edit-table td { padding: 4px 6px; text-align: center; font-size: 12px; }
.perm-edit-table th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.perm-edit-table td:first-child { text-align: left; padding-right: 12px; }
.perm-edit-table .perm-v { color: var(--green); } .perm-edit-table .perm-r { color: var(--danger); }
.perm-edit-table input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.action-bar { display: flex; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.action-bar button:disabled, .action-bar .btn-save:disabled, .action-bar .btn-edit:disabled, .action-bar .btn-del:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }
.h-scroll { overflow-x: auto; }
.table-scroll { min-height: calc(3 * 2.4em + 2.6em); max-height: calc(12 * 2.4em + 2.6em); overflow-y: auto; }
.table-scroll thead { position: sticky; top: 0; z-index: 1; background: var(--card); }
.minw { min-width: 900px; }
table { width: 100%; border-collapse: collapse; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
thead th { text-align: left; background: #121723; color: #c7d2e3; font-size: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th[data-sort] { cursor: pointer; user-select: none; }
thead th[data-sort]::after { content: ' ⇅'; font-size: 9px; opacity: .3; }
thead th[data-sort]:hover { color: #fff; background: #2a3d55; }
thead th[data-sort]:hover::after { opacity: .6; }
thead th[data-sort].sort-active::after { content: ''; }
.sort-icon { font-size: 10px; opacity: .85; }
.bem-star { color: var(--green); font-weight: 700; }
/* Searchable dropdown */
.searchable-select { position: relative; }
.searchable-select select { display: none; }
.ss-results { position: absolute; z-index: 50; left: 0; right: 0; max-height: 220px; overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: 6px; margin-top: 2px; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.ss-results.open { display: block; }
.ss-item { padding: 6px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ss-item:last-child { border-bottom: none; }
.ss-item:hover, .ss-item.active { background: #4a7bc8; color: #fff; }
.ss-item .ss-match { color: var(--green); font-weight: 600; }
.ss-selected { padding: 6px 10px; font-size: 13px; background: #1a2a3a; border: 1px solid var(--border); border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.ss-selected .ss-clear { cursor: pointer; color: var(--danger); font-size: 16px; padding: 0 4px; }
.num-right { text-align: right; font-variant-numeric: tabular-nums; }
/* Searchable select */
.searchable-select select { width: 100%; }
.searchable-select input[type="text"] { width: 100%; }
tbody td { padding: 10px 6px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
tbody tr:hover { background: #1e2d45; cursor: pointer; }
tbody tr.active { background: var(--active); border: 1px solid #5b8bd9; }
tbody tr { user-select: none; }
#btn-update { display: none; }
.detail-layout { display: grid; grid-template-columns: 760px 1fr; gap: 18px; align-items: start; }
.left-col { display: flex; flex-direction: column; gap: 10px; }
.right-col { display: flex; flex-direction: column; gap: 10px; }
.right-col .field { flex: 0 0 auto; }
.w-notiz-right { width: 100%; max-width: var(--field-max, 420px); height: calc(10 * 1.4em + 20px); min-height: calc(10 * 1.4em + 20px); max-height: calc(10 * 1.4em + 20px); resize: none; line-height: 1.4; }
.action-row { margin-top: auto; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding-top: 10px; }
.empty-detail { color: var(--muted); padding: 8px 2px; }
.id-col { width: 10ch; min-width: 10ch; max-width: 10ch; box-sizing: border-box; padding-right: .5ch; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.id-10 { width: 10.3ch; min-width: 10.3ch; max-width: 10.3ch; box-sizing: border-box; padding-right: .5ch; }
#f_k_bez { width: 28ch !important; min-width: 28ch !important; max-width: 28ch !important; box-sizing: border-box; }
/* Lieferanschriften Detail */
.page-lieferanschriften .row-3 .field:nth-child(1) input { width: 50px; }
.page-lieferanschriften .row-3 .field:nth-child(2) input { width: 80px; }
.page-lieferanschriften .row-3 .field:nth-child(3) input { width: 270px; }
.page-lieferanschriften .left-col .field.searchable-select input[type="text"],
.page-lieferanschriften .left-col .field select#customer_id { display: block; width: 100% !important; min-width: unset !important; max-width: 420px !important; }
@media (max-width: 1200px) { .detail-layout { grid-template-columns: 1fr; } }
/* ========================= Context Bar ========================= */
.context-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.btn-ctx { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--card2); color: var(--text); text-decoration: none; cursor: pointer; transition: border-color 0.15s, background 0.15s; font-family: inherit; }
.btn-ctx:hover { border-color: #5b8bd9; color: #fff; background: #2a4570; }
.btn-ctx.disabled, .btn-ctx:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn-ctx.active-cat { background: #4a7bc8; border-color: #7aa5f0; color: #fff; font-weight: 700; box-shadow: 0 0 0 2px rgba(122,165,240,.35); }
.btn-ctx.has-items { border-color: var(--green); color: var(--green); }
.btn-ctx.has-items:hover { background: rgba(31, 157, 85, 0.1); }
.top-right { display: flex; align-items: center; gap: 12px; }
.user-info { color: var(--muted); font-size: 13px; }
.top-right a[href="/logout"] { font-size: 20px; color: var(--muted); text-decoration: none; padding: 4px 8px; border-radius: 6px; transition: all 0.2s; }
.top-right a[href="/logout"]:hover { color: var(--danger); background: rgba(194, 59, 59, 0.1); }
.search-btn { padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--card2); color: var(--text); text-decoration: none; font-size: 13px; transition: all 0.2s; }
.search-btn:hover { border-color: #5b8bd9; background: #4a7bc8; color: #fff; }
.perm-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.perm-toggle input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--green); }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; font-size: 11px; font-weight: 700; border-radius: 10px; background: var(--green); color: #fff; }
/* Tour form inputs — uniform height */
.tour-input { padding: 5px 8px; font-size: 12px; height: 30px; box-sizing: border-box; }
/* Move buttons for tour stops */
.btn-move { background: none; border: 1px solid var(--border); color: var(--muted); padding: 2px 6px; font-size: 10px; cursor: pointer; border-radius: 6px; line-height: 1; }
.btn-move:hover { color: var(--fg); border-color: var(--fg); }
/* Enge Spalten für Artikel-Tabelle */
table.tight-cols tbody td { padding: 10px 3px !important; }
table.tight-cols thead th { padding: 10px 3px !important; }

/* ── FiBu ListView: Tabelle ── */
.fibu-table th, .fibu-table td { padding-left: 0.5mm !important; padding-right: 0.5mm !important; font-size: 12px !important; vertical-align: middle !important; }

/* ── Aufträge ListView: Dok-Badges (AN / AB / LS) ── */
.dok-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); transition: opacity 0.15s;
}
.dok-badge:hover       { opacity: 0.8; }
.dok-badge-open        { background: var(--card2); color: var(--text); }
.dok-badge-manual      { background: var(--card2); color: var(--muted); opacity: 0.5; }
.dok-badge-auto        { background: var(--card2); color: var(--muted); opacity: 0.5; }
.dok-badge-berechnet   { background: #1a3a1a; color: #5dd67a; border-color: #2a5a2a !important; opacity: 1; }
.dok-badge-active      { outline: 2px solid #7ab8f5 !important; outline-offset: 1px; }

/* ── Aufträge ListView: Vorgangs-Zeile ── */
.vg-row td { vertical-align: middle; padding: 6px 8px; font-size: 13px; }

/* ── Aufträge ListView: Artikel-Typ-Button ── */
.art-btn { padding: 4px 10px; font-size: 12px; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); background: var(--card2); color: var(--text); }
.art-btn.active { background: #28a745; color: #fff; border-color: #28a745; }


