/* ============================================================
   MILOBOX – Design System
   Postgelb (#FFC400) + Tinte (#17181C), helles Arbeits-UI
   ============================================================ */

:root {
  --gelb: #FFC400;
  --gelb-dunkel: #E5AF00;
  --gelb-hell: #FFF3C4;
  --ink: #17181C;
  --ink-70: #3D3F46;
  --muted: #6B6E76;
  --line: #E3E2DD;
  --bg: #F4F3EF;
  --surface: #FFFFFF;
  --surface-2: #FAF9F6;
  --blau: #2563EB;
  --blau-hell: #DBEAFE;
  --orange: #C2610C;
  --orange-hell: #FFEDD5;
  --gruen: #15803D;
  --gruen-hell: #DCFCE7;
  --rot: #DC2626;
  --rot-hell: #FEE2E2;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 3px rgba(23, 24, 28, .07), 0 4px 14px rgba(23, 24, 28, .05);
  --shadow-lg: 0 8px 40px rgba(23, 24, 28, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------ Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 56px;
  padding: 0 20px;
  background: var(--ink);
  color: #fff;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 2px;
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: .04em;
  white-space: nowrap;
}

.brand-box {
  background: var(--gelb);
  color: var(--ink);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 2px;
}

.brand-claim {
  margin-left: 12px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .02em;
  color: rgba(255, 255, 255, .55);
}

.mainnav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.mainnav a {
  color: rgba(255, 255, 255, .75);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  transition: background .12s, color .12s;
}

.mainnav a:hover { color: #fff; background: rgba(255, 255, 255, .09); }

.mainnav a.active {
  color: var(--ink);
  background: var(--gelb);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.abteilung-chip {
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .07);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 99px;
  cursor: pointer;
}

.abteilung-chip:hover { border-color: var(--gelb); color: var(--gelb); }

/* ------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .1s, background .12s, border-color .12s;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.btn:hover { background: var(--surface-2); border-color: #CFCEC7; }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }

.btn-primary { background: var(--gelb); border-color: var(--gelb); color: var(--ink); }
.btn-primary:hover { background: var(--gelb-dunkel); border-color: var(--gelb-dunkel); }

.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #2A2C33; border-color: #2A2C33; }

.btn-danger { color: var(--rot); border-color: #F3C3C3; background: #fff; }
.btn-danger:hover { background: var(--rot-hell); border-color: var(--rot); }

.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(255, 255, 255, .1); border-color: transparent; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

/* ------------------------------------------------------------ Formulare */
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gelb-dunkel);
  box-shadow: 0 0 0 3px rgba(255, 196, 0, .25);
}

label.field { display: block; margin-bottom: 12px; }

label.field > span {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

label.field input, label.field select, label.field textarea { width: 100%; }

textarea { resize: vertical; min-height: 80px; }

/* ------------------------------------------------------------ Layout */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 24px 80px;
}

.page-full { padding: 0; max-width: none; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-head h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 20px; }

/* ------------------------------------------------------------ Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(255, 196, 0, .18), transparent),
    var(--ink);
  padding: 20px;
}

.login-card {
  width: 400px;
  max-width: 100%;
  background: var(--surface);
  border-radius: 16px;
  padding: 38px 36px 32px;
  box-shadow: var(--shadow-lg);
}

.login-brand { font-size: 34px; font-weight: 800; letter-spacing: .03em; }
.login-brand .brand-box { padding: 2px 9px; border-radius: 7px; }

.login-claim {
  margin: 10px 0 26px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
}

.login-hint {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

.login-error {
  background: var(--rot-hell);
  color: var(--rot);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  margin-bottom: 14px;
}

/* ------------------------------------------------------------ Statusleiste / Tabs */
.status-tabs { display: flex; gap: 8px; flex-wrap: wrap; }

.status-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-70);
  border-radius: 99px;
  padding: 6px 14px;
  cursor: pointer;
}

.status-tab .count {
  font-weight: 800;
  margin-left: 5px;
  font-size: 12px;
  color: var(--muted);
}

