/* === Design Tokens === */
[hidden] {
  display: none !important;
}

:root {
  --brand: #10b981;
  --brand-dark: #059669;
  --brand-hover: #0d9467;
  --brand-light: rgba(16, 185, 129, 0.1);
  --brand-text: #065f46;

  --sidebar-bg: #0f172a;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-width: 240px;
  --sidebar-item-hover: rgba(255, 255, 255, 0.06);
  --sidebar-item-active: rgba(16, 185, 129, 0.14);
  --sidebar-text: rgba(255, 255, 255, 0.6);
  --sidebar-text-hover: rgba(255, 255, 255, 0.9);
  --sidebar-text-active: #f0fdf4;
  --sidebar-icon: rgba(255, 255, 255, 0.35);
  --sidebar-icon-active: #10b981;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;

  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --line: #e2e8f0;
  --line-2: #cbd5e1;

  --danger: #ef4444;
  --danger-dark: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.18);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;

  --t: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 220ms cubic-bezier(0.4, 0, 0.2, 1);

  --mobile-header-h: 56px;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-x pan-y;
}

html {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; min-width: 0; }
button, a, input, select, textarea { touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }

/* === Login === */
.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 42%, rgba(14, 165, 233, 0.2), transparent 34%),
    linear-gradient(150deg, #080c14 0%, #0d1422 52%, #060a10 100%);
  color: #eef6ff;
}

.login-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.05) 2px,
    rgba(0, 0, 0, 0.05) 4px
  );
}

.login-bg-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
}

.login-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 82% 80% at 50% 50%, transparent 30%, rgba(5, 10, 18, 0.76) 100%);
}

.login-card {
  width: min(420px, 100%);
  position: relative;
  z-index: 2;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.74);
  border: 1px solid rgba(125, 211, 252, 0.22);
  border-radius: 18px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 28px 90px rgba(0, 0, 0, 0.58),
    0 0 64px rgba(14, 165, 233, 0.16);
  padding: 42px 38px 38px;
  display: grid;
  gap: 20px;
  animation: loginCardIn 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@supports (backdrop-filter: blur(18px)) {
  .login-card {
    backdrop-filter: blur(22px) saturate(1.35);
    -webkit-backdrop-filter: blur(22px) saturate(1.35);
  }
}

@keyframes loginCardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.login-brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-logo-box {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #ffffff;
  background: #0ea5e9;
  box-shadow: 0 0 26px rgba(14, 165, 233, 0.36), 0 0 7px rgba(14, 165, 233, 0.32);
}

.login-logo-box svg {
  width: 26px;
  height: 26px;
}

.login-brand-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.login-brand-404 {
  display: block;
  color: #f8fafc;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.login-brand-sub {
  display: block;
  color: #38bdf8;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.login-brand-tagline {
  color: rgba(203, 213, 225, 0.72);
  font-size: 12px;
}

.login-card h1 {
  color: #f8fafc;
  font-size: 18px;
  text-align: center;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: rgba(203, 213, 225, 0.74);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-form input,
.login-form select {
  width: 100%;
  min-height: 46px;
  padding: 12px 16px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 10px;
  outline: none;
  background: rgba(15, 23, 42, 0.84);
  color: #f8fafc;
  font-size: 16px;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}

.login-form input::placeholder {
  color: rgba(148, 163, 184, 0.62);
}

.login-form input:focus,
.login-form select:focus {
  border-color: #38bdf8;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.login-error {
  padding: 10px 14px;
  border: 1px solid rgba(248, 113, 113, 0.24);
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.18);
  color: #fca5a5;
  font-size: 13px;
  text-align: center;
}

.login-secondary-action {
  border: 0;
  background: transparent;
  color: #7dd3fc;
  font-weight: 800;
  cursor: pointer;
  padding: 2px 0;
  justify-self: center;
}

.login-secondary-action:hover {
  color: #e0f2fe;
}

.account-request-page {
  display: grid;
  gap: 14px;
}

.login-request-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.login-submit {
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #0ea5e9;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(14, 165, 233, 0.28);
  transition: transform var(--t), filter var(--t), box-shadow var(--t);
}

