/* ==========================================================================
   Free Document Generator - Styles
   ========================================================================== */

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

:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #d1fae5;
    --dark: #1a1a2e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text-light: #e5e7eb;
    --text-gray: #9ca3af;
    --border: #e5e7eb;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f9fafb;
    color: #1f2937;
}

/* Header */
.header {
    background: var(--dark);
    color: var(--text-light);
    padding: 1.5rem 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header h1 { font-size: 1.5rem; font-weight: 600; }

.isdoc-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(16,185,129,0.15);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    border: 1px solid rgba(16,185,129,0.3);
    letter-spacing: 0.025em;
    white-space: nowrap;
}

.isdoc-badge i { font-size: 0.9rem; }

.header-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.header-link:hover { color: var(--primary-light); }

/* Container */
.fd-container {
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

.alert-error-list {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
}

/* Section Cards */
.section {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title i { color: var(--primary); }

/* Document Type Selection */
.doc-types {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.doc-type-card {
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
}

.doc-type-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(16,185,129,0.1); }
.doc-type-card.selected { border-color: var(--primary); background: var(--primary-light); }

.doc-type-icon { font-size: 2rem; color: var(--primary); margin-bottom: 0.5rem; }
.doc-type-card.selected .doc-type-icon { color: var(--primary-dark); }
.doc-type-name { font-weight: 600; color: #1f2937; font-size: 0.9rem; }

/* Form */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row-3 { grid-template-columns: repeat(3, 1fr); }

.form-row-suggester {
    margin-bottom: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form-group-reason {
    margin-bottom: 1rem;
}

.form-label { font-size: 0.8rem; font-weight: 500; color: #374151; }
.form-label.required::after { content: '*'; color: var(--danger); margin-left: 0.25rem; }

.form-input, .form-select, .form-textarea {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    background: white;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.1);
}

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

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.form-checkbox input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* Company Suggester */
.suggester-wrapper { position: relative; }

.suggester-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
}

.suggester-item {
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
}

.suggester-item:hover { background: var(--primary-light); }

.suggester-item .name { font-weight: 600; font-size: 0.9rem; }
.suggester-item .meta { font-size: 0.8rem; color: #6b7280; }

.suggester-loading {
    padding: 0.75rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.85rem;
}

/* Items Table */
.items-table-wrapper { overflow-x: auto; margin: 1rem 0; }

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

.items-table th {
    background: #f9fafb;
    padding: 0.625rem 0.375rem;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    font-size: 0.8rem;
}

.items-table td { padding: 0.5rem 0.375rem; border-bottom: 1px solid #e5e7eb; }
.items-table tbody tr:nth-child(even) { background: #f9fafb; }

.items-table input, .items-table select {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.85rem;
}

.items-table input:focus, .items-table select:focus { outline: none; border-color: var(--primary); }
.items-table .numeric { text-align: right; }

/* Column widths */
.items-table .col-desc   { width: 22%; }
.items-table .col-qty    { width: 7%; }
.items-table .col-unit   { width: 7%; }
.items-table .col-price  { width: 10%; }
.items-table .col-vat    { width: 18%; }
.items-table .col-subtot { width: 10%; }
.items-table .col-vatamt { width: 10%; }
.items-table .col-total  { width: 10%; }
.items-table .col-action { width: 3%; }

.btn-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    transition: opacity 0.2s;
}

.btn-remove:hover { opacity: 0.7; }

/* Upload Areas */
.upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area:hover { border-color: var(--primary); background: #f0fdf4; }
.upload-area.drag-over { border-color: var(--primary); background: var(--primary-light); }

.upload-preview { position: relative; display: inline-block; }

.upload-placeholder-icon {
    font-size: 2rem;
    color: var(--primary);
}

.upload-placeholder-text {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #6b7280;
}

.upload-placeholder-hint {
    font-size: 0.75rem;
    color: #9ca3af;
}

.upload-preview-img {
    max-height: 80px;
    max-width: 200px;
}

.btn-remove-upload {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.15s;
}

.btn-remove-upload:hover { transform: scale(1.1); }

/* Totals */
.totals {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    background: #f9fafb;
    border-radius: 8px;
    max-width: 350px;
    margin-left: auto;
}

.totals-row { display: flex; justify-content: space-between; padding: 0.375rem 0; font-size: 0.9rem; }

.totals-row.total {
    border-top: 2px solid #d1d5db;
    margin-top: 0.375rem;
    padding-top: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary-dark);
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(16,185,129,0.3); }
.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; }
.btn-outline { background: white; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger-outline { background: white; color: var(--danger); border: 2px solid var(--danger); }
.btn-danger-outline:hover { background: #fee2e2; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }

.action-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.action-bar-right {
    margin-left: auto;
}

/* Email Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 1.5rem; }

.modal-actions { display: flex; gap: 1rem; margin-top: 1.5rem; justify-content: flex-end; }

/* Auto-save indicator */
.autosave-indicator {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: #6b7280;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
    z-index: 50;
}

.autosave-indicator.saving { color: var(--warning); border-color: var(--warning); }
.autosave-indicator.saved { color: var(--primary); border-color: var(--primary); }

/* Footer */
.fd-footer {
    background: var(--dark);
    color: var(--text-gray);
    padding: 2rem 0;
    margin-top: 4rem;
    text-align: center;
}

/* Hidden elements */
.hidden-input { display: none; }
.hidden-form  { display: none; }

/* Animations */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin-animation { animation: spin 1s linear infinite; }

[x-cloak] { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
    .doc-types { grid-template-columns: repeat(2, 1fr); }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .action-bar { flex-direction: column; }
    .action-bar-right { margin-left: 0; }
    .totals { max-width: 100%; }
    .items-table { font-size: 0.75rem; }
}
