/* ============================================================
   shell.css — Strukturelle Basis des Sales-App
   ------------------------------------------------------------
   Layout, App-Chrome (Sidebar/Header/Views), Modal-Box,
   Toasts, Button-/Form-Basis + Keyframes.
   Lädt VOR styles-refined.css (Token-/Visual-Layer).
   ============================================================ */

:root {
  /* Struktur-Tokens (Farben kommen aus styles-refined.css) */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-3xl: 32px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-xl: 0 24px 64px rgba(15, 23, 42, .18);

  --duration-fast: 150ms;
  --duration-normal: 280ms;
  --ease-out-expo: cubic-bezier(.16, 1, .3, 1);

  /* Fallbacks, falls refined nicht geladen ist */
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eef0f3;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --border: #e2e8f0;
  --border-light: #eef2f6;
  --brand: #3b82f6;
  --brand-accent: #10b981;
  --card-bg: var(--surface);

  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--surface-2);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App-Grid ───────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────── */
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--space-6) var(--space-4);
  gap: var(--space-2);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2) var(--space-6);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: var(--space-3);
}
.app-brand-logo {
  width: 42px; height: 42px;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--brand), var(--brand-accent));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
  box-shadow: var(--shadow-sm);
}
.app-brand-text { display: flex; flex-direction: column; min-width: 0; }
.app-brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-brand-tag { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-3);
  padding: var(--space-4) var(--space-2) var(--space-2);
}

.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
  user-select: none;
}
.nav-item .nav-ico { font-size: 17px; width: 22px; text-align: center; }
.nav-badge { margin-left: auto; display: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.nav-badge.is-on { display: inline-block; }
.nav-item.active .nav-badge { background: var(--brand); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
.nav-item.active .nav-ico { filter: none; }

.nav-spacer { flex: 1; }

/* ── Main + Views ───────────────────────────────────────── */
.app-main { min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 50;
}
.app-topbar .header-actions { display: flex; align-items: center; gap: var(--space-3); }

/* Sprach-Umschalter */
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.lang-btn {
  background: var(--surface); border: 0; padding: 6px 10px;
  font-size: 12px; font-weight: 700; color: var(--text-3); cursor: pointer;
  font-family: inherit; transition: background var(--duration-fast), color var(--duration-fast);
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn:hover { background: var(--surface-2); color: var(--text); }
.lang-btn.active { background: var(--brand); color: #fff; }

.app-content { padding: var(--space-6); flex: 1; }

.view { animation: fadeInUp .25s ease both; }
.hidden { display: none !important; }

.sidebar-toggle { display: none; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600; font-size: 14px; font-family: inherit;
  cursor: pointer;
  transition: transform var(--duration-fast), box-shadow var(--duration-fast), background var(--duration-fast);
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary { background: var(--brand); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Forms ──────────────────────────────────────────────── */
.form-input,
input[type="text"], input[type="search"], input[type="number"],
input[type="email"], input[type="date"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px; font-family: inherit;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.form-input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0);
  z-index: 200;
  justify-content: center; align-items: flex-start;
  padding: 48px 20px; overflow-y: auto;
  transition: background var(--duration-normal) ease;
}
.modal-overlay.active { display: flex; background: rgba(15, 23, 42, .48); backdrop-filter: blur(2px); }
.modal {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  padding: var(--space-3xl);
  width: 100%; max-width: 740px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-light);
  animation: modalIn .35s var(--ease-out-expo);
}
.modal.wide { max-width: 920px; }
.modal-title {
  font-size: 20px; font-weight: 700; color: var(--text);
  margin: 0 0 22px; display: flex; align-items: center; gap: 12px;
  letter-spacing: -.015em; position: relative;
}
.modal-close {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-3);
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); transition: background var(--duration-fast), color var(--duration-fast); padding: 0;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; }

/* ── Toasts ─────────────────────────────────────────────── */
.toast-stack {
  position: fixed; bottom: 24px; right: 24px; z-index: 400;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px;
}
.toast-item {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius);
  background: #1e293b; color: #fff;
  box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 500;
  animation: toastIn .3s var(--ease-out-expo);
}
.toast-item.success { background: linear-gradient(135deg, #059669, #10b981); }
.toast-item.error { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast-item.warning { background: linear-gradient(135deg, #d97706, #f59e0b); }
.toast-item.info { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.toast-item.removing { animation: toastOut .2s ease forwards; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: rgba(255, 255, 255, .8); font-size: 18px; cursor: pointer; line-height: 1; padding: 0 2px; }
.toast-undo { background: rgba(255, 255, 255, .15); border: 1px solid rgba(255, 255, 255, .3); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 700; cursor: pointer; }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: rgba(255, 255, 255, .55); transform-origin: left; animation: toastBar linear forwards; }

/* ── Keyframes (compositor-friendly) ────────────────────── */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(24px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes modalOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(30px); } }
@keyframes toastBar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 300;
    width: var(--sidebar-w); transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out-expo);
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 250; }
  .sidebar-toggle { display: inline-flex; }
}

/* Mobile: kompakte Topbar — Funktionen bleiben erreichbar (Sprache in Einstellungen,
   Online-Status als Punkt) statt 3 Zeilen Controls. */
@media (max-width: 640px) {
  .app-topbar { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
  .app-topbar .header-actions { gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; }
  .topbar-title { font-size: 15px; }
  /* Sprache ist in Einstellungen → Sprache; auf Mobil aus der Topbar nehmen */
  .app-topbar .lang-switch { display: none; }
  /* Online-Pill nur als Punkt (Klick öffnet weiterhin den Status) */
  .off-pill .off-label { display: none; }
  .off-pill { padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