.login-submit:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 12px 38px rgba(14, 165, 233, 0.34);
}

.login-submit:active {
  transform: scale(0.99);
}

.login-submit::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 62%);
}

.login-submit.is-loading {
  pointer-events: none;
}

.login-submit.is-loading .login-submit-text {
  opacity: 0;
}

.login-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--t);
}

.login-submit.is-loading .login-spinner {
  opacity: 1;
}

.login-spinner::after {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: loginSpin 0.75s linear infinite;
}

@keyframes loginSpin {
  to { transform: rotate(360deg); }
}

.login-card.is-shaking {
  animation: loginShake 0.36s ease-out;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-8px); }
  48% { transform: translateX(7px); }
  72% { transform: translateX(-4px); }
}

.login-success-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: inherit;
  background: rgba(15, 23, 42, 0.86);
  color: #f8fafc;
  text-align: center;
}

.login-success-icon {
  width: 54px;
  height: 54px;
  border: 2px solid #10b981;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #34d399;
  background: rgba(16, 185, 129, 0.14);
  box-shadow: 0 0 28px rgba(16, 185, 129, 0.32);
}

.login-success-icon svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
}

.login-success-overlay span {
  color: rgba(203, 213, 225, 0.76);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .login-card,
  .login-card.is-shaking,
  .login-spinner::after {
    animation: none;
  }
}

/* === Layout === */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 200;
  transition: transform var(--t-slow);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--brand);
  border-radius: var(--r-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand-info strong {
  display: block;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-info small {
  display: block;
  color: var(--sidebar-text);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#logout-button {
  margin-top: auto;
}

.nav-user {
  margin: 0 8px 8px;
  background: rgba(255, 255, 255, 0.04);
}

.session-indicator {
  margin: 0 12px 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.12);
  color: rgba(240, 253, 244, 0.95);
  font-size: 12px;
  line-height: 1.35;
}

.session-indicator strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #ffffff;
}

.session-indicator.is-warning {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.16);
  color: rgba(254, 226, 226, 0.95);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 12px;
  height: 40px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), color var(--t);
  text-align: left;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: var(--sidebar-icon);
  transition: color var(--t);
}

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

.nav-item:hover svg { color: rgba(255, 255, 255, 0.6); }

.nav-item.is-active {
  background: var(--sidebar-item-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav-item.is-active svg { color: var(--sidebar-icon-active); }

.nav-item-child {
  margin-left: 18px;
  width: calc(100% - 18px);
}

/* === Mobile Header === */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  height: var(--mobile-header-h);
  padding: 0 16px;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  border-bottom: 1px solid var(--sidebar-border);
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background var(--t);
  padding: 0;
  flex-shrink: 0;
}

.menu-toggle svg { width: 20px; height: 20px; }
.menu-toggle:hover { background: rgba(255, 255, 255, 0.14); }

.mobile-title {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.mobile-session-indicator {
  margin-left: auto;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.15);
  color: #ecfdf5;
  font-size: 11px;
  line-height: 1;
}

.mobile-session-indicator strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.mobile-session-indicator.is-warning {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.2);
  color: #fee2e2;
}

/* === Sidebar Overlay === */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.is-visible { display: block; }

/* === Workspace === */
.workspace {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 36px 40px;
  min-width: 0;
}

.session-floating-indicator {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 500;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(16, 185, 129, 0.55);
  background: rgba(15, 23, 42, 0.92);
  color: #ecfdf5;
  font-size: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(2px);
}

.session-floating-indicator strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  color: #ffffff;
}

.session-floating-indicator.is-warning {
  border-color: rgba(239, 68, 68, 0.65);
  background: rgba(127, 29, 29, 0.92);
  color: #fee2e2;
}

/* === Screens === */
.screen { display: none; }

.screen.is-active {
  display: grid;
  gap: 24px;
  animation: screenIn var(--t-slow);
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === Page Header === */
.page-header { max-width: 680px; }

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-dark);
  margin: 0 0 8px;
}

h1 {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 10px;
}

h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
}

