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

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #555;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --border: #e2e8f0;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "Consolas", "Fira Code", "Courier New", monospace;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* === Layout === */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

/* === Header === */
.app-header {
    text-align: center;
    margin-bottom: 32px;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

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

.section h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* === Drop Zone === */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone.drag-active {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
}

.drop-zone-sm {
    padding: 20px;
}

.drop-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.drop-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* === Toggle link === */
.toggle-link {
    text-align: center;
    margin-top: 12px;
    font-size: 0.9rem;
}

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

.toggle-link a:hover {
    text-decoration: underline;
}

/* === Manual Form === */
.manual-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.manual-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.manual-form input,
.manual-form input[type="text"],
.manual-form input[type="number"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: border-color 0.2s;
}

.manual-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

/* === Manual Member Input === */
.manual-input-toggle {
    margin-top: 4px;
}

.manual-member-heading {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}

.manual-member-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.manual-member-row {
    position: relative;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.manual-member-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}

.manual-member-fields label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.manual-member-fields input,
.manual-member-fields input[type="text"],
.manual-member-fields input[type="number"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color 0.2s;
}

.manual-member-fields input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-remove-row {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 8px;
    font-size: 0.8rem;
    color: var(--error);
    background: transparent;
    border: 1px solid transparent;
}

.btn-remove-row:hover {
    background: var(--error-bg);
    border-color: #fecaca;
}

.manual-member-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* === Loaded Badge === */
.loaded-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.badge-file {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
}

.btn:hover {
    background: var(--bg);
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 1rem;
}

/* === Error Banner === */
.error-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--error-bg);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.error-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.error-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--error);
    padding: 0 4px;
    line-height: 1;
}

/* === Preview Table === */
.table-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.preview-table th {
    background: var(--bg);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 2px solid var(--border);
}

.preview-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
}

.preview-table tr:last-child td {
    border-bottom: none;
}

.preview-table tr:hover td {
    background: #f8fafc;
}

.preview-table .mono {
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

/* === Action Bar === */
.action-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

/* === Generating Section === */
.generating-section {
    text-align: center;
    padding: 48px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.generating-section h2 {
    margin-bottom: 24px;
}

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 12px;
    background: var(--bg);
    border-radius: 6px;
    overflow: hidden;
    margin: 0 auto 16px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 6px;
    transition: width 0.3s ease;
}

.progress-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* === Done Section === */
.done-section {
    text-align: center;
    padding: 48px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.done-section h2 {
    margin-bottom: 12px;
    font-size: 1.5rem;
}

.done-summary {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* === Responsive === */
@media (max-width: 600px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .app-header h1 {
        font-size: 1.3rem;
    }

    .section {
        padding: 16px;
    }

    .btn-lg {
        width: 100%;
    }

    .action-bar {
        flex-direction: column;
    }
}

/* === Delete Row Button === */
.btn-delete-row {
    padding: 2px 8px;
    font-size: 0.85rem;
    color: var(--error);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    line-height: 1.4;
    transition: all 0.15s ease;
}

.btn-delete-row:hover {
    background: var(--error-bg);
    border-color: #fecaca;
}
