/* Character Letter System - Styles
   Clean, accessible, professional design
   Mobile-first responsive approach */

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

:root {
    --color-primary: #2c5282;
    --color-primary-dark: #1a365d;
    --color-primary-light: #4299e1;
    --color-success: #276749;
    --color-success-light: #48bb78;
    --color-warning: #c05621;
    --color-warning-light: #ed8936;
    --color-error: #c53030;
    --color-error-light: #fc8181;
    --color-text: #2d3748;
    --color-text-light: #718096;
    --color-bg: #f7fafc;
    --color-white: #ffffff;
    --color-border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 6px 10px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --max-width: 720px;
    --content-padding: 20px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.65;
    color: var(--color-text);
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
    background-attachment: fixed;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--content-padding);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 32px 0 24px;
    margin-bottom: 24px;
}

header h1 {
    margin: 0 0 8px 0;
    color: var(--color-primary-dark);
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

header .subtitle {
    margin: 0;
    color: var(--color-text-light);
    font-size: 1.1rem;
    font-weight: 400;
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Cards */
.card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    margin-bottom: 24px;
    width: 100%;
    max-width: 100%;
}

.card h2 {
    margin: 0 0 20px 0;
    color: var(--color-primary-dark);
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
}

.card h3 {
    margin: 24px 0 12px 0;
    color: var(--color-text);
    font-size: 1.15rem;
    font-weight: 600;
}

/* Hero section on landing */
.hero-section {
    background: linear-gradient(135deg, #ebf4ff 0%, #e6fffa 100%);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    text-align: center;
}

.hero-text {
    font-size: 1.1rem;
    color: var(--color-primary-dark);
    margin: 0;
    line-height: 1.6;
}

/* Guidelines grid */
.guidelines-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 24px 0;
}

.guideline-card {
    padding: 20px;
    border-radius: var(--radius);
    border: 2px solid;
}

.guideline-card.good {
    background: #f0fff4;
    border-color: #9ae6b4;
}

.guideline-card.bad {
    background: #fff5f5;
    border-color: #feb2b2;
}

.guideline-card h4 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 600;
}

.guideline-card.good h4 {
    color: var(--color-success);
}

.guideline-card.bad h4 {
    color: var(--color-error);
}

.guideline-card ul {
    margin: 0;
    padding-left: 20px;
}

.guideline-card li {
    margin: 8px 0;
    line-height: 1.5;
}

