/* BP Monitor Pro - Styles */

/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f1f5f9;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;

    /* BP Classification Colors */
    --bp-normal: #22c55e;
    --bp-elevated: #eab308;
    --bp-stage1: #f97316;
    --bp-stage2: #ef4444;
    --bp-crisis: #dc2626;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Login Screen */
#login-screen {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 10px;
}

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.tagline {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group input[type="password"],
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="datetime-local"],
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.hint {
    display: block;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.checkbox-group label {
    margin-bottom: 0;
    font-weight: 400;
}

.security-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 20px;
    padding: 15px;
    background: #f0f9ff;
    border-radius: var(--radius-sm);
}

.security-note .lock-icon {
    font-size: 20px;
}

.security-note p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--background);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-large {
    padding: 14px 28px;
    font-size: 16px;
    width: 100%;
}

.btn-icon-only {
    padding: 8px 12px;
    background: transparent;
    border: none;
    font-size: 20px;
}

/* App Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Dashboard */
.dashboard-content,
.add-reading-content,
.history-content,
.charts-content,
.settings-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.date-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Latest Reading Display */
.reading-display {
    display: flex;
    justify-content: space-around;
    padding: 20px 0;
}

.reading-value {
    text-align: center;
}

.reading-value .value {
    display: block;
    font-size: 42px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.reading-value .label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-top: 5px;
}

/* Classification Badge */
.classification {
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.classification-badge {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.classification-badge.normal {
    background: #dcfce7;
    color: #166534;
}

.classification-badge.elevated {
    background: #fef9c3;
    color: #854d0e;
}

.classification-badge.stage1 {
    background: #ffedd5;
    color: #9a3412;
}

.classification-badge.stage2 {
    background: #fee2e2;
    color: #991b1b;
}

.classification-badge.crisis {
    background: #fecaca;
    color: #7f1d1d;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Charts */
.chart-container {
    position: relative;
    height: 200px;
}

.chart-container.large {
    height: 300px;
}

.range-select,
.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

/* Camera & Capture */
.capture-card {
    padding: 0;
    overflow: hidden;
}

.camera-container {
    position: relative;
    background: #000;
    aspect-ratio: 4/3;
}

#camera-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.camera-guide {
    border: 3px dashed rgba(255,255,255,0.5);
    border-radius: var(--radius);
    padding: 40px 60px;
    text-align: center;
}

.camera-guide p {
    color: rgba(255,255,255,0.8);
    font-size: 14px;
}

.image-preview-container {
    aspect-ratio: 4/3;
    background: #000;
}

.image-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.capture-actions {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: var(--surface);
}

.capture-actions .btn {
    flex: 1;
}

.upload-btn {
    cursor: pointer;
}

.ocr-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    background: #f0f9ff;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Entry Form */
.entry-card h2 {
    margin-bottom: 5px;
}

.entry-hint {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 20px;
}

.entry-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.entry-field {
    display: flex;
    flex-direction: column;
}

.entry-field label {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.entry-field input,
.entry-field select {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 18px;
    text-align: center;
    font-weight: 600;
}

.entry-field input:focus,
.entry-field select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.entry-extras {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.entry-extras .entry-field input,
.entry-extras .entry-field select {
    font-size: 14px;
    font-weight: 400;
    text-align: left;
}

.entry-field.full-width {
    grid-column: span 2;
}

/* History List */
.history-filters {
    margin-bottom: 15px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    align-items: center;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 15px;
    box-shadow: var(--shadow);
}

.history-item .date-col {
    flex: 0 0 80px;
}

.history-item .date-col .date {
    font-weight: 600;
    font-size: 14px;
}

.history-item .date-col .time {
    font-size: 12px;
    color: var(--text-secondary);
}

.history-item .values-col {
    flex: 1;
    display: flex;
    justify-content: space-around;
    text-align: center;
}

.history-item .values-col .val {
    font-size: 18px;
    font-weight: 700;
}

.history-item .values-col .lbl {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.history-item .status-col {
    flex: 0 0 30px;
    text-align: right;
}

.status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-dot.normal { background: var(--bp-normal); }
.status-dot.elevated { background: var(--bp-elevated); }
.status-dot.stage1 { background: var(--bp-stage1); }
.status-dot.stage2 { background: var(--bp-stage2); }
.status-dot.crisis { background: var(--bp-crisis); }

.history-item .delete-btn {
    display: none;
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.delete-mode .history-item .delete-btn {
    display: block;
}

.delete-mode .history-item .status-col {
    display: none;
}

/* Charts Screen */
.chart-filters {
    margin-bottom: 15px;
}

/* Stats Table */
.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th,
.stats-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.stats-table th {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.stats-table td {
    font-size: 14px;
}

.stats-table .status-good {
    color: var(--success-color);
}

.stats-table .status-warning {
    color: var(--warning-color);
}

.stats-table .status-bad {
    color: var(--danger-color);
}

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.setting-item label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.setting-item input {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 16px;
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.about-card p {
    color: var(--text-secondary);
    font-size: 14px;
}

.about-text {
    margin-top: 10px;
    line-height: 1.6;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

/* 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;
    padding: 20px;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 25px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-bottom: 15px;
    font-size: 18px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .entry-grid {
        grid-template-columns: 1fr;
    }

    .entry-extras {
        grid-template-columns: 1fr;
    }

    .entry-field.full-width {
        grid-column: span 1;
    }

    .reading-value .value {
        font-size: 32px;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) {
    .dashboard-content,
    .add-reading-content,
    .history-content,
    .charts-content,
    .settings-content {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* Print Styles */
@media print {
    .app-header,
    .action-buttons,
    .capture-card,
    .btn {
        display: none !important;
    }

    .screen {
        display: block !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