h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.page-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.65;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.card-header h2 { margin: 0; }
.card-header .eyebrow { margin-bottom: 4px; }

/* === Choice Grid === */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.dashboard-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 20px 20px;
}

.dashboard-kpis {
  padding: 0 20px 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.kpi-item {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 12px;
  display: grid;
  gap: 6px;
}

.kpi-item span {
  color: var(--muted);
  font-size: 12px;
}

.kpi-item strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.choice-card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}

.choice-card:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.choice-card.is-active {
  border-color: var(--brand);
  background: #f0fdf4;
  box-shadow: 0 0 0 4px var(--brand-light), var(--shadow);
}

.choice-card.is-active .choice-icon {
  background: var(--brand);
  color: #fff;
}

.choice-card.is-active .btn {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* Anlagen-Auswahl: keine feste grüne Aktiv-Markierung, nur Hover */
[data-screen="create"] .choice-card.is-active {
  border-color: var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

[data-screen="create"] .choice-card.is-active .choice-icon {
  background: var(--brand-light);
  color: var(--brand);
}

[data-screen="create"] .choice-card.is-active .btn {
  background: var(--surface-3);
  color: var(--ink-2);
  border-color: var(--line);
}

[data-screen="create"] .choice-card:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.choice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--brand-light);
  border-radius: var(--r-sm);
  color: var(--brand);
}

.choice-icon svg { width: 22px; height: 22px; }

.choice-kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-dark);
  margin-top: 4px;
}

.choice-card h2 { font-size: 17px; }

.choice-card p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  flex: 1;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t), transform var(--t), color var(--t), border-color var(--t);
  white-space: nowrap;
  text-decoration: none;
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); box-shadow: none; }

.btn-secondary {
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: var(--line);
  border-color: var(--line-2);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.btn-ghost:hover { background: var(--surface-3); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-download {
  background: var(--brand-light);
  color: var(--brand-text);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.btn-download:hover {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-lg {
  height: 46px;
  padding: 0 22px;
  font-size: 15px;
}

.btn-icon-only {
  width: 36px;
  height: 36px;
  padding: 0;
}

#add-line-item {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  gap: 5px;
}

#add-line-item svg {
  width: 13px;
  height: 13px;
}

/* === Form === */
.document-form {
  padding: 24px;
  display: grid;
  gap: 28px;
}

.document-info-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.document-info-panel legend {
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 14px;
}

.document-info-panel legend svg {
  color: var(--brand);
}

.customer-document-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.customer-document-tools .btn {
  height: 40px;
  white-space: nowrap;
}

.compact-grid {
  gap: 12px 14px;
}

.position-form {
  padding: 24px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 20px;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
  width: 100%;
}

legend svg { width: 14px; height: 14px; }

.fieldset-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.wide-field { grid-column: 1 / -1; }
.field-full { grid-column: 1 / -1; }

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.field-label {
  align-items: baseline;
  display: inline-flex;
  gap: 4px;
  min-height: 20px;
}

.field-optional {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted-2);
}

input, select, textarea {
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  width: 100%;
  transition: border-color var(--t), box-shadow var(--t);
}

textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
}

input:hover, select:hover, textarea:hover { border-color: var(--muted-2); }

input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

input::placeholder { color: var(--muted-2); }

.input-readonly {
  background: var(--surface-3);
  color: var(--muted);
  cursor: default;
}

.input-readonly:hover { border-color: var(--line-2); }
.input-readonly:focus { border-color: var(--line-2); box-shadow: none; }

/* === Line Items === */
.line-items { display: grid; gap: 12px; }

.line-item-table-head {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) 96px 128px 104px 128px 42px;
  gap: 12px;
  margin: 0 0 8px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.line-item-picker {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
}

.line-item-picker-field {
  max-width: 360px;
}

.line-item-picker-actions {
  display: flex;
  gap: 10px;
}

.line-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px;
  display: grid;
  gap: 10px 12px;
  grid-template-columns: minmax(240px, 1.5fr) 96px 128px 104px 128px 42px;
  align-items: end;
  transition: border-color var(--t), box-shadow var(--t);
}

