/* ================================ */
/* === 1. CUSTOM PROPERTIES     === */
/* ================================ */

:root {
  --blue: #185FA5;
  --blue-light: #E8F0FA;
  --blue-dark: #134B84;
  --coral: #993C1D;
  --coral-bg: #FAECE7;
  --green: #1D9E75;
  --green-bg: #E6F7F1;
  --purple: #3C3489;
  --purple-bg: #EEEDFE;
  --red: #EE4B4B;

  --bg: #F5F5F5;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --text-secondary: #6B7280;
  --border: rgba(0,0,0,0.08);

  --radius-sm: 8px;
  --radius: 12px;
  --max-width: 480px;
}

/* ================================ */
/* === 2. RESET + BASE          === */
/* ================================ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ================================ */
/* === 3. VIEW SYSTEM           === */
/* ================================ */

.view {
  display: none;
}

.view.active {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.screen-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 56px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top, 0px);
}

.header-title {
  font-size: 18px;
  font-weight: 500;
}

.header-spacer {
  width: 44px;
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* ================================ */
/* === 4. SHARED COMPONENTS     === */
/* ================================ */

h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

h1 .accent { color: var(--blue); }

.subtitle {
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 32px;
  font-size: 15px;
  line-height: 1.5;
}

.section-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.error-text {
  text-align: center;
  color: var(--red);
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 12px;
}

.success-text {
  text-align: center;
  color: var(--green);
  font-weight: 500;
  font-size: 15px;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

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

.btn-primary {
  background: var(--blue);
  color: white;
}

.btn-primary:hover { background: var(--blue-dark); }

.btn-outline {
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  margin-top: 12px;
}

.btn-small {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
  min-height: 36px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:active { opacity: 0.6; }

/* Document Badge */
.doc-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.doc-badge.badge-rechnung {
  background: var(--blue-light);
  color: var(--blue);
}

.doc-badge.badge-angebot {
  background: var(--coral-bg);
  color: var(--coral);
}

/* Form elements */
.form-group {
  width: 100%;
  margin-bottom: 16px;
}

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

.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}

.form-group input:focus { border-color: var(--blue); }

/* ================================ */
/* === 5. PIN SCREEN            === */
/* ================================ */

#view-pin { background: var(--surface); }
#view-enroll { background: var(--surface); }

.pin-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.pin-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
}

.pin-header h2 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

.pin-digits {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 32px;
}

.pin-digit {
  width: 40px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 500;
  transition: all 0.15s;
}

.pin-digit.filled {
  border-color: var(--blue);
  background: var(--blue-light);
}

.pin-digit.error {
  border-color: var(--red);
  background: #FEE;
  animation: pin-shake 0.4s;
}

@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--surface);
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pin-key:active { background: var(--blue-light); }

.pin-key-empty { border: none; cursor: default; }
.pin-key-empty:active { background: transparent; }
.pin-key-delete { color: var(--text-secondary); }
.pin-key:disabled { opacity: 0.3; cursor: not-allowed; }

/* ================================ */
/* === 6. START SCREEN          === */
/* ================================ */

#view-start { background: var(--bg); }

.greeting {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 4px;
}

.screen-question {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.type-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.type-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 120px;
}

.type-tile:active { transform: scale(0.97); }

.tile-angebot {
  background: var(--coral-bg);
  color: var(--coral);
}

.tile-rechnung {
  background: var(--blue-light);
  color: var(--blue);
}

.tile-icon { flex-shrink: 0; }

.tile-label {
  font-size: 15px;
  font-weight: 500;
}

/* Recent list */
#recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
}

.recent-name {
  font-size: 14px;
  font-weight: 400;
}

.recent-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
}

.recent-badge.badge-rechnung {
  background: var(--blue-light);
  color: var(--blue);
}

.recent-badge.badge-angebot {
  background: var(--coral-bg);
  color: var(--coral);
}

/* ================================ */
/* === 7. INPUT SCREEN          === */
/* ================================ */

#view-input { background: var(--surface); }

.input-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.input-instruction {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 32px;
  text-align: center;
}

.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.record-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--blue);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.record-btn:active { transform: scale(0.95); }

