/* T1D Manager - Dashboard Styles */

:root {
    --color-bg: #f5f7fa;
    --color-card: #ffffff;
    --color-primary: #2196F3;
    --color-success: #4CAF50;
    --color-warning: #FF9800;
    --color-danger: #f44336;
    --color-text: #333333;
    --color-text-light: #666666;
    --color-border: #e0e0e0;
    
    --bg-in-range: #4CAF50;
    --bg-low: #f44336;
    --bg-high: #FF9800;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* Navigation */
.navbar {
    background: var(--color-card);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-primary);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--color-text-light);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--color-primary);
    color: white;
}

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

/* Current BG Section */
.current-bg-section {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.current-bg-card {
    background: var(--color-card);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.3s;
}

.current-bg-card.in-range {
    border-left: 6px solid var(--bg-in-range);
}

.current-bg-card.low {
    border-left: 6px solid var(--bg-low);
    background: linear-gradient(135deg, #fff 0%, #ffebee 100%);
}

.current-bg-card.high {
    border-left: 6px solid var(--bg-high);
    background: linear-gradient(135deg, #fff 0%, #fff3e0 100%);
}

.bg-value-container {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.bg-value {
    font-size: 4rem;
    font-weight: bold;
    color: var(--color-text);
}

.current-bg-card.low .bg-value {
    color: var(--bg-low);
}

.current-bg-card.high .bg-value {
    color: var(--bg-high);
}

.current-bg-card.in-range .bg-value {
    color: var(--bg-in-range);
}

.bg-unit {
    font-size: 1.2rem;
    color: var(--color-text-light);
}

.bg-trend {
    font-size: 2.5rem;
}

.bg-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.bg-status {
    font-size: 1.1rem;
    font-weight: 500;
}

.bg-time {
    color: var(--color-text-light);
    font-size: 0.9rem;
}

/* Stats Cards */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--color-card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: bold;
}

.stat-in-range .stat-value { color: var(--bg-in-range); }
.stat-low .stat-value { color: var(--bg-low); }
.stat-high .stat-value { color: var(--bg-high); }

/* Chart Section */
.chart-section {
    background: var(--color-card);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-header h2 {
    font-size: 1.25rem;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.chart-container {
    height: 300px;
    position: relative;
}

.target-legend {
    margin-top: 1rem;
    text-align: center;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--bg-in-range);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-primary:hover {
    background: #1976D2;
}

.btn-secondary {
    background: var(--color-success);
    color: white;
}

.btn-secondary:hover {
    background: #388E3C;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

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

/* Quick Actions */
.quick-actions {
    margin-bottom: 2rem;
}

.quick-actions h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Recent Activity */
.recent-activity h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.activity-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.activity-card {
    background: var(--color-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.activity-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--color-text-light);
}

.activity-list {
    list-style: none;
}

.activity-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
}

.activity-list li:last-child {
    border-bottom: none;
}

.activity-list li.empty {
    color: var(--color-text-light);
    font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
    .current-bg-section {
        grid-template-columns: 1fr;
    }
    
    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .activity-grid {
        grid-template-columns: 1fr;
    }
    
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
        text-align: center;
    }
}

/* Settings Page */
.settings-section {
    background: var(--color-card);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.settings-section h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.profile-select {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.profile-select select {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
}

.segment-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.segment-table th,
.segment-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.segment-table th {
    background: var(--color-bg);
    font-weight: 600;
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* Log Page Styles */
.log-form {
    background: var(--color-card);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.log-form h2 {
    margin-bottom: 1.5rem;
}

.current-bg-mini {
    background: var(--color-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.current-bg-mini .value {
    font-size: 1.5rem;
    font-weight: bold;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.toast.success {
    background: var(--color-success);
}

.toast.error {
    background: var(--color-danger);
}

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

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

.modal-content {
    background: var(--color-card);
    padding: 2rem;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    margin-bottom: 0.5rem;
}

/* Dexcom Status */
.nav-dexcom {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dexcom-status {
    font-size: 0.9rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
}

.dexcom-status.connected {
    color: var(--color-success);
    background: rgba(76, 175, 80, 0.1);
}

.dexcom-status.disconnected {
    color: var(--color-text-light);
    background: rgba(0, 0, 0, 0.05);
}

/* Error Message */
.error-message {
    background: #ffebee;
    color: var(--color-danger);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Connections Page */
.connection-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.connection-header h2 {
    margin-bottom: 0.25rem;
}

.status-badge {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-badge.connected {
    background: rgba(76, 175, 80, 0.15);
    color: var(--color-success);
}

.status-badge.disconnected {
    background: rgba(0, 0, 0, 0.08);
    color: var(--color-text-light);
}

.connection-info {
    background: var(--color-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.info-row:last-child {
    border-bottom: none;
}

.connection-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

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

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

.text-success {
    color: var(--color-success);
}

.data-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-top: 1rem;
}

.data-info-card {
    background: var(--color-bg);
    padding: 1.5rem;
    border-radius: 12px;
}

.data-info-card h3 {
    margin-bottom: 1rem;
}

.data-info-card ul {
    list-style: none;
    padding: 0;
}

.data-info-card li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.data-info-card li:last-child {
    border-bottom: none;
}

.data-preview {
    background: var(--color-bg);
    padding: 1rem;
    border-radius: 8px;
}

.data-preview h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

@media (max-width: 768px) {
    .data-info-grid {
        grid-template-columns: 1fr;
    }
    
    .connection-header {
        flex-direction: column;
        gap: 1rem;
    }
}

/* ==================== MOBILE RESPONSIVE ==================== */

/* Mobile Navigation - Hamburger Menu */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--color-text);
}

@media (max-width: 768px) {
    /* Show hamburger menu button */
    .mobile-menu-toggle {
        display: block;
    }
    
    /* Hide nav links by default on mobile */
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--color-card);
        flex-direction: column;
        padding: 1rem;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        gap: 0.5rem;
    }
    
    .nav-links.active {
        display: flex;
    }
    
    .nav-links a {
        padding: 0.75rem 1rem;
        border-radius: 8px;
        text-align: center;
    }
    
    .navbar {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
        position: relative;
    }
    
    .nav-brand {
        font-size: 1.25rem;
    }
    
    /* Container padding */
    .container {
        padding: 1rem;
    }
    
    /* Current BG Section */
    .current-bg-section {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .current-bg-card {
        padding: 1.25rem;
    }
    
    .bg-value {
        font-size: 3rem;
    }
    
    /* Stats cards - 2 columns on mobile */
    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    /* Chart section */
    .chart-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .chart-header h2 {
        font-size: 1.1rem;
    }
    
    .chart-controls {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .chart-controls .btn {
        flex: 1;
        min-width: auto;
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    /* Activity grid */
    .activity-grid {
        grid-template-columns: 1fr;
    }
    
    /* Buttons */
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Tables - horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    th, td {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-group input,
    .form-group select {
        padding: 0.75rem;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
    }
    
    /* Cards */
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .summary-card {
        padding: 0.75rem;
    }
    
    .summary-card .value {
        font-size: 1.25rem;
    }
    
    /* Modal */
    .modal {
        width: 95%;
        max-width: none;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Status bar */
    .data-status-bar {
        flex-wrap: wrap;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
        font-size: 0.75rem;
    }
    
    .status-item.last-update {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
    .nav-brand {
        font-size: 1.1rem;
    }
    
    .bg-value {
        font-size: 2.5rem;
    }
    
    .stats-cards {
        grid-template-columns: 1fr 1fr;
    }
    
    .stat-card {
        padding: 0.5rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }
    
    /* Hide less important info on very small screens */
    .hide-mobile-xs {
        display: none;
    }
}

/* Touch-friendly tap targets */
@media (pointer: coarse) {
    .btn,
    .nav-links a,
    .timing-select,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    .delete-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.5rem;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .navbar {
        padding-top: calc(0.75rem + env(safe-area-inset-top));
        padding-left: calc(1rem + env(safe-area-inset-left));
        padding-right: calc(1rem + env(safe-area-inset-right));
    }
    
    .container {
        padding-left: calc(1rem + env(safe-area-inset-left));
        padding-right: calc(1rem + env(safe-area-inset-right));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}