/* Info boxes */
.info-box {
    background: linear-gradient(to right, #ebf8ff, #f0fff4);
    border-left: 4px solid var(--color-primary);
    padding: 20px 24px;
    margin: 20px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.info-box.warning {
    background: linear-gradient(to right, #fffaf0, #fff5f5);
    border-left-color: var(--color-warning);
}

.info-box h3, .info-box h4 {
    margin: 0 0 10px 0;
    color: var(--color-primary-dark);
    font-size: 1rem;
}

.info-box.warning h3, .info-box.warning h4 {
    color: var(--color-warning);
}

.info-box p {
    margin: 0;
}

.info-box ul {
    margin: 10px 0;
    padding-left: 20px;
}

.info-box li {
    margin: 6px 0;
}

/* Guidance boxes */
.guidance-box {
    background: linear-gradient(to right, #f0fff4, #e6fffa);
    border: 1px solid #9ae6b4;
    padding: 20px 24px;
    margin: 20px 0;
    border-radius: var(--radius);
}

.guidance-box.warning {
    background: linear-gradient(to right, #fffaf0, #fefcbf);
    border-color: #f6ad55;
}

.guidance-box h4 {
    margin: 0 0 12px 0;
    color: var(--color-success);
    font-size: 1rem;
}

.guidance-box.warning h4 {
    color: var(--color-warning);
}

.guidance-box ul {
    margin: 8px 0;
    padding-left: 20px;
}

.guidance-box li {
    margin: 6px 0;
}

/* Warning box */
.warning-box {
    background: #fff5f5;
    border: 2px solid var(--color-error-light);
    padding: 20px;
    margin: 20px 0;
    border-radius: var(--radius);
}

.warning-box h4 {
    margin: 0 0 10px 0;
    color: var(--color-error);
}

/* Error box */
.error-box {
    background: #fff5f5;
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}

/* Forms */
.wizard-form, .start-form {
    margin: 20px 0;
}

.form-group {
    margin-bottom: 24px;
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--color-white);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23718096' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}

textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

.help-text {
    display: block;
    margin-top: 8px;
    font-size: 0.875rem;
    color: var(--color-text-light);
    line-height: 1.4;
}

/* Suggestion button next to textareas */
.textarea-with-suggest {
    position: relative;
}

.textarea-with-suggest textarea {
    padding-right: 90px;
}

.suggest-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.suggest-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggest-btn:active {
    transform: translateY(0);
}

.suggest-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.suggest-btn .icon {
    font-size: 1.1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.btn.primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
}

.btn.primary:hover {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, #0d2137 100%);
}

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

.btn.secondary:hover {
    background-color: var(--color-bg);
    border-color: var(--color-text-light);
}

.btn.success {
    background: linear-gradient(135deg, var(--color-success) 0%, #1e4d3d 100%);
    color: var(--color-white);
}

.btn.success:hover {
    background: linear-gradient(135deg, #1e4d3d 0%, #143528 100%);
}

.btn.large {
    padding: 18px 36px;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.button-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 28px;
    flex-wrap: wrap;
}

.button-row.spread {
    justify-content: space-between;
}

.export-buttons {
    justify-content: center;
}

/* Progress bar */
.progress-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 28px;
    padding: 0 10px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
    min-width: 60px;
}

.step::after {
    content: '';
    position: absolute;
    top: 18px;
    left: 50%;
    width: 100%;
    height: 3px;
    background: var(--color-border);
    z-index: 0;
}

.step:last-child::after {
    display: none;
}

.step-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-white);
    border: 3px solid var(--color-border);
    color: var(--color-text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    z-index: 1;
    transition: all 0.3s ease;
}

.step.active .step-number {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
    transform: scale(1.1);
}

.step.completed .step-number {
    background: var(--color-success);
    border-color: var(--color-success);
    color: var(--color-white);
}

.step-label {
    margin-top: 10px;
    font-size: 0.75rem;
    color: var(--color-text-light);
    text-align: center;
    white-space: nowrap;
    font-weight: 500;
}

.step.active .step-label {
    color: var(--color-primary);
    font-weight: 600;
}

/* Wizard steps */
.wizard-step {
    display: none;
    width: 100%;
}

.wizard-step.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* Status and loading */
.status-box {
    text-align: center;
    padding: 48px 24px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    margin: 0 auto 24px;
    animation: spin 1s linear infinite;
}

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

/* Letter editor - FULL PAGE */
.editor-card {
    padding: 24px;
}

.editor-card h2 {
    margin-bottom: 16px;
}

#letter-editor {
    font-family: Georgia, 'Times New Roman', Times, serif;
    font-size: 1.05rem;
    line-height: 1.85;
    width: 100%;
    min-height: 55vh;
    padding: 24px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    resize: vertical;
    background: #fffef8;
}

#letter-editor:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

/* Letter preview header */
.letter-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--color-border);
    flex-wrap: wrap;
    gap: 12px;
}

.letter-preview-header h3 {
    margin: 0;
    color: var(--color-primary-dark);
}

/* Success card */
.success-card {
    text-align: center;
    border-top: 5px solid var(--color-success);
}

.success-card h2 {
    color: var(--color-success);
    font-size: 1.75rem;
}

/* Defendant name display */
.defendant-name {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary-dark);
    margin: 20px 0;
    text-align: center;
}

.defendant-inline {
    color: var(--color-primary-dark);
    font-weight: 600;
}

/* Error display */
.error {
    color: var(--color-error);
    font-size: 0.95rem;
    margin-top: 12px;
    text-align: center;
    font-weight: 500;
}

/* Utility classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

hr {
    border: none;
    border-top: 2px solid var(--color-border);
    margin: 32px 0;
}

/* Footer */
footer {
    text-align: center;
    padding: 28px 0;
    margin-top: auto;
    color: var(--color-text-light);
    font-size: 0.875rem;
}

footer p {
    margin: 6px 0;
}

/* ==========================================
   RESPONSIVE DESIGN - Mobile First
   ========================================== */

/* Small phones */
@media (max-width: 374px) {
    :root {
        --content-padding: 12px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .card {
        padding: 20px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .step-label {
        display: none;
    }
    
    .suggest-btn {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    
    .suggest-btn span:not(.icon) {
        display: none;
    }
    
    .textarea-with-suggest textarea {
        padding-right: 55px;
    }
}

/* Standard phones */
@media (max-width: 599px) {
    :root {
        --content-padding: 16px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .form-row .form-group {
        min-width: 100%;
    }
    
    .button-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .button-row.spread {
        flex-direction: column-reverse;
    }
    
    .btn {
        width: 100%;
    }
    
    .progress-bar {
        padding: 0;
        justify-content: space-around;
    }
    
    .step-label {
        font-size: 0.7rem;
    }
    
    #letter-editor {
        min-height: 45vh;
        font-size: 1rem;
        padding: 20px;
    }
    
    .guidelines-grid {
        grid-template-columns: 1fr;
    }
    
    .letter-preview-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .letter-preview-header h3 {
        text-align: center;
    }
}

/* Tablets */
@media (min-width: 600px) and (max-width: 899px) {
    :root {
        --content-padding: 24px;
    }
    
    .card {
        padding: 32px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .guidelines-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop and larger */
@media (min-width: 900px) {
    :root {
        --content-padding: 32px;
        --max-width: 800px;
    }
    
    .card {
        padding: 36px;
    }
    
    header h1 {
        font-size: 2.25rem;
    }
    
    header .subtitle {
        font-size: 1.15rem;
    }
    
    #letter-editor {
        min-height: 60vh;
    }
    
    .guidelines-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large desktop */
@media (min-width: 1200px) {
    :root {
        --max-width: 840px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 52px;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 52px;
    }
    
    .suggest-btn {
        min-width: 48px;
        min-height: 48px;
    }
}

/* High contrast / accessibility */
@media (prefers-contrast: high) {
    :root {
        --color-border: #555;
        --color-text-light: #333;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

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

/* Print styles */
@media print {
    header, footer, .progress-bar, .button-row, 
    .guidance-box, .info-box, .suggest-btn, 
    .guidelines-grid, .hero-section {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        padding: 0;
        border: none;
    }
    
    #letter-editor {
        border: none;
        padding: 0;
        font-size: 12pt;
        background: white;
    }
}
