/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: #1a3a52;
    color: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-logo {
    height: 80px;
    width: auto;
    background: white;
    padding: 10px;
    border-radius: 8px;
}

.header-text {
    flex: 1;
}

header h1 {
    font-size: 1.8em;
    margin-bottom: 5px;
}

.subtitle {
    opacity: 0.9;
    font-size: 0.95em;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
}

.tab-btn {
    background: none;
    border: none;
    padding: 12px 24px;
    font-size: 1em;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    color: #666;
}

.tab-btn:hover {
    color: #2c3e50;
    background: #f0f0f0;
}

.tab-btn.active {
    color: #2c3e50;
    border-bottom-color: #3498db;
    font-weight: 600;
}

.tab-content {
    display: none;
}

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

/* Period Selector */
.period-selector {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: wrap;
}

.period-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.period-controls label {
    font-weight: 600;
    color: #2c3e50;
}

.period-buttons {
    display: flex;
    gap: 8px;
}

.period-btn {
    padding: 8px 16px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    color: #666;
    transition: all 0.3s;
}

.period-btn:hover {
    border-color: #3498db;
    color: #3498db;
}

.period-btn.active {
    background: #3498db;
    border-color: #3498db;
    color: white;
}

.period-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 6px;
}

.period-label {
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
}

.period-range {
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.95em;
}

#custom-period {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-left: 10px;
}

#custom-period input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
}

#custom-period button {
    padding: 8px 16px;
    font-size: 0.9em;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.metric-card h3 {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 2.5em;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 5px;
}

.metric-label {
    color: #888;
    font-size: 0.9em;
}

.metric-note {
    color: #999;
    font-size: 0.75em;
    margin-top: 5px;
    font-style: italic;
}

.metric-value.good {
    color: #27ae60;
}

.metric-value.warning {
    color: #f39c12;
}

.metric-value.danger {
    color: #e74c3c;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-height: 300px;
    max-height: 400px;
}

.chart-container h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.chart-container canvas {
    max-height: 320px;
}

/* Section */
.section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.section h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eee;
}

.section-description {
    color: #666;
    font-size: 0.95em;
    margin-bottom: 20px;
    line-height: 1.5;
}

.disclaimer {
    margin-top: 20px;
    padding: 12px;
    background: #fff3cd;
    border-left: 4px solid #f39c12;
    border-radius: 4px;
    font-size: 0.9em;
    color: #856404;
}

.disclaimer strong {
    color: #856404;
}

/* Dose Response Analysis */
.dose-response-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.dose-response-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.dose-response-header {
    font-weight: 700;
    color: #2c3e50;
    font-size: 1.1em;
    margin-bottom: 12px;
}

.dose-group {
    background: white;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 10px;
}

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

.dose-title {
    font-weight: 600;
    color: #3498db;
    margin-bottom: 8px;
    font-size: 0.95em;
}

.dose-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9em;
    color: #555;
}

.dose-stat-item {
    display: flex;
    justify-content: space-between;
}

.dose-stat-label {
    color: #666;
}

.dose-stat-value {
    font-weight: 600;
    color: #2c3e50;
}

.no-bolus-message {
    padding: 20px;
    text-align: center;
    color: #999;
    font-style: italic;
}

/* Dias Instaveis */
.dia-instavel {
    padding: 12px;
    margin-bottom: 10px;
    border-left: 4px solid #e74c3c;
    background: #fff5f5;
    border-radius: 4px;
}

