:root {
    --primary-color: #0d6efd;
    --primary-hover: #0b5ed7;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --header-bg: #1e293b;
    --header-text: #ffffff;

    /* Sugar Level & BMI Colors */
    --color-sugar-red-bg: #f8d7da;
    --color-sugar-red-text: #721c24;
    --color-sugar-orange-bg: #fff3cd;
    --color-sugar-orange-text: #856404;
    --color-sugar-white-bg: #ffffff;
    --color-sugar-white-text: #212529;

    --color-bmi-green-bg: #d4edda;
    --color-bmi-green-text: #155724;
    --color-bmi-blue-bg: #d1ecf1;
    --color-bmi-blue-text: #0c5460;
    --color-bmi-red-bg: #f8d7da;
    --color-bmi-red-text: #721c24;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

/* Auth Container */
.auth-container {
    max-width: 420px;
    margin: 80px auto;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h1 {
    font-size: 1.5rem;
    color: #1e293b;
    margin-bottom: 8px;
}

.auth-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    color: #6c757d;
    cursor: pointer;
    transition: color 0.2s;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    margin-bottom: -2px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.btn-primary {
    width: 100%;
    padding: 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid #f5c6cb;
}

/* Navbar */
.app-header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    font-size: 0.9rem;
    color: #cbd5e1;
}

.btn-outline {
    background: transparent;
    border: 1px solid #94a3b8;
    color: #f8fafc;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: rgba(255,255,255,0.1);
    border-color: white;
}

.btn-danger {
    background: #dc3545;
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-danger:hover {
    background: #bb2d3b;
}

/* Dashboard Content */
.app-content {
    padding: 20px 24px;
    max-width: 100%;
    overflow-x: auto;
}

.upcoming-banner {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: background-color 0.15s, border-color 0.15s;
}

.upcoming-banner:hover {
    background-color: #dbeafe;
    border-color: #93c5fd;
}

.upcoming-badge-title {
    font-weight: 700;
    color: #1d4ed8;
    white-space: nowrap;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    background: white;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.height-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 500;
}

.reports-buttons {
    display: flex;
    gap: 10px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-secondary:hover {
    background: #5c636a;
}

/* Data Table */
.table-container {
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    text-align: center;
    min-width: 1200px;
}

.data-table th, .data-table td {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table th {
    background-color: #f1f5f9;
    color: #334155;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
}

.repeated-header-row th {
    background-color: #e2e8f0 !important;
    color: #0f172a !important;
    font-weight: 600;
    border-top: 2px solid #94a3b8 !important;
    border-bottom: 2px solid #94a3b8 !important;
    position: static !important;
}

.data-table th.col-date { width: 105px; }
.data-table th.col-sugar { width: 85px; }
.data-table th.col-weight { width: 80px; }
.data-table th.col-bmi { width: 75px; }
.data-table th.col-insulin { width: 85px; }
.data-table th.col-notes { width: auto; text-align: left; }

.insulin-select {
    width: 100%;
    padding: 3px 2px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #f8fafc;
    cursor: pointer;
    text-align: center;
}

.insulin-select:focus {
    border-color: var(--primary-color);
    outline: none;
    background: white;
}

.cell-date {
    background-color: #f8fafc;
    font-weight: 600;
    color: #475569;
}

.cell-today {
    background-color: #eff6ff !important;
    font-weight: 700;
    color: #1d4ed8;
}

.cell-editable {
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    user-select: none;
}

.cell-editable:hover {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
    opacity: 0.95;
}

/* Light Yellow Row & Column Highlight */
.row-highlighted td {
    background-color: #fef9c3 !important;
    color: #1e293b;
}

.col-highlighted {
    background-color: #fef9c3 !important;
    color: #1e293b;
}

.cell-selected {
    background-color: #fef08a !important;
    outline: 3px solid #eab308 !important;
    outline-offset: -3px;
    z-index: 10;
    position: relative;
}

/* Drag and Drop for Cells */
.cell-draggable {
    cursor: grab;
}

.cell-draggable:active {
    cursor: grabbing;
}

.is-dragging {
    opacity: 0.4;
    outline: 2px dashed var(--primary-color) !important;
    outline-offset: -2px;
}

.drag-over {
    background-color: #cbd5e1 !important;
    outline: 2px solid var(--primary-color) !important;
    outline-offset: -2px;
}

/* Cell Wrapper & Small Delete Icon */
.cell-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 3px;
}

.col-notes .cell-wrapper {
    justify-content: space-between;
}

.delete-cell-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 13px;
    height: 13px;
    font-size: 10px;
    font-weight: bold;
    color: #64748b;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
    transition: all 0.15s ease-in-out;
    flex-shrink: 0;
}

.delete-cell-btn:hover {
    color: #ffffff;
    background-color: #dc3545;
}

.cell-notes {
    text-align: left !important;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Color classes for Sugar Levels */
.sugar-red {
    background-color: var(--color-sugar-red-bg) !important;
    color: var(--color-sugar-red-text) !important;
    font-weight: 600;
}

.sugar-orange {
    background-color: var(--color-sugar-orange-bg) !important;
    color: var(--color-sugar-orange-text) !important;
    font-weight: 600;
}

.sugar-white {
    background-color: var(--color-sugar-white-bg) !important;
    color: var(--color-sugar-white-text) !important;
}

/* Color classes for BMI */
.bmi-green {
    background-color: var(--color-bmi-green-bg) !important;
    color: var(--color-bmi-green-text) !important;
    font-weight: 600;
}

.bmi-blue {
    background-color: var(--color-bmi-blue-bg) !important;
    color: var(--color-bmi-blue-text) !important;
    font-weight: 600;
}

.bmi-red {
    background-color: var(--color-bmi-red-bg) !important;
    color: var(--color-bmi-red-text) !important;
    font-weight: 600;
}

/* Modal Overlay & Dialog */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-dialog {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 480px;
    padding: 24px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-header {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1e293b;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-body label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: #475569;
}

.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

.modal-body textarea {
    min-height: 100px;
    resize: vertical;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-cancel {
    background: #e2e8f0;
    color: #334155;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-cancel:hover {
    background: #cbd5e1;
}

.btn-save {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-save:hover {
    background: var(--primary-hover);
}

/* Print Layout: Landscape A4 with Minimal Margins */
@page {
    size: A4 landscape;
    margin: 5mm;
}

@media print {
    body {
        background: white !important;
        color: black !important;
    }
    .app-header, .toolbar, .btn-primary, .btn-secondary, .btn-danger, .btn-outline, .modal-overlay {
        display: none !important;
    }
    .app-content {
        padding: 0 !important;
    }
    .table-container {
        box-shadow: none !important;
    }
    .data-table {
        min-width: 100% !important;
        font-size: 7.5pt !important;
    }
    .data-table th, .data-table td {
        padding: 3px 4px !important;
    }
}