.status-tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.status-tab.active .count { color: var(--gelb); }

/* ------------------------------------------------------------ Suche & Filter */
.searchbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 14px;
  margin-bottom: 14px;
}

.searchbar .search-input {
  flex: 1 1 300px;
  min-width: 220px;
  font-size: 15px;
  padding: 10px 14px 10px 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6E76' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.4-3.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}

.searchbar select, .searchbar input[type="date"] { font-size: 13px; padding: 8px 9px; }

.filter-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.filter-active-note { font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------ Tabelle */
.table-wrap { overflow-x: auto; }

table.vtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.vtable th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
  user-select: none;
}

.vtable th.sortable { cursor: pointer; }
.vtable th.sortable:hover { color: var(--ink); }

.vtable td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.vtable tbody tr { cursor: pointer; transition: background .08s; }
.vtable tbody tr:hover { background: var(--gelb-hell); }
.vtable tbody tr.row-done { opacity: .62; }

.vtable .cell-nummer { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.vtable .cell-absender { font-weight: 700; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtable .cell-betreff { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-70); }
.vtable td.cell-check { width: 34px; }

.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
}

.empty-state .big { font-size: 40px; margin-bottom: 10px; }

/* ------------------------------------------------------------ Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 99px;
  padding: 3px 10px;
  white-space: nowrap;
}

.badge-neu { background: var(--blau-hell); color: var(--blau); }
.badge-in_bearbeitung { background: var(--orange-hell); color: var(--orange); }
.badge-abgeschlossen { background: var(--gruen-hell); color: var(--gruen); }

.badge-abt { background: #EFEEE9; color: var(--ink-70); }

.badge-frist { background: #EFEEE9; color: var(--ink-70); font-family: var(--mono); font-size: 11px; }
.badge-frist.due-soon { background: var(--orange-hell); color: var(--orange); }
.badge-frist.overdue { background: var(--rot-hell); color: var(--rot); }

.komm-indicator { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ------------------------------------------------------------ Bulkbar & Pager */
.bulkbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}

.bulkbar select { font-size: 12.5px; padding: 5px 8px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.pager .btns { display: flex; gap: 6px; }

/* ------------------------------------------------------------ Upload */
.dropzone {
  border: 2.5px dashed #CFCEC7;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 54px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--gelb-dunkel);
  background: var(--gelb-hell);
}

.dropzone .dz-icon { font-size: 42px; margin-bottom: 8px; }
.dropzone .dz-main { font-size: 16px; font-weight: 700; }
.dropzone .dz-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.import-row td { vertical-align: top; }
.import-row input, .import-row select { width: 100%; font-size: 13px; padding: 6px 8px; }
.import-row .fname { font-size: 11.5px; color: var(--muted); font-family: var(--mono); word-break: break-all; }
.import-status { font-size: 12px; font-weight: 700; white-space: nowrap; }
.import-status.ok { color: var(--gruen); }
.import-status.err { color: var(--rot); }
.import-status.warn { color: var(--orange); }

.progressbar {
  height: 7px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
  margin: 10px 0;
}

.progressbar > div { height: 100%; background: var(--gelb); width: 0%; transition: width .2s; }

/* ------------------------------------------------------------ Detailansicht */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 440px;
  gap: 0;
  height: calc(100vh - 56px);
}

.detail-viewer {
  background: #494B52;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: #33353B;
  color: #fff;
  font-size: 13px;
}

.viewer-toolbar .pos { font-family: var(--mono); font-size: 12px; color: rgba(255,255,255,.75); }
.viewer-toolbar .spacer { flex: 1; }

