/* ========================= 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; }

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: 8px;
  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: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-all:hover { background: #4a7bc8; color: #fff; }

.btn-reset {
  background: var(--danger);
  color: #fff;
  border: 0;
  border-radius: 8px;
  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: 8px;
  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-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; }

.btn-save {
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 8px;
  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: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.btn-edit {
  background: #2f4f7f;
  color: #fff;
  border: 0;
  border-radius: 8px;
  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: 6px 10px; 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(15 * 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; }

#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: 8px;
  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: 8px;
  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: 4px;
  line-height: 1;
}
.btn-move:hover {
  color: var(--fg);
  border-color: var(--fg);
}
