/* ============================================
   MESKES CRM - Stylesheet
   ============================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0891b2;
  --info-light: #ecfeff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-width: 210px;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

/* Dark Mode */
[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #1e3a5f;
  --success: #22c55e;
  --success-light: #14291e;
  --warning: #f59e0b;
  --warning-light: #2d2005;
  --danger: #ef4444;
  --danger-light: #2d1515;
  --info: #06b6d4;
  --info-light: #0a2530;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active: #3b82f6;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.3);
}

[data-theme="dark"] tbody tr:hover { background: #1e3a5f; }
[data-theme="dark"] .btn-secondary { background: #334155; color: #f1f5f9; border-color: #475569; }
[data-theme="dark"] .btn-secondary:hover { background: #475569; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #1e293b; color: #f1f5f9; border-color: #334155;
}
[data-theme="dark"] input::placeholder, [data-theme="dark"] textarea::placeholder { color: #64748b; }
[data-theme="dark"] .modal { background: #1e293b; }
[data-theme="dark"] .modal-header { border-color: #334155; background: #1e293b; }
[data-theme="dark"] .tab { background: #1e293b; color: #94a3b8; border-color: #334155; }
[data-theme="dark"] .tab.active { background: #3b82f6; color: white; }
[data-theme="dark"] #picker-overlay > div { background: #1e293b !important; }
[data-theme="dark"] #picker-overlay > div > div { background: #1e293b !important; border-color: #334155 !important; }
[data-theme="dark"] #picker-list { background: #1e293b !important; }
[data-theme="dark"] #picker-list > div:hover { background: #334155 !important; }
[data-theme="dark"] .login-card { background: #1e293b; }
[data-theme="dark"] .login-body { background: #0f172a; }

/* Dark mode theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin: 8px 12px;
  border-radius: var(--radius);
  background: none;
  border: 1px solid var(--sidebar-hover);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 13px;
  width: calc(100% - 24px);
  transition: background 0.15s;
}
.theme-toggle:hover { background: var(--sidebar-hover); }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ============ LOGIN ============ */
.login-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e40af 100%);
}

.login-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 24px;
}

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

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-text {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 4px;
}

.logo-sub {
  display: block;
  font-size: 12px;
  letter-spacing: 6px;
  color: var(--text-muted);
  margin-top: -4px;
}

.login-footer {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  letter-spacing: 2px;
}

/* ============ LAYOUT ============ */
#app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo .logo-text {
  font-size: 20px;
  font-weight: 800;
  color: white;
  letter-spacing: 3px;
}

.sidebar-logo .logo-sub {
  font-size: 10px;
  letter-spacing: 4px;
  color: rgba(255,255,255,0.4);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 14px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
}

.nav-item.active {
  background: rgba(37, 99, 235, 0.2);
  color: white;
  border-left-color: var(--primary);
}

.nav-item.nav-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-name {
  color: white;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  color: rgba(255,255,255,0.4);
  font-size: 11px;
  text-transform: capitalize;
}

.btn-logout {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.4);
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
}

.btn-logout:hover { color: var(--danger); background: rgba(220,38,38,0.1); }
.btn-logout svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 40px;
}

.app-footer {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  letter-spacing: 1px;
  z-index: 50;
}

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.page-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.page-body {
  padding: 20px 24px;
}

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 20px; }

/* ============ STAT CARDS ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

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

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

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

.stat-card.primary { border-top: 3px solid var(--primary); }
.stat-card.success { border-top: 3px solid var(--success); }
.stat-card.warning { border-top: 3px solid var(--warning); }
.stat-card.danger { border-top: 3px solid var(--danger); }
.stat-card.info { border-top: 3px solid var(--info); }

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  gap: 8px;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  padding: 8px 0;
  font-size: 14px;
  width: 100%;
  background: transparent;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

/* ============ TABLE ============ */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--bg);
  padding: 10px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  cursor: pointer;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--primary-light); }

tbody td {
  padding: 12px 16px;
  font-size: 14px;
  vertical-align: middle;
}

.table-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

/* ============ BADGES / STATUS ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-neu, .badge-offen { background: var(--info-light); color: var(--info); }
.badge-in_bearbeitung, .badge-nachfragen { background: var(--warning-light); color: var(--warning); }
.badge-erledigt, .badge-abgeschlossen, .badge-bezahlt, .badge-aktiv { background: var(--success-light); color: var(--success); }
.badge-storniert, .badge-inaktiv, .badge-ueberfaellig, .badge-abgelehnt { background: var(--danger-light); color: var(--danger); }
.badge-entwurf { background: #f1f5f9; color: #64748b; }
.badge-gesendet { background: var(--warning-light); color: var(--warning); }
/* Gastronomie-Statuse */
.badge-anfrage { background: var(--info-light); color: var(--info); }
.badge-bestätigt { background: var(--success-light); color: var(--success); }
.badge-erschienen { background: var(--success-light); color: var(--success); }
.badge-abgesagt, .badge-no_show { background: var(--danger-light); color: var(--danger); }
.badge-in_zubereitung { background: var(--warning-light); color: var(--warning); }
.badge-serviert { background: var(--primary-light); color: var(--primary); }