.line-item:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow-xs);
}

.line-item label {
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.line-item input,
.line-item select {
  height: 38px;
  font-size: 14px;
}

.line-item .wide-field {
  grid-column: 1 / -2;
}

.line-item-total input {
  text-align: right;
  font-weight: 700;
}

.remove-line-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--danger-border);
  border-radius: var(--r-sm);
  background: var(--danger-bg);
  color: var(--danger);
  cursor: pointer;
  padding: 0;
  transition: background var(--t), color var(--t), border-color var(--t);
  flex-shrink: 0;
}

.remove-line-button svg {
  width: 17px;
  height: 17px;
}

.remove-line-button:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.offer-summary {
  margin: 0 24px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(255, 255, 255, 0.96));
  border: 1px solid rgba(16, 185, 129, 0.18);
  border-radius: var(--r);
}

.offer-summary-header {
  margin-bottom: 14px;
}

.offer-summary-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.offer-summary-grid {
  display: grid;
  gap: 10px;
}

.summary-breakdown {
  display: grid;
  gap: 8px;
}

.summary-breakdown-empty {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  padding: 4px 0 8px;
}

.summary-breakdown-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 13px;
}

.summary-breakdown-row strong {
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--ink-2);
  font-size: 14px;
}

.summary-row strong {
  color: var(--ink);
  font-size: 15px;
}

.summary-row-total {
  border-bottom: 0;
  padding-bottom: 0;
  margin-top: 4px;
}

.summary-row-total span,
.summary-row-total strong {
  color: var(--brand-text);
  font-size: 18px;
  font-weight: 700;
}

/* === Form Actions === */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 24px;
}

.position-form .form-actions { padding: 0; }

/* === Tabs === */
.tabs {
  display: flex;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 2px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color var(--t), border-color var(--t);
}

.tab-button svg { width: 15px; height: 15px; }
.tab-button.is-active { color: var(--ink); border-bottom-color: var(--brand); }
.tab-button:hover { color: var(--ink-2); }

.settings-panel { display: none; }
.settings-panel.is-active { display: block; }

.company-logo-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px auto;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}

.company-logo-copy h3 {
  margin: 4px 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.company-logo-copy p:last-child,
.company-logo-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.company-logo-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 160px;
  height: 72px;
  padding: 8px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.company-logo-preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.company-logo-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.company-logo-upload {
  cursor: pointer;
}

.company-logo-upload.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.company-logo-hint {
  grid-column: 1 / -1;
}

.document-design-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.toggle-row {
  align-items: center;
  display: flex;
  gap: 10px;
  min-height: 40px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.document-design-option {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding: 12px;
}

.document-design-option small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-top: 3px;
}

.yes-no-toggle {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: inline-flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
}

.yes-no-toggle label {
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  min-width: 58px;
  padding: 8px 12px;
  place-content: center;
}

.yes-no-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.yes-no-toggle label:has(input:checked) {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.document-design-preview {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: #fff;
}

.document-design-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
}

.document-design-preview-head span {
  color: var(--document-preview-accent, var(--brand));
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-design-preview-line {
  height: 3px;
  border-radius: 999px;
  background: var(--document-preview-accent, var(--brand));
}

.document-design-preview p,
.document-design-preview small {
  margin: 0;
  color: var(--muted);
}

.document-design-preview-table {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--document-preview-accent, var(--brand));
  color: #fff;
  font-weight: 700;
}

.company-code-card {
  margin: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  display: grid;
  gap: 10px;
}

.company-code-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.company-code-head h3 {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 700;
}

.company-code-body {
  display: grid;
  gap: 6px;
}

.company-code-value {
  display: inline-flex;
  width: fit-content;
  min-height: 34px;
  align-items: center;
  padding: 0 10px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-sm);
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--ink);
}

.company-code-expire {
  font-size: 12px;
  color: var(--muted);
}

.company-member-entry {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}

.settings-panel[data-company-panel="members"] .position-list {
  padding: 0;
}

#company-members-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#admin-company-list,
#admin-company-members-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.company-member-main {
  min-width: 0;
}

