/* Karolinger Mail-Manager - Stylesheet */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #202020;
  background: #f4f4f1;
  line-height: 1.5;
}
a { color: #185fa5; text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: 1px solid #e0e0db; margin: 20px 0; }
code { background: #efeee8; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.muted { color: #666; }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* Top nav */
.topnav {
  background: white;
  padding: 12px 24px;
  border-bottom: 1px solid #e0e0db;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { font-size: 16px; }
.nav-links { display: flex; gap: 16px; align-items: center; }
.nav-links a { color: #333; }
.nav-user { color: #666; font-size: 12px; }
.nav-links form { margin: 0; }

/* Layout */
.main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.layout-2col { display: grid; grid-template-columns: 220px 1fr; gap: 20px; }
.detail-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }

/* Sidebar */
.sidebar { background: white; border: 1px solid #e0e0db; border-radius: 8px; padding: 12px; height: fit-content; }
.sb-section { margin-bottom: 16px; }
.sb-section:last-child { margin-bottom: 0; }
.sb-h { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 8px 4px; }
.sb-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; border-radius: 6px; color: #333; font-size: 13px;
}
.sb-item:hover { background: #f4f4f1; text-decoration: none; }
.sb-item.on { background: #e6f1fb; color: #0c447c; font-weight: 500; }
.sb-item .ct {
  font-size: 11px; color: #666; background: #efeee8; padding: 1px 7px; border-radius: 10px;
}
.sb-item.on .ct { background: #b5d4f4; color: #0c447c; }

/* Content area */
.content { background: white; border: 1px solid #e0e0db; border-radius: 8px; overflow: hidden; }
.toolbar {
  padding: 12px; border-bottom: 1px solid #e0e0db; display: flex; gap: 8px; background: #fafaf6;
}
.toolbar input[type=text] { flex: 1; }

/* Inputs */
input[type=text], input[type=password], input[type=email], select, textarea {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px;
  font-family: inherit; background: white;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #185fa5; box-shadow: 0 0 0 2px rgba(24, 95, 165, 0.15); }
textarea { width: 100%; resize: vertical; line-height: 1.5; }

/* Buttons */
button, .btn-small, .btn-primary, .btn-secondary {
  font-family: inherit; font-size: 13px; padding: 7px 14px;
  border: 1px solid #ccc; border-radius: 6px; cursor: pointer;
  background: white; color: #333;
}
button:hover, .btn-small:hover { background: #f4f4f1; }
.btn-primary { background: #185fa5; color: white; border-color: #185fa5; }
.btn-primary:hover { background: #0c447c; }
.btn-secondary { background: #efeee8; }
.btn-warning {
  background: #d97706; color: white; border-color: #d97706;
  font-family: inherit; font-size: 13px; padding: 7px 14px;
  border-radius: 6px; cursor: pointer;
}
.btn-warning:hover { background: #b45309; border-color: #b45309; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* Mail list */
.mail-list { }
.mail-item {
  display: block; padding: 12px 16px; border-bottom: 1px solid #f0efe8;
  color: #333; cursor: pointer;
}
.mail-item:hover { background: #f8f8f4; text-decoration: none; }
.mail-item.unread { background: #fafcff; }
.mail-item.unread .mail-from { font-weight: 600; }
.mail-item.done { opacity: 0.6; }
.mail-row1 { display: flex; justify-content: space-between; margin-bottom: 4px; }
.mail-from { font-size: 13px; }
.mail-time { font-size: 11px; color: #888; }
.mail-subject { font-size: 13px; color: #333; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-preview { font-size: 12px; color: #666; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-badges { display: flex; gap: 4px; flex-wrap: wrap; }

/* Badges */
.bdg {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px;
  font-weight: 500;
}
.bdg.prio-high { background: #fcebeb; color: #791f1f; }
.bdg.prio-med { background: #faeeda; color: #633806; }
.bdg.prio-low { background: #f1efe8; color: #444; }
.bdg.cat-versand { background: #e6f1fb; color: #0c447c; }
.bdg.cat-rezept { background: #eeedfe; color: #3c3489; }
.bdg.cat-reklamation { background: #fcebeb; color: #791f1f; }
.bdg.cat-rechnung { background: #e1f5ee; color: #085041; }
.bdg.cat-retoure { background: #faece7; color: #712b13; }
.bdg.done { background: #e1f5ee; color: #085041; }
.bdg.waiting { background: #fef3c7; color: #78350f; }
.bdg.customer { background: #efeee8; color: #444; }
.bdg.ai { background: #fef9e7; color: #856404; border: 1px solid #f4d35e; }
.bdg.flag { background: #f7e4d4; color: #712b13; }
.bdg.order-shipped { background: #e6f1fb; color: #0c447c; }
.bdg.order-delivered { background: #e1f5ee; color: #085041; }
.bdg.order-processing { background: #faeeda; color: #633806; }
.bdg.order-cancelled { background: #fcebeb; color: #791f1f; }

/* Detail */
.back-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.detail-main { background: white; border: 1px solid #e0e0db; border-radius: 8px; padding: 20px 24px; }
.detail-subject { font-size: 20px; margin: 8px 0 12px; }
.detail-meta { color: #666; font-size: 13px; margin-bottom: 16px; }
.detail-meta div { margin: 2px 0; }
.mail-body {
  background: #fafaf6; border: 1px solid #e0e0db; border-radius: 6px;
  padding: 14px 16px; white-space: pre-wrap; font-size: 13px; line-height: 1.65;
  margin-bottom: 4px; max-height: 400px; overflow-y: auto;
}

/* Templates */
.templates-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 14px; align-items: center; }
.chip {
  display: inline-block; padding: 5px 12px; border-radius: 14px;
  border: 1px solid #ccc; background: white; cursor: pointer; font-size: 12px;
}
.chip:hover { background: #f4f4f1; }
.chip.on { background: #185fa5; color: white; border-color: #185fa5; }

/* Reply form */
.reply-form { display: flex; flex-direction: column; gap: 10px; }
.reply-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #555; }
.reply-form input[type=text] { width: 100%; }
.form-actions { display: flex; gap: 8px; margin-top: 6px; }

/* Reply history */
.reply-history { display: flex; flex-direction: column; gap: 12px; }
.reply-item { border-left: 3px solid #c0dd97; padding: 8px 12px; background: #fafaf6; border-radius: 4px; }
.reply-item.reply-err { border-left-color: #e24b4a; background: #fef5f5; }
.reply-meta { font-size: 12px; color: #666; margin-bottom: 6px; }
.reply-body { font-size: 12px; white-space: pre-wrap; margin: 0; font-family: inherit; }

/* Side panel */
.detail-side h3 { margin: 0 0 8px; font-size: 14px; }
.detail-side h4 { margin: 14px 0 6px; font-size: 13px; }
.card {
  background: white; border: 1px solid #e0e0db; border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px;
}
.customer-name { font-weight: 600; margin-bottom: 2px; }
table.kv { width: 100%; font-size: 12px; margin-top: 8px; }
table.kv td { padding: 3px 0; }
table.kv td:first-child { color: #666; }
table.kv td:last-child { text-align: right; font-weight: 500; }
.customer-flags { margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.order-row { padding: 6px 0; border-bottom: 1px solid #f0efe8; }
.order-row:last-child { border-bottom: none; }
.order-header { display: flex; justify-content: space-between; margin-bottom: 2px; }

/* Login */
.login-box {
  max-width: 360px; margin: 60px auto; background: white;
  padding: 28px; border: 1px solid #e0e0db; border-radius: 10px;
}
.login-box h1 { margin: 0 0 4px; font-size: 18px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #555; }

/* Flash */
.flash-container { max-width: 1400px; margin: 10px auto 0; padding: 0 24px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 13px; }
.flash-info { background: #e6f1fb; color: #0c447c; }
.flash-success { background: #e1f5ee; color: #085041; }
.flash-error { background: #fcebeb; color: #791f1f; }

/* Status */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.status-dot.ok { background: #1d9e75; }
.status-dot.err { background: #e24b4a; }

/* Data table */
.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: 6px; overflow: hidden; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; font-size: 12px; border-bottom: 1px solid #f0efe8; }
.data-table th { background: #fafaf6; font-weight: 500; color: #555; }
.data-table tr:hover td { background: #fafaf6; }

/* Empty state */
.empty-state { padding: 40px 20px; text-align: center; color: #666; }

/* Dashboard-Karten */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.dash-card {
  background: white;
  border: 1px solid #e5e3d8;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s, box-shadow 0.1s;
}
.dash-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.05); text-decoration: none; }
.dash-card.highlight { background: #fff7ed; border-color: #fdba74; }
.dash-card.warn { background: #fee2e2; border-color: #fca5a5; }
.dash-card.good { background: #d1fae5; border-color: #6ee7b7; }
.dash-num { font-size: 28px; font-weight: 600; line-height: 1; }
.dash-label { font-size: 12px; color: #666; margin-top: 6px; }

/* Tastatur-Fokus */
.mail-item-row.keyboard-focus {
  outline: 2px solid #5b8fb9;
  outline-offset: -2px;
  background: #f0f7ff;
}

/* Shortcut-Hilfe Overlay */
.shortcut-help {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.shortcut-help-box {
  background: white; padding: 24px 32px; border-radius: 12px;
  min-width: 320px; max-width: 480px;
}
.shortcut-help-box h3 { margin-top: 0; }
.shortcut-help-box table { width: 100%; border-collapse: collapse; }
.shortcut-help-box td { padding: 8px 0; }
.shortcut-help-box td:first-child { width: 80px; }
kbd {
  display: inline-block;
  padding: 2px 8px;
  background: #f4f3ed;
  border: 1px solid #d4d2c5;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}

/* KI-Entwurf-Panel */
.ai-draft-panel {
  background: linear-gradient(135deg, #fef9e7 0%, #fff8db 100%);
  border: 1px solid #f4d35e;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.ai-draft-panel.accepted {
  opacity: 0.5;
  background: #f0f7ff;
}
.ai-draft-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.ai-icon { font-size: 18px; }
.ai-confidence {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.ai-confidence.high { background: #d1fae5; color: #065f46; }
.ai-confidence.med { background: #fef3c7; color: #78350f; }
.ai-confidence.low { background: #fee2e2; color: #7f1d1d; }
.ai-intent { margin-bottom: 6px; }
.ai-draft-body {
  background: white;
  border: 1px solid #f4d35e;
  border-radius: 6px;
  padding: 12px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
}

/* Permanent-Templates */
.templates-row.permanent { margin-top: 6px; }
.chip-permanent {
  background: #fff7ed;
  border-color: #fdba74;
  color: #9a3412;
}
.chip-permanent:hover { background: #ffedd5; }
.chip-permanent.on { background: #fb923c; color: white; }

/* KI-Generate Button */
.ai-gen-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.ai-gen-btn { background: #fef9e7; border-color: #f4d35e; }

/* Rechnungen */
.invoice-actions {
  background: #f4f3ed;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 12px;
}
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.invoice-table th, .invoice-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e5e3d8;
}
.invoice-table th {
  background: #f4f3ed;
  font-weight: 600;
}
.invoice-detail-card {
  background: white;
  border: 1px solid #e5e3d8;
  border-radius: 10px;
  padding: 20px;
  margin: 20px 0;
}
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin: 16px 0;
}
.alert-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #7f1d1d;
}

/* Anhaenge */
.attachments-section {
  background: #f8f8f4;
  border: 1px solid #e5e3d8;
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 12px;
}
.attachments-section strong { margin-right: 10px; }
.attachment-list { margin: 10px 0; }
.attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: white;
  border: 1px solid #e5e3d8;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 13px;
}
.att-icon { font-size: 14px; }
.att-name { font-weight: 500; }
.att-size { margin-right: auto; }
.btn-link-danger {
  background: transparent;
  border: none;
  color: #c44;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
}
.btn-link-danger:hover { color: #a33; }
.upload-form { margin-top: 6px; display: flex; align-items: center; gap: 10px; }

/* Rechnungs-Formular */
.invoice-form-page { max-width: 720px; }
.invoice-form-summary {
  background: #f4f3ed;
  border: 1px solid #e5e3d8;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 20px;
  line-height: 1.7;
}
.invoice-customer-form {
  background: white;
  border: 1px solid #e5e3d8;
  border-radius: 10px;
  padding: 24px;
}
.invoice-customer-form .form-row {
  display: flex;
  gap: 16px;
  margin-top: 14px;
}
.invoice-customer-form label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: #555;
  flex: 1;
  gap: 4px;
}
.invoice-customer-form label.full-width { width: 100%; }
.invoice-customer-form input[type="text"] {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #d4d2c5;
  border-radius: 6px;
  font-family: inherit;
}
.invoice-customer-form input:focus {
  outline: none;
  border-color: #5b8fb9;
  box-shadow: 0 0 0 2px rgba(91,143,185,0.15);
}
.required { color: #c44; }

/* Eingehende Anhaenge */
.incoming-attachments {
  background: #f0f7ff;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
}
.incoming-attachments .att-name {
  color: #1d4ed8;
  text-decoration: none;
}
.incoming-attachments .att-name:hover {
  text-decoration: underline;
}

/* KI-Chat aus Stichpunkten */
.ki-chat-form {
  background: linear-gradient(135deg, #fef9e7 0%, #fff8db 100%);
  border: 1px solid #f4d35e;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 16px 0;
}
.ki-chat-form label {
  display: block;
  margin-bottom: 8px;
}
.ki-chat-form textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid #f4d35e;
  border-radius: 6px;
  margin-top: 6px;
  resize: vertical;
  box-sizing: border-box;
}
.ki-chat-form button {
  margin-right: 10px;
}


/* Loeschen */
.btn-danger {
  background: #c44; color: white; border-color: #c44;
  font-size: 13px; padding: 7px 14px; border-radius: 6px; cursor: pointer;
  font-family: inherit;
}
.btn-danger:hover { background: #a33; border-color: #a33; }

/* Bulk-Auswahl */
.bulk-bar {
  background: #fffbeb;
  border: 1px solid #fbe5a8;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.mail-item-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #f0efe8;
}
.mail-item-row:hover { background: #f8f8f4; }
.mail-item-row.unread { background: #fafcff; }
.mail-item-row.unread .mail-from { font-weight: 600; }
.mail-item-row.done { opacity: 0.6; }
.mail-checkbox {
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  cursor: pointer;
}
.mail-checkbox input { width: 16px; height: 16px; cursor: pointer; }
.mail-item-link {
  flex: 1;
  display: block;
  padding: 12px 16px 12px 4px;
  color: #333;
}
.mail-item-link:hover { text-decoration: none; }

