/* ============================================================
   Design Tokens — matching UnterhaltsPlan design system
   ============================================================ */
:root {
  --forest-900: oklch(0.24 0.045 155);
  --forest-800: oklch(0.32 0.055 155);
  --forest-700: oklch(0.42 0.075 152);
  --forest-600: oklch(0.55 0.10 150);
  --forest-500: oklch(0.66 0.10 148);
  --forest-100: oklch(0.94 0.025 150);
  --forest-50:  oklch(0.97 0.012 150);

  --gray-400: oklch(0.70 0.00 0);
  --gray-100: oklch(0.94 0.00 0);

  --cream:   oklch(0.985 0.010 85);
  --cream-2: oklch(0.970 0.014 82);

  --ink-900: oklch(0.18 0.015 250);
  --ink-700: oklch(0.35 0.012 250);
  --ink-400: oklch(0.58 0.010 250);
  --ink-200: oklch(0.82 0.006 250);

  --surface: #ffffff;
  --border:  oklch(0.88 0.008 250);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow:    0 2px 8px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --header-h: 56px;
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink-900);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }

/* ============================================================
   Header
   ============================================================ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-brand { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--forest-900);
  letter-spacing: -0.02em;
  transition: color 0.15s;
}
.logo-link:hover .logo { color: var(--forest-700); }
.app-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--forest-700);
  background: var(--forest-50);
  border: 1px solid var(--forest-100);
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.header-nav {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.nav-link {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-700);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--cream-2); color: var(--forest-800); }

/* ============================================================
   Local Notice
   ============================================================ */
.local-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--forest-50);
  border-bottom: 1px solid var(--forest-100);
  color: var(--forest-800);
  font-size: 0.82rem;
  padding: 8px 20px;
}
.local-notice-icon { font-size: 1rem; flex-shrink: 0; }

/* ============================================================
   App Layout — 2 columns on desktop, stacked on mobile
   ============================================================ */
.app-layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  align-items: start;
}

/* ============================================================
   Panels
   ============================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.panel + .panel { margin-top: 16px; }
.panel-title {
  font-size: 0.80rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-400);
  margin-bottom: 16px;
}

/* ============================================================
   Form Elements
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; margin-bottom: 0; }
.field-label {
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--ink-700);
}
.field-hint {
  font-size: 0.75rem;
  color: var(--ink-400);
  margin-top: 2px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  color: var(--ink-900);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--forest-600);
  box-shadow: 0 0 0 3px var(--forest-100);
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.5; }

/* ============================================================
   Letter-type Selector
   ============================================================ */
.letter-type-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.letter-type-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--cream);
}
.letter-type-option:hover { border-color: var(--forest-500); background: var(--forest-50); }
.letter-type-option.selected { border-color: var(--forest-700); background: var(--forest-50); }
.letter-type-option input[type="radio"] { display: none; }
.letter-type-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  margin-top: 2px;
  transition: border-color 0.15s, background 0.15s;
}
.letter-type-option.selected .letter-type-dot {
  border-color: var(--forest-700);
  background: var(--forest-700);
}
.letter-type-text {}
.letter-type-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-900);
  display: block;
  line-height: 1.3;
}
.letter-type-desc {
  font-size: 0.78rem;
  color: var(--ink-400);
  display: block;
  margin-top: 2px;
  line-height: 1.4;
}

/* ============================================================
   Children Section
   ============================================================ */
.children-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.child-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.child-row .field { flex: 1; margin-bottom: 0; }
.child-row .field-year { flex: 0 0 90px; }
.btn-remove-child {
  color: var(--ink-400);
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  padding: 8px 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.12s;
  height: 36px;
  display: flex;
  align-items: center;
}
.btn-remove-child:hover { color: oklch(0.45 0.15 25); }

/* ============================================================
   Rechner Link
   ============================================================ */
.rechner-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--forest-700);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--forest-100);
  transition: color 0.12s, text-decoration-color 0.12s;
  margin-top: 4px;
}
.rechner-link:hover { color: var(--forest-900); text-decoration-color: var(--forest-500); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.08s;
  white-space: nowrap;
  cursor: pointer;
  min-height: 44px;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--forest-800);
  color: #fff;
  border: 1px solid transparent;
}
.btn-primary:hover { background: var(--forest-900); }

.btn-secondary {
  background: var(--forest-100);
  color: var(--forest-800);
  border: 1px solid var(--forest-100);
}
.btn-secondary:hover { background: var(--forest-50); border-color: var(--forest-500); }

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

.btn-sm { padding: 7px 12px; font-size: 0.82rem; min-height: 36px; }
.btn-full { width: 100%; }

/* ============================================================
   Preview Panel
   ============================================================ */
.preview-panel { position: sticky; top: calc(var(--header-h) + 20px); }
.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.letter-preview {
  width: 100%;
  min-height: 420px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink-900);
  font-family: 'Georgia', serif;
  font-size: 0.92rem;
  line-height: 1.75;
  resize: vertical;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.letter-preview:focus {
  border-color: var(--forest-600);
  box-shadow: 0 0 0 3px var(--forest-100);
}

/* ============================================================
   Status Toast
   ============================================================ */
.status-msg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--forest-700);
  background: var(--forest-50);
  border: 1px solid var(--forest-100);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.status-msg.visible { opacity: 1; }

/* ============================================================
   Disclaimer
   ============================================================ */
.disclaimer {
  font-size: 0.78rem;
  color: var(--ink-400);
  background: var(--cream-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  line-height: 1.5;
  margin-top: 16px;
}
.disclaimer strong { color: var(--ink-700); }

/* ============================================================
   Footer
   ============================================================ */
.app-footer {
  max-width: 1320px;
  margin: 32px auto 0;
  padding: 20px 20px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.footer-legal {
  font-size: 0.78rem;
  color: var(--ink-400);
}

/* ============================================================
   Divider
   ============================================================ */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ============================================================
   Responsive — tablet / mobile
   ============================================================ */
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 16px;
  }
  .preview-panel { position: static; }
  .header-nav { display: none; }
}

@media (max-width: 520px) {
  .header-inner { padding: 0 14px; }
  .app-layout { padding: 12px; gap: 12px; }
  .panel { padding: 16px; }
  .preview-actions { gap: 6px; }
  .preview-actions .btn { flex: 1; }
  .app-badge { display: none; }
  .letter-type-desc { display: none; }
  .child-row .field-year { flex: 0 0 75px; }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .app-header,
  .local-notice,
  .form-column,
  .preview-actions,
  .disclaimer,
  .app-footer,
  .status-msg { display: none !important; }

  body { background: #fff; font-size: 12pt; }

  .app-layout {
    display: block;
    padding: 0;
    max-width: none;
  }

  .preview-panel {
    position: static;
    box-shadow: none;
    border: none;
    padding: 0;
    background: #fff;
  }

  .panel-title { display: none; }

  .letter-preview {
    width: 100%;
    min-height: unset;
    height: auto;
    border: none;
    background: #fff;
    color: #000;
    font-family: Georgia, serif;
    font-size: 12pt;
    line-height: 1.75;
    padding: 0;
    resize: none;
    white-space: pre-wrap;
  }
}