.dia-instavel-header {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

.dia-instavel-motivos {
    font-size: 0.9em;
    color: #666;
}

/* Alertas */
.alerta {
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 4px;
    border-left: 4px solid;
}

.alerta.CRITICA {
    border-color: #c0392b;
    background: #fdeaea;
}

.alerta.ALTA {
    border-color: #e74c3c;
    background: #fff5f5;
}

.alerta.MEDIA {
    border-color: #f39c12;
    background: #fef9e7;
}

.alerta-header {
    font-weight: 600;
    margin-bottom: 5px;
}

.alerta-recomendacao {
    font-size: 0.9em;
    color: #666;
    margin-top: 5px;
}

/* Table */
.table-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.table-controls input,
.table-controls select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    flex: 1;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: #2c3e50;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

td {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

tr:hover {
    background: #f9f9f9;
}

.glicemia-cell {
    font-weight: 600;
}

.glicemia-baixa {
    color: #e74c3c;
}

.glicemia-alvo {
    color: #27ae60;
}

.glicemia-alta {
    color: #f39c12;
}

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

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

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.form-actions {
    display: flex;
    gap: 10px;
}

/* Buttons */
button {
    font-family: inherit;
}

.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    padding: 6px 12px;
    font-size: 0.9em;
}

.btn-danger:hover {
    background: #c0392b;
}

/* Export Buttons */
.export-buttons {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

.btn-export {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.3s;
    color: white;
}

.btn-pdf {
    background: #e74c3c;
}

.btn-pdf:hover {
    background: #c0392b;
}

.btn-xlsx {
    background: #27ae60;
}

.btn-xlsx:hover {
    background: #229954;
}

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

/* Messages */
.message {
    padding: 12px;
    border-radius: 4px;
    margin-top: 15px;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

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

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px 20px;
    font-style: italic;
}

#loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

/* Footer */
.footer {
    background: #1a3a52;
    color: white;
    padding: 30px 20px;
    margin-top: 40px;
    border-radius: 8px;
    text-align: center;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer-copyright {
    font-size: 1em;
    font-weight: 600;
    margin-bottom: 8px;
}

.footer-rights {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 12px;
}

.footer-disclaimer {
    font-size: 0.85em;
    opacity: 0.8;
    font-style: italic;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 15px;
    margin-top: 15px;
}

/* Privacy Banner */
.privacy-banner {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-left: 4px solid #2196f3;
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 0 8px 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.privacy-banner p {
    margin: 0;
    color: #1565c0;
    font-size: 0.95em;
}

.privacy-banner a {
    color: #0d47a1;
    font-weight: 600;
}

/* Backup Reminder */
.backup-reminder {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-left: 4px solid #ff9800;
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 0 8px 8px 0;
}

.backup-reminder p {
    margin: 0 0 12px 0;
    color: #e65100;
    font-weight: 500;
}

.backup-reminder-actions {
    display: flex;
    gap: 10px;
}

/* Buttons small */
.btn-small {
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    background: #2196f3;
    color: white;
    transition: all 0.3s;
}

.btn-small:hover {
    background: #1976d2;
}

.btn-warning {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    background: #ff9800;
    color: white;
    transition: all 0.3s;
}

.btn-warning:hover {
    background: #f57c00;
}

.btn-icon {
    padding: 4px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.1em;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: #f0f0f0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content.modal-large {
    max-width: 700px;
}

.modal-content h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.modal-content p {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s ease-out;
}

.toast-success {
    background: #27ae60;
}

.toast-error {
    background: #e74c3c;
}

.toast-info {
    background: #3498db;
}

.toast.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Config Tab */
.config-group {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.config-group label {
    font-weight: 600;
    color: #555;
    min-width: 200px;
}

.config-group input[type="text"] {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95em;
    min-width: 200px;
}

.config-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

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

.config-hint {
    color: #888;
    font-size: 0.85em;
    margin-top: 4px;
    width: 100%;
}

.backup-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.backup-info p {
    margin: 5px 0;
    font-size: 0.95em;
}

.backup-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.import-options {
    margin-top: 15px;
    padding: 15px;
    background: #fff3e0;
    border-radius: 8px;
}

.import-options p {
    margin-bottom: 10px;
    font-weight: 600;
    color: #e65100;
}

.import-options button {
    margin-right: 10px;
    margin-bottom: 5px;
}

.warning-text {
    color: #e74c3c;
    font-weight: 500;
    margin-bottom: 15px;
}

/* Footer Privacy Link */
.footer-privacy {
    font-size: 0.85em;
    margin-top: 10px;
}

.footer-privacy a {
    color: #81d4fa;
    text-decoration: none;
}

.footer-privacy a:hover {
    text-decoration: underline;
}

/* Glicemia Classes */
.glicemia-hipo {
    color: #e74c3c;
}

.glicemia-alvo {
    color: #27ae60;
}

.glicemia-atencao {
    color: #f39c12;
}

.glicemia-alto {
    color: #c0392b;
}

/* Advanced Metrics Section */
.advanced-metrics {
    margin-bottom: 30px;
}

.advanced-metrics h3 {
    color: #2c3e50;
    margin-bottom: 20px;
}

.advanced-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.advanced-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    border-left: 4px solid #3498db;
}

.advanced-card h4 {
    color: #2c3e50;
    font-size: 1em;
    margin-bottom: 12px;
    font-weight: 600;
}

.advanced-hint {
    color: #888;
    font-size: 0.85em;
    margin-bottom: 10px;
    font-style: italic;
}

.advanced-stat {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
}

.advanced-stat .stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #2c3e50;
}

.advanced-stat .stat-label {
    color: #666;
    font-size: 0.9em;
}

.advanced-detail {
    font-size: 0.9em;
    color: #555;
}

.advanced-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #e0e0e0;
}

.advanced-detail-item:last-child {
    border-bottom: none;
}

.advanced-detail-label {
    color: #666;
}

.advanced-detail-value {
    font-weight: 600;
    color: #2c3e50;
}

.advanced-detail-value.warning {
    color: #f39c12;
}

.advanced-detail-value.danger {
    color: #e74c3c;
}

.advanced-detail-value.good {
    color: #27ae60;
}

/* Hipoglicemia Grid */
.hipo-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 12px;
}

.hipo-stat {
    text-align: center;
    background: white;
    padding: 12px 8px;
    border-radius: 6px;
}

.hipo-stat .stat-value {
    font-size: 1.8em;
    font-weight: 700;
    color: #2c3e50;
    display: block;
}

.hipo-stat .stat-value.hipo-noturna {
    color: #5c6bc0;
}

.hipo-stat .stat-value.hipo-grave {
    color: #c0392b;
}

.hipo-stat .stat-label {
    font-size: 0.8em;
    color: #888;
    display: block;
    margin-top: 4px;
}

.hipo-pattern {
    background: white;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    color: #666;
}

.hipo-pattern strong {
    color: #2c3e50;
}

/* Excursao badge colors */
.excursao-alta {
    color: #e74c3c;
}

.excursao-media {
    color: #f39c12;
}

.excursao-ok {
    color: #27ae60;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5em;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .header-logo {
        height: 60px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .tabs {
        overflow-x: auto;
    }

    .footer {
        padding: 20px 10px;
    }

    .footer-copyright {
        font-size: 0.9em;
    }
}