.company-member-name {
  margin: 0;
  font-size: 15px;
  line-height: 1.1;
  color: var(--ink);
  font-weight: 700;
}

.company-member-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.company-member-role {
  margin-left: auto;
  flex-shrink: 0;
  min-height: 24px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 700;
}

.company-member-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-sm {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

@media (max-width: 980px) {
  .document-info-layout {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .line-item-table-head {
    display: none;
  }

  .line-item {
    grid-template-columns: minmax(0, 1fr) minmax(92px, 0.35fr);
  }

  .line-item-product,
  .line-item .wide-field {
    grid-column: 1 / -1;
  }

  .company-member-entry {
    padding: 8px 10px;
  }

  .company-member-name {
    font-size: 14px;
  }

  .company-member-meta {
    font-size: 11px;
  }

  .company-member-role {
    font-size: 10px;
    min-height: 22px;
    padding: 0 7px;
  }
}

/* === Document List === */
.document-list {
  list-style: none;
  margin: 0;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.document-entry {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  transition: border-color var(--t), box-shadow var(--t);
}

.document-entry:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow-xs);
}

.document-entry-body {
  cursor: pointer;
}

.document-entry.is-alert {
  border-color: rgba(239, 68, 68, 0.5);
  background: #fff5f5;
}

.document-entry-body {
  flex: 1;
  min-width: 0;
}

.document-entry-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 5px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.document-entry-number {
  display: inline-block;
  line-height: 1.2;
}

.document-status {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
}

.document-status.is-active {
  color: #065f46;
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.document-status.is-storno,
.document-status.is-corrected {
  color: #991b1b;
  background: #fee2e2;
  border-color: #fca5a5;
}

.document-status.is-mail-sent {
  color: #065f46;
  background: #ecfdf5;
  border-color: #6ee7b7;
  gap: 5px;
  margin-left: 2px;
}

.document-status.is-mail-sent svg {
  width: 12px;
  height: 12px;
}

.document-mail-button.is-sent {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #065f46;
}

.document-mail-button.is-sent svg {
  color: #059669;
}

.document-entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.document-entry-meta .sep {
  opacity: 0.55;
  font-size: 11px;
  margin: 0 1px;
}

.document-relation {
  font-weight: 600;
  color: #1d4ed8;
}

.document-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.position-entry-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 4px 8px;
  margin: 2px 0 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
}

.position-entry-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.login-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.position-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: border-color var(--t), background var(--t), color var(--t);
}

.position-edit:hover {
  background: var(--surface-3);
  border-color: var(--line-2);
}

.position-move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color var(--t), background var(--t), color var(--t);
}

.position-move:hover {
  background: var(--surface-3);
  border-color: var(--line-2);
}

/* keep legacy selector working */
.download-document {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand-light);
  color: var(--brand-text);
  border: 1px solid rgba(16, 185, 129, 0.2);
  transition: background var(--t), color var(--t), border-color var(--t);
}

.download-document:hover {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.delete-document {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  transition: background var(--t), color var(--t), border-color var(--t);
}

.delete-document:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* === Position List === */
.position-list { padding: 0 24px 24px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

#position-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

#tag-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

#users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

#customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.admin-report-wrap {
  padding: 0 24px 24px;
}

.admin-report-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.admin-report-table th,
.admin-report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.95rem;
}

.admin-report-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.admin-report-table tr:last-child td {
  border-bottom: none;
}

.position-entry {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  transition: border-color var(--t);
}

.position-entry:hover { border-color: var(--line-2); }

#customer-list .position-entry {
  flex-direction: column;
  align-items: flex-start;
}

#customer-list .position-content {
  flex: 0 1 auto;
  min-width: 0;
  text-align: left;
}

#customer-list .position-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-left: 0;
}

#customer-form .form-actions,
#customer-edit-modal-form .form-actions,
#document-customer-modal-form .form-actions {
  justify-content: flex-start;
}

.position-entry-body { flex: 1; min-width: 0; }

.position-entry-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 2px;
}

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

.text-warning {
  color: #b45309;
}

