:root {
  --navy: #16283f;
  --navy-2: #1e3a5f;
  --accent: #2563eb;
  --accent-h: #1d4ed8;
  --bg: #f1f4f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 30, 60, .08), 0 4px 16px rgba(15, 30, 60, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0 0 .5em; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 5px; color: #334155; }
label .req { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: 8px; font-weight: 600;
  transition: background .15s;
}
.btn:hover { background: var(--accent-h); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f8fafc; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--muted); border: none; padding: 5px 8px; }
.btn.ghost:hover { color: var(--text); background: #eef2f7; }

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

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff;
  white-space: nowrap;
}
.chip .x { cursor: pointer; opacity: .8; font-weight: 700; }
.chip .x:hover { opacity: 1; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.Neu { background: #fee2e2; color: #b91c1c; }
.badge.b-inb, .badge.InBearbeitung { background: #fef3c7; color: #92400e; }
.badge.b-warten { background: #dbeafe; color: #1d4ed8; }
.badge.Erledigt { background: #dcfce7; color: #166534; }
.badge.Geschlossen { background: #e2e8f0; color: #475569; }

.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 13.5px; margin-top: 10px; min-height: 1.2em; }

/* ============ Auth / öffentliche Seiten ============ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 60%, #2a4d7a 100%);
  padding: 24px;
}
.auth-card { width: 420px; max-width: 100%; padding: 34px; }
.auth-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-card .logo-mark {
  width: 42px; height: 42px; border-radius: 10px; background: var(--navy-2);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; letter-spacing: .5px;
}
.auth-card h1 { font-size: 19px; margin: 0; }
.auth-card .sub { color: var(--muted); font-size: 13px; }
.step { display: none; }
.step.active { display: block; }

.public-wrap { max-width: 720px; margin: 0 auto; padding: 40px 20px 80px; }
.public-header { text-align: center; margin-bottom: 26px; }
.public-header .logo-mark {
  width: 54px; height: 54px; border-radius: 14px; background: var(--navy-2);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; margin-bottom: 12px;
}

.filebox {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.filebox:hover, .filebox.drag { border-color: var(--accent); background: #f0f6ff; }
.filelist { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.filelist .fitem {
  display: flex; align-items: center; gap: 10px;
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; font-size: 13px;
}
.filelist .fitem .rm { margin-left: auto; color: var(--danger); cursor: pointer; font-weight: 700; }

/* ============ App-Layout ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--navy); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px;
  color: #fff; font-weight: 700; font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800;
}
.sidebar nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 10px 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: #cbd5e1;
  font-weight: 500; margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a .cnt {
  margin-left: auto; background: rgba(255,255,255,.15);
  border-radius: 999px; padding: 1px 8px; font-size: 11.5px;
}
.sidebar nav a.active .cnt { background: rgba(255,255,255,.25); }
.sidebar .userbox {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.sidebar .userbox .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #334e6e;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700;
}
.sidebar .userbox .uinfo { overflow: hidden; }
.sidebar .userbox .uinfo div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .userbox .logout { margin-left: auto; color: #94a3b8; cursor: pointer; background: none; border: none; font-size: 16px; }
.sidebar .userbox .logout:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head .spacer { flex: 1; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { padding: 18px 20px; }
.stat .num { font-size: 30px; font-weight: 750; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.accent { border-left: 4px solid var(--accent); }
.stat.red { border-left: 4px solid var(--danger); }
.stat.green { border-left: 4px solid var(--ok); }
.stat.orange { border-left: 4px solid var(--warn); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-grid .card h2 { font-size: 15px; margin-bottom: 12px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid #f0f3f8; cursor: pointer;
}
.list-plain li:last-child { border-bottom: none; }
.list-plain li:hover { background: #f8fafc; }
.list-plain .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Mail */
.mail-layout { display: flex; gap: 0; height: calc(100vh - 130px); background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.mail-list { width: 380px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; }
.mail-item { padding: 12px 16px; border-bottom: 1px solid #f0f3f8; cursor: pointer; }
.mail-item:hover { background: #f8fafc; }
.mail-item.sel { background: #eef4ff; }
.mail-item .row1 { display: flex; align-items: baseline; gap: 8px; }
.mail-item .from { font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.read .from { font-weight: 450; color: #475569; }
.mail-item .mdate { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.mail-item .subj { font-size: 13.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.read .subj { color: var(--muted); }
.mail-item .snip { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.mail-item .chips { margin-top: 5px; display: flex; gap: 5px; flex-wrap: wrap; }
.mail-item .chips .chip { font-size: 10.5px; padding: 1px 8px; }
.mail-item .flag { color: #f59e0b; }
.mail-view { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mail-view .mv-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); }
.mail-view .mv-body { flex: 1; overflow-y: auto; padding: 22px; }
.mail-view .mv-body iframe { width: 100%; height: 100%; border: none; min-height: 400px; }
.mail-view .mv-body pre { white-space: pre-wrap; font: inherit; margin: 0; }
.mv-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.empty-view { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 8px; }
.empty-view .big { font-size: 40px; opacity: .4; }

/* Tabellen */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--border); }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid #f0f3f8; vertical-align: middle; }
table.tbl tr.rowlink { cursor: pointer; }
table.tbl tr.rowlink:hover { background: #f8fafc; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 25, 45, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 20px 20px; z-index: 100; overflow-y: auto;
}
.modal { width: 640px; max-width: 100%; padding: 26px; position: relative; }
.modal.wide { width: 860px; }
.modal .close { position: absolute; top: 14px; right: 16px; border: none; background: none; font-size: 20px; color: var(--muted); }
.modal .close:hover { color: var(--text); }
.modal h2 { font-size: 17px; margin-bottom: 6px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* Kalender */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cal-head h2 { margin: 0; font-size: 17px; min-width: 190px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-grid .dow { background: #f8fafc; padding: 8px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-cell { background: #fff; min-height: 104px; padding: 6px; cursor: pointer; position: relative; }
.cal-cell:hover { background: #f8fafc; }
.cal-cell.other { background: #fafbfd; color: #b6c2d2; }
.cal-cell .dnum { font-size: 12.5px; font-weight: 650; margin-bottom: 4px; }
.cal-cell.today .dnum { background: var(--accent); color: #fff; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.cal-ev { font-size: 11px; color: #fff; border-radius: 4px; padding: 1.5px 6px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* Todos */
.todo-item { display: flex; align-items: center; gap: 12px; padding: 11px 6px; border-bottom: 1px solid #f0f3f8; }
.todo-item input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; }
.todo-item .t-title { font-weight: 600; }
.todo-item.done .t-title { text-decoration: line-through; color: var(--muted); font-weight: 450; }
.todo-item .t-meta { font-size: 12.5px; color: var(--muted); }
.todo-item .t-meta.overdue { color: var(--danger); font-weight: 600; }

/* Settings */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 10px 16px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.label-row { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 1px solid #f0f3f8; }
.label-row .swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid rgba(0,0,0,.1); flex-shrink: 0; cursor: pointer; padding: 0; }
input[type=color].swatch { -webkit-appearance: none; appearance: none; }
input[type=color].swatch::-webkit-color-swatch-wrapper { padding: 2px; }
input[type=color].swatch::-webkit-color-swatch { border: none; border-radius: 5px; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 700px) { .form-2col { grid-template-columns: 1fr; } }

.q-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.q-row input, .q-row select { width: auto; flex: 1; min-width: 140px; padding: 6px 10px; }
.q-row .opts { flex-basis: 100%; }
.q-row .opts input { width: 100%; }

/* Toast */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 18px;
  border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px;
  max-width: 360px; animation: slidein .25s ease;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.checkbox-line { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkbox-line input { width: auto; }
.checkbox-line label { margin: 0; font-weight: 500; }

.dropdown { position: relative; display: inline-block; }
.dropdown .menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px; min-width: 210px;
}
.dropdown .menu .mi { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.dropdown .menu .mi:hover { background: #f1f5f9; }
.dropdown .menu .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
