/* =========================================
   Gerador de Tabela Nutricional - CSS
   RDC 429/2020 e IN 75/2020 ANVISA
   ========================================= */

/* === CSS Variables === */
:root {
    --primary-color: #1a365d;
    --primary-light: #2d4a7c;
    --primary-dark: #0f2744;
    --accent-color: #38b2ac;
    --accent-light: #4fd1c5;
    --background-dark: #0f172a;
    --background-card: rgba(30, 41, 59, 0.8);
    --background-glass: rgba(255, 255, 255, 0.05);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.1);
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(56, 178, 172, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background-dark);
    background-image:
        radial-gradient(ellipse at top, rgba(56, 178, 172, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(26, 54, 93, 0.2) 0%, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* === Typography === */
h1,
h2,
h3,
h4 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1rem;
}

/* === Layout === */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.header {
    text-align: center;
    padding: 2rem 0 3rem;
}

.header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

.main-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 2rem;
    align-items: start;
}

/* === Cards === */
.card {
    background: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header .icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-light));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.card-header h3 {
    flex: 1;
}

/* === Forms === */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--background-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 178, 172, 0.2);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

/* === File Upload === */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(56, 178, 172, 0.05);
}

.upload-area .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.upload-area small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.upload-area input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.file-info {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--background-glass);
    border-radius: var(--radius-sm);
    margin-top: 1rem;
}

.file-info.visible {
    display: flex;
}

.file-info .file-icon {
    font-size: 1.5rem;
}

.file-info .file-name {
    flex: 1;
    font-size: 0.875rem;
    word-break: break-all;
}

.file-info .remove-file {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.25rem;
}

/* === Nutrient Grid === */
.nutrient-grid {
    display: grid;
    gap: 0.75rem;
}

.nutrient-item {
    display: grid;
    grid-template-columns: 1fr 100px 60px;
    gap: 0.75rem;
    align-items: center;
}

.nutrient-item label {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin: 0;
}

.nutrient-item input {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.nutrient-item .unit {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === Model Selection === */
.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.model-card {
    background: var(--background-glass);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    cursor: pointer;
    transition: all var(--transition-normal);
    text-align: center;
}

.model-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.model-card.selected {
    border-color: var(--accent-color);
    background: rgba(56, 178, 172, 0.1);
    box-shadow: var(--shadow-glow);
}

.model-card input[type="radio"] {
    display: none;
}

.model-card .model-preview {
    width: 100%;
    height: 120px;
    background: white;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.model-card .model-name {
    font-weight: 500;
    font-size: 0.875rem;
}

/* === Mini Table Previews === */
.mini-table {
    font-size: 6px;
    color: #000;
    text-align: left;
    width: 100%;
    padding: 4px;
}

.mini-table.vertical {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mini-table.horizontal {
    display: flex;
    flex-direction: row;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.mini-table.linear {
    display: flex;
    flex-direction: row;
    gap: 2px;
    font-size: 5px;
    overflow: hidden;
}

/* === Dimension Controls === */
.dimension-controls {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.dimension-controls .form-group {
    flex: 1;
    margin-bottom: 0;
}

.dimension-controls input {
    text-align: center;
}

.dimension-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.25rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-light));
    color: white;
    box-shadow: 0 4px 15px rgba(56, 178, 172, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56, 178, 172, 0.4);
}

.btn-secondary {
    background: var(--background-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-block {
    width: 100%;
}

/* === Action Bar === */
.action-bar {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.action-bar .btn {
    flex: 1;
}

/* === Preview Panel === */
.preview-panel {
    position: sticky;
    top: 2rem;
}

.preview-container {
    background: white;
    border-radius: var(--radius-md);
    padding: 1.5rem;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-placeholder {
    text-align: center;
    color: #64748b;
}

.preview-placeholder .icon {
    font-size: 4rem;
    opacity: 0.3;
    margin-bottom: 1rem;
}

/* === Nutritional Table Styles (Preview) === */
.tabela-nutricional {
    font-family: 'Helvetica', Arial, sans-serif;
    font-size: 8pt;
    color: #000;
    background: #fff;
    border: 1px solid #000;
    padding: 8px;
    width: 100%;
    max-width: 100%;
}

.tabela-nutricional .titulo {
    font-weight: bold;
    font-size: 10pt;
    text-align: center;
    border-bottom: 2px solid #000;
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.tabela-nutricional .porcao {
    font-size: 8pt;
    border-bottom: 1px solid #000;
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.tabela-nutricional table {
    width: 100%;
    border-collapse: collapse;
}

.tabela-nutricional th,
.tabela-nutricional td {
    padding: 2px 4px;
    text-align: left;
    font-size: 8pt;
    border-bottom: 1px solid #ccc;
}

.tabela-nutricional th {
    font-weight: bold;
    border-bottom: 1px solid #000;
}

.tabela-nutricional .vd {
    text-align: right;
}

.tabela-nutricional .nota {
    font-size: 7pt;
    margin-top: 4px;
    border-top: 1px solid #000;
    padding-top: 4px;
}

/* === Alerts & Messages === */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

/* === Loading State === */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* === Responsive === */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .preview-panel {
        position: static;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.75rem;
    }

    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }

    .model-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-bar {
        flex-direction: column;
    }

    .nutrient-item {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

/* === Ingredients Found === */
.ingredients-found {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--background-glass);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-color);
}

.ingredients-found h4 {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.ingredient-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
}

.ingredient-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

.ingredient-list li:last-child {
    border-bottom: none;
}

.ingredient-list li.matched .ingredient-icon {
    color: var(--success-color);
}

.ingredient-list li.unmatched .ingredient-icon {
    color: var(--warning-color);
}

.ingredient-original {
    flex: 1;
    color: var(--text-secondary);
}

.ingredient-matched {
    font-size: 0.75rem;
    color: var(--accent-color);
}

.ingredients-total {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
}

/* === Calculated Fields === */
.nutrient-item input.calculated {
    background: rgba(56, 178, 172, 0.1);
    border-color: var(--accent-color);
}

.recalculate-info {
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    color: var(--warning-color);
}

.recalculate-info small {
    display: block;
    font-size: 0.75rem;
}

/* === Upload area links === */
.upload-area a {
    color: var(--accent-color);
    text-decoration: none;
}

.upload-area a:hover {
    text-decoration: underline;
}