.account-request-entry .position-entry-controls {
  align-items: center;
}

.position-entry-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.delete-position {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
  background: transparent;
  color: var(--muted-2);
  border: 1px solid transparent;
  transition: background var(--t), color var(--t), border-color var(--t);
  flex-shrink: 0;
  padding: 0;
}

.delete-position:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
}

.empty-state[hidden] { display: none; }

.empty-state svg {
  width: 40px;
  height: 40px;
  color: var(--muted-2);
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  color: var(--muted);
}

/* === Toast Notifications === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  min-width: 280px;
  max-width: 380px;
  padding: 14px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  pointer-events: all;
  animation: toastIn var(--t-slow) cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.toast.is-leaving {
  animation: toastOut var(--t-slow) cubic-bezier(0.4, 0, 1, 1) both;
}

.toast-message {
  flex: 1;
  min-width: 0;
}

.toast-icon {
  display: inline-flex;
  flex-shrink: 0;
}

.toast-icon svg { width: 18px; height: 18px; }

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}

.toast-close:hover,
.toast-close:focus-visible {
  background: rgba(148, 163, 184, 0.24);
  color: #ffffff;
  transform: scale(1.04);
}

.toast-success .toast-icon svg { color: var(--brand); }
.toast-error .toast-icon svg { color: #f87171; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* === Preview Modal === */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}


.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.preview-modal-panel {
  position: relative;
  z-index: 1;
  width: min(900px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

.logout-progress-panel {
  width: min(460px, calc(100vw - 40px));
  padding: 20px 22px;
}

.logout-progress-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logout-progress-content h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.logout-progress-content p {
  margin: 0;
  color: var(--muted);
}

.logout-spinner {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 3px solid rgba(16, 185, 129, 0.25);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.preview-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.preview-close:hover {
  color: var(--ink);
  border-color: var(--line-2);
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 22px 0;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 24px 16px;
  border-bottom: 1px solid var(--line);
}

.preview-convert-inline {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: end;
}

.preview-inline-dialog {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  padding: 12px;
  box-shadow: var(--shadow-xs);
  display: grid;
  gap: 10px;
}

.preview-inline-dialog-head {
  font-size: 12px;
  font-weight: 800;
  color: var(--brand-text);
  text-transform: uppercase;
}

.preview-inline-dialog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-inline-dialog-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}

.preview-inline-dialog-grid input,
.preview-inline-dialog-grid select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--ink);
}

.preview-inline-dialog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-inline-items {
  display: grid;
  gap: 8px;
}

.preview-inline-items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-inline-items-list {
  display: grid;
  gap: 8px;
}

.preview-inline-item-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 1fr) 96px 96px 96px 38px;
  gap: 8px;
  align-items: center;
}

.preview-inline-item-row input[type="text"],
.preview-inline-item-row input[type="number"],
.preview-inline-item-row select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--ink);
}

.preview-inline-item-row .btn-icon-only {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
}

.document-entry.is-completed {
  opacity: 0.72;
}

.preview-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink-2);
}

.preview-section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}

.preview-row {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px;
}

.preview-row strong {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.preview-item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px;
}

.preview-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
  color: var(--ink);
}

.preview-item-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.preview-summary {
  display: grid;
  gap: 8px;
}

.preview-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--ink-2);
}

.preview-summary-row strong {
  color: var(--ink);
}