.viewer-frame { flex: 1; border: 0; width: 100%; background: #494B52; }

.viewer-img-wrap { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 20px; }
.viewer-img-wrap img { max-width: 100%; box-shadow: var(--shadow-lg); background: #fff; }

.detail-side {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 18px 40px;
}

.detail-side h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.detail-side h2:first-child { margin-top: 0; }

.detail-nummer { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.status-row { display: flex; gap: 7px; flex-wrap: wrap; }

.status-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 99px;
  padding: 6px 13px;
  cursor: pointer;
}

.status-btn.active-neu { background: var(--blau-hell); border-color: var(--blau); color: var(--blau); }
.status-btn.active-in_bearbeitung { background: var(--orange-hell); border-color: var(--orange); color: var(--orange); }
.status-btn.active-abgeschlossen { background: var(--gruen-hell); border-color: var(--gruen); color: var(--gruen); }

.action-col { display: flex; flex-direction: column; gap: 8px; }

.komm-item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}

.komm-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; font-weight: 600; }

.komm-form { display: flex; gap: 8px; margin-top: 10px; }
.komm-form textarea { flex: 1; min-height: 40px; font-size: 13px; }

.log-item {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  font-size: 12.5px;
  border-bottom: 1px dashed var(--line);
}

.log-item:last-child { border-bottom: 0; }
.log-time { font-family: var(--mono); font-size: 10.5px; color: var(--muted); white-space: nowrap; padding-top: 2px; min-width: 100px; }
.log-body b { font-weight: 700; }
.log-body .log-details { color: var(--muted); }
.log-abt { color: var(--muted); font-size: 11px; }

.kbd-hints { font-size: 11.5px; color: var(--muted); line-height: 2; }

kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--ink-70);
}

/* ------------------------------------------------------------ Briefassistent */
.brief-layout {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 20px;
  align-items: start;
}

.brief-form { padding: 20px; }

.brief-form h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 20px 0 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}

.brief-form h3:first-child { margin-top: 0; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.brief-preview-wrap {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brief-preview-scroll {
  overflow: auto;
  max-height: calc(100vh - 170px);
  padding: 22px;
  background: #494B52;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.a4scale { position: relative; flex: none; overflow: hidden; }

.a4page {
  position: relative;
  width: 210mm;
  height: 297mm;
  background: #fff;
  box-shadow: 0 6px 30px rgba(0, 0, 0, .4);
  transform-origin: top left;
  overflow: hidden;
  flex: none;
}

.a4page .el {
  position: absolute;
  white-space: pre;
  line-height: 1;
  transform: translateY(-82%);
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
}

.a4page .el.gray { color: #6B6E76; }
.a4page .mark { position: absolute; background: #9a9a9a; height: 0.3mm; }
.a4page .rule { position: absolute; background: #B9B8B2; height: 0.2mm; }

.din-note { font-size: 11.5px; color: rgba(255,255,255,.8); text-align: center; }

/* ------------------------------------------------------------ Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 24, 28, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
}

.modal h2 { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.abt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.abt-btn {
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  padding: 16px 10px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color .1s, background .1s;
}

.abt-btn:hover { border-color: var(--gelb-dunkel); background: var(--gelb-hell); }
.abt-btn.current { border-color: var(--ink); background: var(--ink); color: var(--gelb); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ------------------------------------------------------------ Toast */
#toast-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 99px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}

.toast.toast-error { background: var(--rot); }
.toast.toast-success { background: var(--gruen); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------ Einstellungen / Hilfe */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

.hilfe h3 { margin: 22px 0 8px; font-size: 16px; }
.hilfe p, .hilfe li { color: var(--ink-70); font-size: 14px; }
.hilfe ul, .hilfe ol { padding-left: 22px; margin: 8px 0; }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--gelb-dunkel);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center { text-align: center; padding: 60px; color: var(--muted); }

/* ------------------------------------------------------------ Responsive */
@media (max-width: 1100px) {
  .detail-layout { grid-template-columns: 1fr 380px; }
  .brief-layout { grid-template-columns: 1fr; }
  .brief-preview-wrap { position: static; }
}

@media (max-width: 860px) {
  .brand-claim { display: none; }
  .detail-layout { grid-template-columns: 1fr; height: auto; }
  .detail-viewer { height: 60vh; }
  .settings-grid { grid-template-columns: 1fr; }
  .mainnav { overflow-x: auto; }
}