/* Aktions-Panel */
.action-panel {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 20px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  align-items: center;
}

.action-panel .action-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.btn-action-order { background: #16a34a; color: white; border: none; }
.btn-action-order:hover { background: #15803d; }
.btn-action-followup { background: #d97706; color: white; border: none; }
.btn-action-followup:hover { background: #b45309; }
.btn-action-reject { background: #dc2626; color: white; border: none; }
.btn-action-reject:hover { background: #b91c1c; }
.btn-action-done { background: #0891b2; color: white; border: none; }
.btn-action-done:hover { background: #0e7490; }

.prio-hoch { color: var(--danger); font-weight: 600; }
.prio-normal { color: var(--text-muted); }
.prio-niedrig { color: var(--success); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ============ FORMS ============ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-section {
  margin-bottom: 24px;
}

.form-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

/* ============ ALERTS ============ */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #bbf7d0; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fde68a; }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-sm .modal { max-width: 420px; }
.modal-lg .modal { max-width: 900px; }

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

.modal-header h3 { font-size: 18px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ============ TOAST ============ */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  font-weight: 500;
  min-width: 250px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--primary); color: white; }
.toast-warning { background: var(--warning); color: white; }

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

/* ============ DETAIL VIEW ============ */
.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 24px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.detail-avatar {
  width: 56px;
  height: 56px;
  background: var(--primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.detail-title { font-size: 20px; font-weight: 700; }
.detail-meta { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.detail-field label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 4px;
}

.detail-field span {
  font-size: 14px;
  color: var(--text);
}

/* ============ TABS ============ */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  background: var(--surface);
  padding: 0 32px;
}

.tab {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ============ INVOICE ITEMS ============ */
.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.invoice-items-table th,
.invoice-items-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.invoice-items-table th {
  background: var(--bg);
  font-weight: 600;
  text-align: left;
}

.invoice-items-table input {
  border: none;
  outline: none;
  width: 100%;
  font-size: 13px;
  background: transparent;
}

.invoice-total {
  text-align: right;
  margin-top: 8px;
}

.invoice-total table {
  display: inline-table;
  width: auto;
  min-width: 280px;
}

.invoice-total td { padding: 4px 12px; font-size: 14px; }
.invoice-total .total-row { font-weight: 700; font-size: 16px; border-top: 2px solid var(--border); }

/* ============ DASHBOARD ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ============ EXPORT PAGE ============ */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.export-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.export-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }

.export-icon {
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.export-icon svg {
  width: 24px;
  height: 24px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.export-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.export-card p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ============ UTILS ============ */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.currency { font-weight: 600; }
.currency::before { content: ''; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 16px;
  background: none;
  border: none;
  padding: 0;
}

.back-btn:hover { color: var(--primary); }
.back-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ============ DATA PAGE ============ */
.data-tabs {
  display: flex;
  gap: 4px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* ============ MOBILE TOPBAR ============ */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s;
}

.mobile-topbar-logo {
  display: flex;
  flex-direction: column;
}

.mobile-topbar-logo .logo-text {
  font-size: 16px;
  font-weight: 800;
  color: white;
  letter-spacing: 3px;
}

.mobile-topbar-logo .logo-sub {
  font-size: 9px;
  letter-spacing: 4px;
  color: rgba(255,255,255,0.4);
  display: block;
  margin-top: -2px;
}

/* ============ SIDEBAR OVERLAY ============ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .mobile-topbar { display: flex; }
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; transition: opacity 0.3s; }

  .sidebar {
    transform: translateX(-100%);
    z-index: 160;
    top: 0;
  }

  #app.sidebar-open .sidebar { transform: translateX(0); }
  #app.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }

  .main-content {
    margin-left: 0;
    padding-top: 56px;
  }

  .app-footer {
    left: 0;
  }

  .page-header {
    padding: 14px 16px 12px;
    flex-wrap: wrap;
    gap: 10px;
    top: 56px;
  }

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

  .page-body {
    padding: 16px;
  }

  .detail-header {
    padding: 16px;
    flex-wrap: wrap;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-tabs {
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card .stat-value { font-size: 22px; }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .export-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    gap: 8px;
  }

  .search-box {
    min-width: 0;
    max-width: 100%;
    flex: 1;
  }

  .filter-select {
    flex: 1;
    min-width: 0;
  }

  .modal {
    max-height: 100dvh;
    border-radius: 0;
    height: 100dvh;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-sm .modal,
  .modal-lg .modal {
    max-width: 100%;
    height: 100dvh;
    border-radius: 0;
  }

  .action-panel {
    padding: 12px;
    gap: 8px;
  }

  .btn { padding: 9px 14px; }
  .btn-sm { padding: 7px 10px; }

  .page-header .btn { font-size: 13px; }

  #toast-container {
    left: 16px;
    right: 16px;
    top: 64px;
  }

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

  .main-content { padding-bottom: 56px; }

  .invoice-items-table { font-size: 12px; }
  .invoice-items-table th, .invoice-items-table td { padding: 6px 8px; }

  /* Login card padding */
  .login-card { padding: 28px 20px; }

  /* Detail header action buttons wrap */
  .detail-header .flex { flex-wrap: wrap; gap: 8px; }

  /* Settings card full width */
  #data-body .card { max-width: 100% !important; }

  /* Email chat: column layout on mobile */
  .chat-container { flex-direction: column !important; height: auto !important; min-height: 0 !important; }
  .chat-messages-wrap { min-height: 300px; }
  .chat-sidebar { width: 100% !important; flex-shrink: unset !important; }

  /* Fallback: target chat container by its inline style (in case class not applied) */
  .page-body > div[style*="height:calc(100vh"] {
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .page-body > div[style*="height:calc(100vh"] > div[style*="width:240px"] {
    width: 100% !important;
  }

  /* Invoice detail: header buttons column on narrow screens */
  .detail-header > div:last-child { flex-wrap: wrap; gap: 8px; align-items: flex-start; }

  /* Invoice detail: make items table card scrollable */
  .page-body .card { overflow: visible; }
  .page-body .card > .card-body { overflow-x: auto; }

  /* Make sure detail-header flex children wrap and don't overflow */
  .detail-header { gap: 12px; }
  .detail-header > div[style*="flex:1"] { min-width: 0; }
  .detail-header > div:last-child { flex-wrap: wrap; }

  /* Email ticket reply area full-width on mobile */
  #reply-text { width: 100% !important; }

  /* Invoice detail: hide Einheit column to save space */
  .invoice-items-table thead th:nth-child(3),
  .invoice-items-table tbody td:nth-child(3) { display: none; }

  /* Invoice total: left-align on mobile instead of right */
  .invoice-total { text-align: left; }
  .invoice-total table { width: 100%; min-width: 0; display: table; }

  /* --- card-body + invoice-total: scrollable on overflow --- */
  .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .invoice-total { overflow-x: auto; }
  .invoice-total table { min-width: 0; }

  /* --- Override inline-width inputs (settings port fields etc.) --- */
  .form-group input[style*="width"] { width: 100% !important; }

  /* --- Customers table: show only Kundennr, Name/Firma, Status --- */
  #customers-table table thead th:nth-child(3),
  #customers-table table tbody td:nth-child(3),
  #customers-table table thead th:nth-child(4),
  #customers-table table tbody td:nth-child(4),
  #customers-table table thead th:nth-child(5),
  #customers-table table tbody td:nth-child(5),
  #customers-table table thead th:nth-child(7),
  #customers-table table tbody td:nth-child(7) { display: none; }

  /* --- Requests table: show only Nr, Betreff, Status --- */
  #requests-table table thead th:nth-child(3),
  #requests-table table tbody td:nth-child(3),
  #requests-table table thead th:nth-child(4),
  #requests-table table tbody td:nth-child(4),
  #requests-table table thead th:nth-child(6),
  #requests-table table tbody td:nth-child(6),
  #requests-table table thead th:nth-child(7),
  #requests-table table tbody td:nth-child(7),
  #requests-table table thead th:nth-child(8),
  #requests-table table tbody td:nth-child(8) { display: none; }

  /* --- Orders table: show only Nr, Titel, Betrag, Status --- */
  #orders-table table thead th:nth-child(3),
  #orders-table table tbody td:nth-child(3),
  #orders-table table thead th:nth-child(4),
  #orders-table table tbody td:nth-child(4),
  #orders-table table thead th:nth-child(7),
  #orders-table table tbody td:nth-child(7),
  #orders-table table thead th:nth-child(8),
  #orders-table table tbody td:nth-child(8) { display: none; }

  /* --- Invoices table: show only Nr, Titel, Betrag, Status --- */
  #invoices-table table thead th:nth-child(3),
  #invoices-table table tbody td:nth-child(3),
  #invoices-table table thead th:nth-child(4),
  #invoices-table table tbody td:nth-child(4),
  #invoices-table table thead th:nth-child(5),
  #invoices-table table tbody td:nth-child(5),
  #invoices-table table thead th:nth-child(8),
  #invoices-table table tbody td:nth-child(8) { display: none; }

  /* --- Email tickets table: show only Ticket, Absender, Status --- */
  #email-list-body table thead th:nth-child(3),
  #email-list-body table tbody td:nth-child(3),
  #email-list-body table thead th:nth-child(5),
  #email-list-body table tbody td:nth-child(5),
  #email-list-body table thead th:nth-child(6),
  #email-list-body table tbody td:nth-child(6) { display: none; }

  /* --- Users table: show only Name, Rolle, Status, Aktionen --- */
  #data-body .table-container table thead th:nth-child(2),
  #data-body .table-container table tbody td:nth-child(2),
  #data-body .table-container table thead th:nth-child(3),
  #data-body .table-container table tbody td:nth-child(3) { display: none; }
}