/* === Real Mobile Responsive === */
@media (max-width: 768px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    width: min(86vw, 320px);
    padding-top: env(safe-area-inset-top);
  }

  .sidebar.is-open { transform: translateX(0); }

  .mobile-header {
    display: flex;
    height: calc(var(--mobile-header-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }

  .mobile-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-session-indicator {
    flex-shrink: 0;
  }

  .workspace {
    margin-left: 0;
    padding:
      calc(var(--mobile-header-h) + env(safe-area-inset-top) + 16px)
      max(12px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .session-floating-indicator {
    display: none;
  }

  .screen.is-active {
    gap: 16px;
  }

  .page-header {
    max-width: none;
  }

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

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

  .dashboard-actions {
    padding: 0 16px 16px;
  }

  .dashboard-actions .btn {
    flex: 1 1 100%;
  }

  .card {
    border-radius: 14px;
  }

  .card-header {
    padding: 16px;
  }

  .choice-card {
    padding: 16px;
  }

  .btn,
  .download-document,
  .delete-document,
  .position-edit {
    min-height: 42px;
    height: auto;
    white-space: normal;
    line-height: 1.2;
    padding: 10px 12px;
  }

  .btn-icon-only,
  .position-move,
  .delete-position {
    width: 42px;
    min-height: 42px;
    padding: 0;
  }

  .customer-document-tools {
    grid-template-columns: 1fr;
  }

  .customer-document-tools .btn {
    width: 100%;
    justify-content: center;
  }

  .company-logo-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .company-logo-preview {
    width: 100%;
    max-width: 220px;
  }

  .company-logo-actions {
    justify-content: stretch;
  }

  .company-logo-actions .btn,
  .company-logo-upload {
    width: 100%;
    justify-content: center;
  }

  .document-design-grid {
    grid-template-columns: 1fr;
  }

  .line-item-picker-actions {
    flex-direction: column;
  }

  .offer-summary {
    margin: 0;
  }

  .line-item {
    grid-template-columns: 1fr;
  }

  .line-item .wide-field,
  .line-item-product {
    grid-column: 1 / -1;
  }

  .remove-line-button {
    width: 100%;
  }

  h1 { font-size: 26px; }

  h2 { font-size: 17px; }

  .form-actions {
    flex-direction: column;
    padding: 0 16px 16px;
  }

  .form-actions .btn { width: 100%; justify-content: center; }

  .document-entry { flex-direction: column; align-items: flex-start; }

  .document-entry-meta {
    gap: 6px;
  }

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

  .document-actions .btn,
  .document-actions .download-document,
  .document-actions .delete-document {
    flex: 1 1 100%;
    justify-content: center;
  }

  .position-entry {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .position-entry-desc {
    white-space: normal;
  }

  .position-entry-controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-left: 0;
  }

  .position-entry-controls .position-edit,
  .position-entry-controls .position-delete,
  .position-entry-controls .btn {
    flex: 1 1 auto;
  }

  .position-entry-price {
    white-space: normal;
  }

  .card-header { flex-direction: column; align-items: flex-start; }

  .document-form, .position-form { padding: 16px; }

  .position-list { padding: 12px 16px 20px; }
  .admin-report-wrap { padding: 12px 16px 20px; }

  .document-list { padding: 12px; }

  .tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 6px 10px;
    overflow: visible;
    padding: 10px 16px;
    scroll-snap-type: none;
  }

  .tab-button {
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    height: auto;
    padding: 8px 4px;
    margin-bottom: 0;
    white-space: normal;
    line-height: 1.15;
    text-align: center;
    scroll-snap-align: none;
  }

  .tabs-admin {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    overflow: visible;
    padding: 10px 16px;
  }

  .tabs-admin .tab-button {
    justify-content: center;
    width: 100%;
    min-height: 42px;
    padding: 8px 4px;
    margin-bottom: 0;
    border-bottom-width: 2px;
    white-space: normal;
    line-height: 1.15;
    text-align: center;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .toast-container { left: 16px; right: 16px; bottom: 16px; }
  .toast { min-width: unset; }

  .preview-modal {
    align-items: stretch;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .preview-modal-panel {
    width: 100%;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 14px;
  }

  .preview-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface);
    padding: 14px 16px;
  }

  .preview-meta,
  .preview-actions,
  .preview-section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .preview-actions .btn,
  .preview-actions .download-document,
  .preview-actions .delete-document {
    flex: 1 1 100%;
  }

  .preview-pill {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

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

  .preview-item-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-inline-dialog-grid {
    grid-template-columns: 1fr;
  }

  .preview-convert-inline {
    grid-template-columns: 1fr;
  }

  .preview-inline-dialog-actions .btn {
    flex: 1 1 100%;
  }

  .preview-inline-item-row {
    grid-template-columns: 1fr;
  }
}