.record-btn.recording {
  background: var(--red);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(238,75,75,0.4); }
  50% { box-shadow: 0 0 0 16px rgba(238,75,75,0); }
}

.rec-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

#rec-active {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: rec-blink 1s ease-in-out infinite;
}

@keyframes rec-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#rec-timer {
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--red);
}

.input-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  color: var(--text-secondary);
  font-size: 13px;
}

.input-divider::before,
.input-divider::after {
  content: '';
  flex: 1;
  height: 0.5px;
  background: var(--border);
}

.text-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.text-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  resize: vertical;
  outline: none;
  min-height: 80px;
  transition: border-color 0.15s;
}

.text-group textarea:focus { border-color: var(--blue); }

/* ================================ */
/* === 8. PROCESSING SCREEN     === */
/* ================================ */

#view-processing { background: var(--surface); }

.processing-title {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 32px;
}

.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 300px;
}

.pipe-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  position: relative;
  padding-bottom: 28px;
}

.pipe-step.last { padding-bottom: 0; }

.pipe-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  position: relative;
  z-index: 1;
}

.pipe-line {
  position: absolute;
  left: 11px;
  top: 24px;
  width: 2px;
  height: 28px;
  background: var(--border);
  transition: background 0.3s;
}

.pipe-step.last .pipe-line { display: none; }

.pipe-label {
  font-size: 14px;
  color: var(--text-secondary);
  padding-top: 2px;
  transition: color 0.3s;
}

/* Pipeline states */
.pipe-step.done .pipe-dot {
  background: var(--green);
  border-color: var(--green);
}

.pipe-step.done .pipe-dot::after {
  content: '✓';
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.pipe-step.done .pipe-line { background: var(--green); }
.pipe-step.done .pipe-label { color: var(--text); }

.pipe-step.active .pipe-dot {
  background: var(--blue);
  border-color: var(--blue);
  animation: pipe-pulse 1.2s ease-in-out infinite;
}

.pipe-step.active .pipe-label {
  color: var(--blue);
  font-weight: 500;
}

@keyframes pipe-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(24,95,165,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(24,95,165,0); }
}

/* ================================ */
/* === 9. DRAFT SCREEN          === */
/* ================================ */

#view-draft { background: var(--bg); }

.draft-content {
  padding-bottom: 80px;
}

.draft-field {
  margin-bottom: 16px;
}

.draft-field select,
.draft-field input {
  width: 100%;
  padding: 10px 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  min-height: 44px;
  transition: border-color 0.15s;
}

.draft-field select:focus,
.draft-field input:focus { border-color: var(--blue); }

.draft-field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.draft-field-small { flex: 1; }
.draft-field-large { flex: 2; }

.draft-field-row .draft-field { margin-bottom: 0; }

#new-customer-fields {
  padding: 12px;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

/* Position rows */
#draft-positions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.pos-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  position: relative;
}

.pos-card select {
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  min-height: 40px;
  margin-bottom: 8px;
}

.pos-card select:focus { border-color: var(--blue); }

.pos-fields {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pos-fields input {
  padding: 8px;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  outline: none;
  min-height: 40px;
  background: var(--surface);
  color: var(--text);
}

.pos-fields input:focus { border-color: var(--blue); }

.pos-qty { width: 56px; }
.pos-unit { width: 56px; color: var(--text-secondary); background: var(--bg) !important; }
.pos-price { width: 80px; }

.pos-line-total {
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  min-width: 60px;
  white-space: nowrap;
}

.pos-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.pos-remove:active { background: #FEE; color: var(--red); }

.btn-add {
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s, color 0.15s;
  margin-bottom: 16px;
}

.btn-add:active {
  border-color: var(--blue);
  color: var(--blue);
}

.draft-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-top: 1.5px solid var(--border);
}

.total-label {
  font-size: 15px;
  font-weight: 500;
}

.total-value {
  font-size: 20px;
  font-weight: 500;
}

.draft-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}

.btn-cta {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ================================ */
/* === 10. UPDATE BANNER        === */
/* ================================ */

#update-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--blue);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
}

#update-banner .btn-small {
  background: white;
  color: var(--blue);
  font-weight: 500;
}
