/**
 * MKTermiGen - Design System
 * 
 * Dark Mode (Standard) + Light Mode
 * Mobile-First, Responsive Design
 * WCAG AA konform
 */

/* ===== CSS Custom Properties (Design Tokens) ===== */
:root,
[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #2d3a4f;
    --primary: #38bdf8;
    --primary-hover: #7dd3fc;
    --primary-dark: #0284c7;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(148, 163, 184, 0.2);
    --border-focus: #38bdf8;
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg: #ffffff;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-dark: #075985;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.3);
    --border-focus: #0284c7;
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.05);
    --success: #16a34a;
    --warning: #d97706;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition), color var(--transition);
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    font-weight: 700;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Layout ===== */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ===== Header ===== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
}

.logo-icon {
    font-size: 1.5rem;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.theme-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 32px 0;
    outline: none;
}

/* ===== Hero Section ===== */
.hero {
    text-align: center;
    padding: 32px 0 24px;
}

.hero-title {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.privacy-badge {
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-align: left;
    max-width: 600px;
}

.privacy-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

/* ===== Section Heading ===== */
.section-heading {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 24px;
    color: var(--text);
}

/* ===== Type Selection Grid ===== */
.type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    list-style: none;
    padding: 0;
}

.type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    font-family: inherit;
    color: var(--text);
    font-size: 1rem;
}

.type-card:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.type-card:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.type-icon {
    font-size: 2.5rem;
}

.type-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.type-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* ===== Form Container ===== */
.form-container {
    max-width: 720px;
    margin: 0 auto;
}

.form-title {
    font-size: 1.5rem;
    margin-bottom: 24px;
    color: var(--text);
}

/* ===== Notice Info Box ===== */
.notice-info {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
    font-size: 0.875rem;
    line-height: 1.7;
}

[data-theme="light"] .notice-info {
    background: rgba(2, 132, 199, 0.05);
    border-color: rgba(2, 132, 199, 0.3);
}

.notice-info small {
    color: var(--text-secondary);
}

/* ===== Form Sections ===== */
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ===== Form Groups ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.required-mark {
    color: var(--error);
    font-weight: 700;
}

/* ===== Form Inputs ===== */
.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
    -webkit-appearance: none;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

[data-theme="light"] .form-input:focus {
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.form-input.field-error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px var(--error-bg);
}

select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* ===== Checkbox ===== */
.form-group-checkbox {
    margin-bottom: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9375rem;
    padding: 8px 0;
}

.form-checkbox {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-text {
    flex: 1;
}

/* ===== Error Message ===== */
.error-message {
    color: var(--error);
    font-size: 0.8125rem;
    margin-top: 4px;
    padding: 4px 0;
}

/* ===== Tooltip ===== */
.tooltip-icon {
    cursor: help;
    font-size: 0.875rem;
    position: relative;
}

.tooltip-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    min-width: 200px;
    max-width: 320px;
    line-height: 1.5;
    white-space: normal;
    font-weight: 400;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    color: #0f172a;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

/* ===== Form Actions ===== */
.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
}

/* ===== Preview Page ===== */
.preview-container {
    max-width: 800px;
    margin: 0 auto;
}

/* ===== Tabs ===== */
.preview-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: -2px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== Letter Paper (Preview) ===== */
.letter-paper {
    background: #ffffff;
    color: #1a1a1a;
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    min-height: 600px;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 0.9375rem;
    line-height: 1.7;
}

.letter-preview {
    max-width: 100%;
}

.letter-sender {
    font-size: 0.75rem;
    color: #555;
    border-bottom: 1px solid #ccc;
    padding-bottom: 4px;
    margin-bottom: 24px;
}

.letter-spacer {
    height: 32px;
}

.letter-spacer-sm {
    height: 20px;
}

.letter-spacer-xs {
    height: 10px;
}

.letter-recipient {
    font-size: 0.9375rem;
}

.letter-date {
    text-align: right;
    font-size: 0.9375rem;
}

.letter-subject {
    font-size: 1rem;
}

.letter-salutation,
.letter-body,
.letter-closing,
.letter-name {
    font-size: 0.9375rem;
}

.letter-signature-space {
    height: 56px;
    border-bottom: 1px dotted #ccc;
    margin-bottom: 4px;
    width: 200px;
}

.letter-notice {
    margin-top: 32px;
    font-size: 0.6875rem;
    color: #888;
    border-top: 1px solid #ddd;
    padding-top: 12px;
    line-height: 1.5;
}

/* ===== Letter Editor ===== */
.letter-editor {
    width: 100%;
    padding: 24px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    resize: vertical;
    min-height: 500px;
}

.letter-editor:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

/* ===== Preview Actions ===== */
.preview-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
    justify-content: center;
}

/* ===== Legal Hint ===== */
.legal-hint {
    background: var(--error-bg);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 24px;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text);
}

/* ===== Footer ===== */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 24px 0;
    margin-top: auto;
    text-align: center;
}

.footer-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 720px;
    margin: 0 auto;
}

/* ===== Responsive Breakpoints ===== */

/* Tablet */
@media (max-width: 1024px) {
    .type-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* Mobile */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }

    .hero-title {
        font-size: 1.875rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .section-heading {
        font-size: 1.25rem;
    }

    .type-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .type-card {
        padding: 16px 12px;
    }

    .type-icon {
        font-size: 2rem;
    }

    .type-title {
        font-size: 0.9375rem;
    }

    .type-desc {
        font-size: 0.75rem;
    }

    .form-section {
        padding: 16px;
    }

    .form-actions {
        flex-direction: column;
    }

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

    .preview-actions {
        flex-direction: column;
    }

    .preview-actions .btn {
        width: 100%;
    }

    .letter-paper {
        padding: 20px;
    }

    .preview-tabs {
        overflow-x: auto;
    }

    .privacy-badge {
        font-size: 0.75rem;
        padding: 10px 14px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .type-grid {
        grid-template-columns: 1fr;
    }

    .header-inner {
        flex-wrap: wrap;
        gap: 8px;
    }

    .theme-toggle {
        font-size: 0.8125rem;
        padding: 6px 12px;
    }
}

/* ===== Focus Visible (Accessibility) ===== */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ===== Print Styles ===== */
@media print {
    .header, .footer, .form-actions, .preview-actions, .preview-tabs, .legal-hint, .tab-content:not(.active) {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .letter-paper {
        box-shadow: none;
        padding: 0;
    }
}

/* ===== Custom Fields ===== */
.custom-fields-container {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.custom-fields-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.btn-small {
    padding: 4px 12px;
    font-size: 0.85rem;
}

.custom-field-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.custom-field-row .form-input {
    flex: 1;
}

.custom-field-row .custom-field-label {
    flex: 0.8;
}

.btn-remove-custom-field {
    background: transparent;
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: var(--radius);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-remove-custom-field:hover {
    background: var(--error-bg);
}

/* ===== Letter References (Vertragsnummern unter Datum) ===== */
.letter-references {
    font-size: 0.9em;
    color: var(--text-secondary);
}

.letter-ref-line {
    margin-bottom: 2px;
}
