/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f11;
  --surface: #18181c;
  --surface2: #222228;
  --surface3: #2a2a32;
  --accent: #e8a45a;
  --accent-dim: rgba(232,164,90,0.15);
  --text: #f0efe8;
  --muted: #7a7a82;
  --green: #5ac87a;
  --red: #e85a5a;
  --blue: #5a9ee8;
  --purple: #a05ae8;
  --yellow: #e8d45a;
  --radius-card: 16px;
  --radius-btn: 10px;
  --radius-input: 10px;
  --nav-height: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#screen-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ─── Bottom Nav ─────────────────────────────────────────────── */
#bottom-nav {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--surface3);
  padding-bottom: var(--safe-bottom);
  min-height: var(--nav-height);
  position: relative;
  z-index: 50;
}
#bottom-nav.hidden { display: none; }

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  min-height: 44px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }

.nav-sync {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
}
.nav-sync.visible { opacity: 1; animation: spin 1.5s linear infinite; }
.nav-sync svg { width: 16px; height: 16px; }

@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

/* ─── Offline Bar ────────────────────────────────────────────── */
#offline-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #7a4a1a;
  color: #f0c080;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  padding: 8px 16px;
  z-index: 200;
  transition: transform 0.3s;
}
#offline-bar.hidden { display: none; }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius-btn);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  border-left: 3px solid var(--accent);
  animation: toast-in 0.25s ease;
  pointer-events: auto;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Shared Components ──────────────────────────────────────── */
.screen {
  min-height: 100%;
  padding-bottom: 24px;
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(16px, calc(var(--safe-top) + 8px)) 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--surface2);
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  background: var(--surface);
  border: none;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.back-btn svg { width: 20px; height: 20px; }

.screen-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 16px;
  margin: 0 16px 12px;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: var(--radius-btn);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary { background: var(--accent); color: #0f0f11; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

/* Inputs */
.input-group {
  margin-bottom: 16px;
}
.input-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
.input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--muted); }

textarea.input { resize: vertical; min-height: 100px; }

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-neu        { background: rgba(232,164,90,0.2); color: var(--accent); }
.badge-bearbeitung { background: rgba(90,158,232,0.2); color: var(--blue); }
.badge-erstellt   { background: rgba(160,90,232,0.2); color: var(--purple); }
.badge-versendet  { background: rgba(232,212,90,0.2); color: var(--yellow); }
.badge-gewonnen   { background: rgba(90,200,122,0.2); color: var(--green); }
.badge-verloren   { background: rgba(232,90,90,0.2); color: var(--red); }

/* Chip Selects */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.chip {
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--surface3);
  border-radius: 20px;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.chip.selected {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--surface2);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 15px; font-weight: 500; }
.toggle {
  position: relative;
  width: 50px; height: 28px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border-radius: 14px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 22px; height: 22px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent-dim); }
.toggle input:checked + .toggle-slider::after {
  transform: translateX(22px);
  background: var(--accent);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--surface2);
  margin: 16px 0;
}

/* Section Header */
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 20px 16px 8px;
}

/* Loading Spinner */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 16px;
  color: var(--muted);
  font-size: 14px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 16px;
  color: var(--muted);
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-state p  { font-size: 14px; }

/* ─── Login Screen ───────────────────────────────────────────── */
#screen-login {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0;
}

.login-header {
  padding: max(48px, calc(var(--safe-top) + 24px)) 24px 32px;
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px;
  background: var(--accent-dim);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}
.login-header h1 { font-size: 24px; font-weight: 700; }
.login-header p  { color: var(--muted); font-size: 15px; margin-top: 4px; }

