/* ============================================================
   BAM Consulting & KI – Dashboard Stylesheet
   CI: Navy #1a2744 · Gold #c49a2a · Off-white #f8f7f4
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  /* BAM CI Farben */
  --navy:        #1a2744;
  --navy-light:  #243358;
  --navy-dim:    #0e1829;
  --gold:        #c49a2a;
  --gold-dim:    #9a7720;
  --gold-light:  #f5edd8;

  /* Dashboard Farben */
  --bg:          #0e1829;
  --bg-card:     #162035;
  --bg-hover:    #1e2d4a;
  --bg-active:   #243358;
  --border:      #2a3a5c;
  --text:        #e8e4d8;
  --text-muted:  #8a95a8;
  --text-dim:    #4a5a78;
  --primary:     #c49a2a;
  --primary-dim: #9a7720;
  --primary-light: rgba(196,154,42,0.12);
  --success:     #4ecdc4;
  --warning:     #ffd43b;
  --danger:      #ff6b6b;
  --info:        #74c0fc;
  --sidebar-w:   230px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
  --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

/* ============================================================
   Layout
   ============================================================ */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--navy-dim);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 15px;
}

.logo-icon { font-size: 20px; }

.logo-bam {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.logo-bam-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
}
.logo-bam-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-stats {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.stat-badge {
  background: var(--bg-active);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.badge-count {
  font-weight: 700;
  font-size: 18px;
  color: var(--primary);
}

.badge-label {
  color: var(--text-muted);
  font-size: 12px;
}

.nav-list {
  list-style: none;
  padding: 0.5rem 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-right: 0.5rem;
  transition: background 0.15s;
  color: var(--text-muted);
  user-select: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--gold); border-left: 3px solid var(--gold); }
.nav-icon { font-size: 16px; }
.nav-label { font-weight: 500; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.btn-sync {
  width: 100%;
  padding: 0.6rem;
  background: var(--bg-active);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.btn-sync:hover { background: var(--bg-hover); }
.btn-sync.loading { opacity: 0.6; pointer-events: none; }

.btn-logout {
  width: 100%;
  padding: 0.6rem;
  background: transparent;
  border: 1px solid #4a1942;
  color: #f87171;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  margin-top: 0.5rem;
  transition: background 0.15s;
}
.btn-logout:hover { background: #2d1515; }

/* ============================================================
   Tab-Inhalte
   ============================================================ */
.tab-content {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.tab-content.active { display: flex; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.page-header h1 {
  font-size: 18px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ============================================================
   Emails
   ============================================================ */
.email-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.email-list-panel {
  width: 380px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.email-detail-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.email-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.email-item:hover { background: var(--bg-hover); }
.email-item.active { background: var(--bg-active); border-left: 3px solid var(--primary); }
.email-item.unread .email-from { font-weight: 700; color: var(--text); }
.email-item.unread .email-subject { font-weight: 600; }

.email-from {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.email-date {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.email-subject {
  font-size: 13px;
  margin-bottom: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.email-snippet {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.email-meta {
  display: flex;
  gap: 0.3rem;
  margin-top: 4px;
}

.email-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-active);
  color: var(--text-muted);
}

.email-tag.attachment { background: #2a4299; color: var(--info); }
.email-tag.starred    { background: #4a3800; color: var(--warning); }

/* Detail Panel */
.email-detail-header {
  margin-bottom: 1rem;
}

.email-detail-subject {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.email-detail-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 0.75rem;
}

.email-detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.email-body {
  font-size: 14px;
  line-height: 1.8;
}

.email-body-html iframe {
  width: 100%;
  border: none;
  background: white;
  border-radius: var(--radius);
  min-height: 400px;
}

/* ============================================================
   Regeln
   ============================================================ */
#rules-list {
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.rule-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.rule-card.disabled { opacity: 0.5; }

.rule-toggle {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin-top: 2px;
  transition: background 0.2s;
}

.rule-toggle.on { background: var(--success); }

.rule-toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
}

.rule-toggle.on::after { left: 18px; }

.rule-info { flex: 1; }
.rule-name { font-weight: 700; margin-bottom: 0.25rem; }
.rule-desc { color: var(--text-muted); font-size: 13px; margin-bottom: 0.5rem; }

.rule-conditions-summary {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  display: inline-block;
  margin-bottom: 0.4rem;
}

.rule-badges {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--bg-active);
  color: var(--text-muted);
}

.badge.action { background: var(--primary-dim); color: var(--info); }
.badge.trigger-count { background: #1e3a1e; color: var(--success); }

.rule-actions-btns {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Condition/Action Builder */
.condition-row, .action-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.condition-row select, .condition-row input,
.action-row select, .action-row input {
  flex: 1;
}

/* ============================================================
   Statistiken
   ============================================================ */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stats-card-wide { grid-column: 1 / -1; }
.stats-card h3 { margin-bottom: 0.75rem; font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Mini Bar Chart */
.chart-container {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 80px;
}

.bar {
  flex: 1;
  background: var(--primary-dim);
  border-radius: 2px 2px 0 0;
  min-width: 4px;
  transition: background 0.15s;
  position: relative;
}

.bar:hover { background: var(--primary); }

.bar[title] { cursor: pointer; }

.top-list { display: flex; flex-direction: column; gap: 0.4rem; }
.top-list-item { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.top-list-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-active);
  border-radius: 3px;
  margin: 0 0.5rem;
  overflow: hidden;
}

.top-list-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }
.top-list-count { color: var(--text-muted); font-size: 12px; min-width: 30px; text-align: right; }

/* ============================================================
   Logs
   ============================================================ */
.log-table-wrapper {
  flex: 1;
  overflow: auto;
  padding: 0 1rem;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--font-mono);
}

.log-table th {
  background: var(--bg-card);
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.log-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  max-width: 600px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-table tr:hover td { background: var(--bg-hover); }

.log-level {
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
}

.log-level.DEBUG    { background: #1a2a3a; color: #74c0fc; }
.log-level.INFO     { background: #1a3a1e; color: var(--success); }
.log-level.WARNING  { background: #3a2e00; color: var(--warning); }
.log-level.ERROR    { background: #3a1a1a; color: var(--danger); }
.log-level.CRITICAL { background: #5a0a0a; color: #ff9494; }

/* ============================================================
   Einstellungen
   ============================================================ */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.settings-card-wide { grid-column: 1 / -1; }
.settings-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 1rem; }

.account-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.account-item:last-child { border: none; }
.account-email { font-weight: 500; }
.account-status { font-size: 12px; color: var(--success); }

.sync-history-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sync-history-table th, .sync-history-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.sync-status.success { color: var(--success); }
.sync-status.error   { color: var(--danger); }
.sync-status.running { color: var(--warning); }

/* ============================================================
   Formulare
   ============================================================ */
.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-control, .select-input, .search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color 0.15s;
}

.form-control:focus, .select-input:focus, .search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.select-input, .search-input { width: auto; }

.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

.form-checkbox { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }
.hint { color: var(--text-dim); font-size: 11px; margin-top: 0.25rem; display: block; }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary, .btn-secondary, .btn-danger, .btn-icon {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary   { background: var(--primary); color: white; }
.btn-secondary { background: var(--bg-active); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger); color: white; }
.btn-icon      { background: transparent; color: var(--text-muted); padding: 0.3rem 0.5rem; }

.btn-primary:hover   { opacity: 0.9; }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger:hover    { opacity: 0.9; }
.btn-icon:hover      { color: var(--text); }

.btn-sm { padding: 0.35rem 0.6rem; font-size: 12px; }

/* ============================================================
   Modal
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal.open { display: flex; align-items: center; justify-content: center; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-large { width: 740px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 16px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 18px; }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal-body h3 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1rem 0 0.5rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============================================================
   Pagination
   ============================================================ */
.pagination {
  display: flex;
  gap: 0.3rem;
  padding: 0.75rem 1.5rem;
  justify-content: center;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.page-btn {
  background: var(--bg-active);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
}

.page-btn:hover { background: var(--bg-hover); }
.page-btn.active { background: var(--primary); border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 250px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }
.toast.info    { border-left: 3px solid var(--info);    }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ============================================================
   Hilfsstile
   ============================================================ */
.loading {
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
}

.empty-icon { font-size: 48px; margin-bottom: 0.75rem; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============================================================
   Mobile Navigation Toggle
   ============================================================ */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.mobile-title {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
}

.back-btn {
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ============================================================
   Responsive – Tablet (≤1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }

  .email-list-panel { width: 300px; }

  .stats-grid { grid-template-columns: 1fr; }
  .stats-card-wide { grid-column: 1; }
}

/* ============================================================
   Responsive – Mobile (≤768px)
   ============================================================ */
@media (max-width: 768px) {
  body { overflow: auto; }

  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  /* Mobile header bar */
  .mobile-header { display: flex; }

  /* Sidebar als Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 260px;
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  /* Hauptbereich */
  .main-content {
    height: auto;
    min-height: calc(100vh - 50px);
  }

  .tab-content {
    height: auto;
    min-height: calc(100vh - 50px);
  }

  /* Page Header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-actions .search-input,
  .header-actions .select-input {
    flex: 1;
    min-width: 120px;
  }

  /* Email Layout */
  .email-layout {
    flex-direction: column;
  }

  .email-list-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  .email-detail-panel {
    padding: 1rem;
  }

  /* Email Detail: auf Mobile ausblenden bis Email gewählt */
  .email-detail-panel.mobile-hidden {
    display: none;
  }

  .email-list-panel.mobile-hidden {
    display: none;
  }

  .back-btn { display: flex; }

  /* Stats */
  .stats-overview {
    grid-template-columns: repeat(2, 1fr);
    padding: 0.75rem 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    padding: 0.75rem 1rem;
  }

  .stats-card-wide { grid-column: 1; }

  /* Settings */
  .settings-grid {
    grid-template-columns: 1fr;
    padding: 0.75rem 1rem;
  }

  .settings-card-wide { grid-column: 1; }

  /* Logs */
  .log-table-wrapper { padding: 0 0.5rem; }

  .log-table th:nth-child(2),
  .log-table td:nth-child(2) { display: none; }

  /* Modals */
  .modal-content, .modal-large {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
    position: fixed;
    bottom: 0;
    border-bottom: none;
  }

  .modal.open { align-items: flex-end; }

  /* Buttons */
  .btn-primary, .btn-secondary { padding: 0.6rem 0.9rem; }

  /* Pagination */
  .pagination { padding: 0.5rem; }

  /* Toast */
  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

  .toast { min-width: unset; width: 100%; }

  /* Form rows stack */
  .form-row { flex-direction: column; }
}

/* ============================================================
   Chat – Leon KI-Assistent
   ============================================================ */

#tab-chat { padding: 0; overflow: hidden; }

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info { display: flex; align-items: center; gap: 0.75rem; }
.chat-avatar { font-size: 2rem; }
.chat-name { font-weight: 600; font-size: 1rem; }
.chat-status { font-size: 0.75rem; color: var(--success); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex: 1;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

.chat-welcome-icon { font-size: 3rem; }
.chat-welcome-text { font-size: 0.95rem; line-height: 1.6; }

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  gap: 0.2rem;
}

.chat-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1.2rem;
  line-height: 1.5;
  font-size: 0.9rem;
  word-break: break-word;
}

.chat-msg-user .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 0.3rem;
}

.chat-msg-assistant .chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 0.3rem;
}

.chat-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
}

.chat-time {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 0 0.3rem;
}

/* Typing indicator */
.chat-typing-bubble {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.75rem 1rem;
}

.chat-typing-bubble span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}

.chat-typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 1.2rem;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--primary);
}

.chat-input::placeholder { color: var(--text-dim); }

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.chat-send-btn:hover { background: var(--primary-dim); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile Chat */
@media (max-width: 768px) {
  .chat-container { max-width: 100%; }
  .chat-messages { padding: 1rem; }
  .chat-msg { max-width: 90%; }
  .chat-input-area { padding: 0.75rem 1rem; }
}

/* ============================================================
   Dashboard Widget – Begrüssung, Wetter, News, Stats
   ============================================================ */

.dashboard-widget {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.widget-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
}

/* Greeting */
.widget-greeting {
  grid-column: 1 / 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#widget-greeting {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.greeting-emoji { font-size: 2rem; flex-shrink: 0; }
.greeting-main  { font-size: 1rem; font-weight: 600; color: var(--text); }
.greeting-date  { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.1rem; }

/* Stats */
.widget-stats-card {
  grid-column: 2 / 3;
}

#widget-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.wstat {
  text-align: center;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.wstat-alert { background: rgba(255,107,107,0.1); }
.wstat-warn  { background: rgba(255,212,59,0.1); }

.wstat-val   { font-size: 1.4rem; font-weight: 700; color: var(--gold); line-height: 1; }
.wstat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.15rem; }

/* Weather */
.widget-weather-card {
  grid-column: 3 / 4;
  grid-row: 1 / 3;
}

.weather-current {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.weather-emoji    { font-size: 2.5rem; }
.weather-temp     { font-size: 1.5rem; font-weight: 700; color: var(--gold); }
.weather-desc     { font-size: 0.75rem; color: var(--text-muted); }
.weather-wind     { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.15rem; }

.weather-forecast {
  display: flex;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.weather-forecast-day {
  flex: 1;
  text-align: center;
}

.forecast-label { font-size: 0.65rem; color: var(--text-muted); }
.forecast-emoji { font-size: 1.1rem; margin: 0.2rem 0; }
.forecast-temp  { font-size: 0.75rem; font-weight: 600; color: var(--text); }
.forecast-min   { font-size: 0.65rem; color: var(--text-dim); }

/* News */
.widget-news-card {
  grid-column: 1 / 3;
}

.widget-news-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

#widget-news {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.news-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  overflow: hidden;
}

.news-item:hover { background: var(--bg-hover); }

.news-source {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--gold);
  background: var(--primary-light);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.news-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news-title:hover { color: var(--text); }

/* Mobile Widget */
@media (max-width: 768px) {
  .dashboard-widget {
    grid-template-columns: 1fr 1fr;
    padding: 0.75rem 1rem;
  }
  .widget-greeting    { grid-column: 1 / 3; }
  .widget-stats-card  { grid-column: 1 / 2; }
  .widget-weather-card { grid-column: 2 / 3; grid-row: auto; }
  .widget-news-card   { grid-column: 1 / 3; display: none; }
  .weather-forecast   { display: none; }
  #widget-stats       { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   Chat – Modern Redesign
   ============================================================ */

/* Leon Avatar */
.leon-avatar-lg {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: var(--navy-dim);
  box-shadow: 0 4px 20px rgba(196,154,42,0.35);
}

.leon-avatar-sm {
  width: 32px; height: 32px; min-width: 32px;
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: var(--navy-dim);
  align-self: flex-end; margin-bottom: 4px;
}

/* Welcome Screen */
.chat-welcome-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.5rem; flex: 1; padding: 2rem 1rem;
  text-align: center;
}

.leon-welcome-name { font-size: 1.4rem; font-weight: 700; color: var(--gold); }
.leon-welcome-sub  { font-size: 0.75rem; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 0.5rem; }
.leon-welcome-msg  { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; max-width: 280px; }

/* Quick Actions */
.quick-actions {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  justify-content: center; margin-top: 1rem; max-width: 360px;
}

.quick-action-btn {
  background: var(--primary-light);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 20px;
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
  font-family: var(--font);
}

.quick-action-btn:hover {
  background: var(--gold); color: var(--navy-dim);
}

/* Message Layout */
.chat-msg { display: flex; gap: 0.6rem; max-width: 85%; }
.chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-assistant { align-self: flex-start; }

.chat-msg-body { display: flex; flex-direction: column; gap: 0.2rem; }
.chat-msg-user .chat-msg-body { align-items: flex-end; }
.chat-msg-assistant .chat-msg-body { align-items: flex-start; }

/* Bubbles */
.chat-msg-user .chat-bubble {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: var(--navy-dim);
  border-radius: 18px 18px 4px 18px;
  font-weight: 500;
}

.chat-msg-assistant .chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 18px 18px 18px 4px;
}

/* Action Card */
.chat-action-card {
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin: 0.5rem 0;
  align-self: flex-start;
  max-width: 85%;
}

.action-card-q {
  font-size: 0.85rem; color: var(--text); margin-bottom: 0.6rem;
}

.action-card-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.action-card-btn {
  background: var(--gold); color: var(--navy-dim);
  border: none; border-radius: 6px;
  padding: 0.4rem 0.8rem; font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
  font-family: var(--font);
}

.action-card-btn:hover { background: var(--gold-dim); color: var(--text); }
.action-card-dismiss { background: var(--bg-hover); color: var(--text-muted); }
.action-card-dismiss:hover { background: var(--bg-active); color: var(--text); }

/* Mobile */
@media (max-width: 768px) {
  .chat-msg { max-width: 92%; }
  .quick-actions { max-width: 100%; }
}

/* ============================================================
   Wichtigkeit & Draft
   ============================================================ */

/* Email-Liste Wichtigkeit */
.email-item.importance-urgent { border-left: 3px solid var(--danger); }
.email-item.importance-high   { border-left: 3px solid var(--gold); }

.email-tag.importance-tag.urgent { background: rgba(255,107,107,0.15); color: var(--danger); font-weight: 600; }
.email-tag.importance-tag.high   { background: rgba(196,154,42,0.15);  color: var(--gold);   font-weight: 600; }

/* Importance Banner im Detail */
.importance-banner {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
}
.importance-banner.urgent { background: rgba(255,107,107,0.12); color: var(--danger); border: 1px solid rgba(255,107,107,0.3); }
.importance-banner.high   { background: rgba(196,154,42,0.12);  color: var(--gold);   border: 1px solid rgba(196,154,42,0.3); }

/* Draft Offer */
.draft-offer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--primary-light);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.draft-offer-icon { font-size: 1.5rem; flex-shrink: 0; }
.draft-offer-text { flex: 1; font-size: 0.875rem; color: var(--text); }
.draft-offer-btns { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Draft Panel */
.draft-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1.5rem;
}

.draft-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.draft-meta { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.75rem; }
.draft-body { width: 100%; margin-bottom: 0.75rem; min-height: 150px; font-family: var(--font); font-size: 0.875rem; }

.draft-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

@media (max-width: 768px) {
  .draft-offer { flex-direction: column; align-items: flex-start; }
  .draft-actions { flex-direction: column; }
}