.user-list {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.user-card:active { background: var(--surface2); }

.user-avatar {
  width: 46px; height: 46px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.user-info .user-name { font-size: 16px; font-weight: 600; }
.user-info .user-role { font-size: 13px; color: var(--muted); }

/* PIN Screen */
.pin-screen {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.pin-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 8px 0;
}
.pin-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--surface3);
  transition: background 0.15s;
}
.pin-dot.filled { background: var(--accent); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pin-key {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-card);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 22px;
  font-weight: 500;
  height: 68px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.pin-key:active { background: var(--surface3); transform: scale(0.96); }
.pin-key.pin-delete { font-size: 18px; color: var(--muted); }
.pin-key.pin-empty  { pointer-events: none; }
.pin-key .pin-sub   { font-size: 9px; letter-spacing: 0.1em; color: var(--muted); font-weight: 400; }

.pin-error {
  text-align: center;
  color: var(--red);
  font-size: 14px;
  font-weight: 500;
  min-height: 20px;
}

/* ─── Home Screen ────────────────────────────────────────────── */
.home-header {
  padding: max(20px, calc(var(--safe-top) + 12px)) 16px 16px;
}
.home-greeting { font-size: 13px; color: var(--muted); }
.home-name     { font-size: 22px; font-weight: 700; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px 4px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 14px 12px;
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}

.search-bar {
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.search-wrap {
  position: relative;
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--muted);
  pointer-events: none;
}
.search-wrap .input { padding-left: 40px; }

.anfragen-list {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.anfrage-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid transparent;
  overflow: hidden;
  touch-action: manipulation;
}
.anfrage-card:active { background: var(--surface2); }

.anfrage-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.anfrage-top > div:first-child {
  min-width: 0;
  flex: 1;
}
.anfrage-top .badge {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}
.anfrage-name { font-size: 16px; font-weight: 600; }
.anfrage-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.anfrage-meta svg { width: 14px; height: 14px; flex-shrink: 0; }
.anfrage-meta span { display: flex; align-items: center; gap: 4px; }
.anfrage-betreff {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Pull to refresh */
.ptr-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transition: height 0.2s;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}
.ptr-indicator.visible { height: 48px; }

/* ─── Detail Screen ──────────────────────────────────────────── */
.detail-hero {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.detail-avatar {
  width: 56px; height: 56px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.detail-name { font-size: 20px; font-weight: 700; }

.info-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--surface2);
}
.info-row:last-child { border-bottom: none; }
.info-icon {
  width: 36px; height: 36px;
  background: var(--surface2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--muted);
}
.info-icon svg { width: 16px; height: 16px; }
.info-content { flex: 1; min-width: 0; }
.info-key   { font-size: 12px; color: var(--muted); }
.info-val   { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-val a { color: var(--accent); text-decoration: none; }

.action-buttons {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aktivitaet-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface2);
}
.aktivitaet-item:last-child { border-bottom: none; }
.aktivitaet-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.aktivitaet-content { flex: 1; }
.aktivitaet-name    { font-size: 14px; font-weight: 500; }
.aktivitaet-desc    { font-size: 13px; color: var(--muted); }
.aktivitaet-time    { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ─── Aufmaß Screen ──────────────────────────────────────────── */
.form-section {
  margin-bottom: 8px;
}
.form-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 16px 16px 8px;
}

.sticky-submit {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
  z-index: 10;
}

/* ─── Angebot Screen ─────────────────────────────────────────── */
.angebot-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 16px;
}

.pdf-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-card);
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  margin: 0 16px 12px;
  transition: background 0.15s;
}
.pdf-btn:active { background: var(--surface2); }
.pdf-btn svg { width: 22px; height: 22px; color: var(--red); flex-shrink: 0; }
.pdf-btn span { flex: 1; }

.preis-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface2);
}
.preis-row:last-child { border-bottom: none; }
.preis-row.total .preis-label { font-weight: 700; }
.preis-row.total .preis-val   { font-size: 20px; font-weight: 700; color: var(--accent); }
.preis-label { font-size: 14px; color: var(--muted); }
.preis-val   { font-size: 15px; font-weight: 600; }

.polling-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 24px;
  text-align: center;
}
.polling-state h3 { font-size: 17px; font-weight: 600; }
.polling-state p  { font-size: 14px; color: var(--muted); }

/* ─── Settings Screen ────────────────────────────────────────── */
.settings-user-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 16px;
}
.settings-avatar {
  width: 56px; height: 56px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.settings-name { font-size: 18px; font-weight: 700; }
.settings-role { font-size: 14px; color: var(--muted); }

/* ─── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 13px; }
.fw-600 { font-weight: 600; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.px-16 { padding-left: 16px; padding-right: 16px; }
.pb-16 { padding-bottom: 16px; }

/* Screen transitions */
.screen-enter { animation: screen-in 0.2s ease; }
@keyframes screen-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
