:root {
    --color-primary: #4A6DFF;
    --color-primary-dark: #3B5BD9;
    --color-bg: #F5F6FA;
    --color-card: #FFFFFF;
    --color-text: #333333;
    --color-text-light: #888888;
    --color-border: #E8E8E8;
    --color-hipotensao: #3498DB;
    --color-normal: #2ECC71;
    --color-pre: #F1C40F;
    --color-estagio1: #E67E22;
    --color-estagio2: #E74C3C;
    --nav-height: 64px;
    --header-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    height: 100%;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

#app {
    height: 100vh;
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow: hidden;
    overflow-x: hidden;
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    height: 100%;
    width: 100%;
    max-width: 100vw;
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden;
}
.screen.active { display: flex; }

/* ===== LOGIN ===== */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
}

.login-icon {
    font-size: 72px;
    margin-bottom: 16px;
}

.login-container h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 16px;
    color: var(--color-text-light);
    margin-bottom: 40px;
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 320px;
    padding: 14px 24px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: #fff;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.2s;
}

.btn-google:hover {
    background: #fafafa;
    transform: translateY(-1px);
}

.google-icon {
    width: 20px;
    height: 20px;
}

.login-info {
    margin-top: 16px;
    font-size: 13px;
    color: var(--color-text-light);
}

/* ===== HEADER ===== */
.app-header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 10;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-user img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.header-user span {
    font-size: 15px;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    color: var(--color-text);
}

/* ===== TAB CONTENT ===== */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
}
.tab-content.active { display: block; }

/* ===== PRESSURE BAR ===== */
.pressure-bar-container {
    background: #fff;
    border-radius: 16px;
    padding: 20px 16px;
    margin-bottom: 16px;
    text-align: center;
    position: relative;
}

.pressure-label {
    font-size: 18px;
    font-weight: 700;
    font-style: italic;
    margin-bottom: 12px;
    color: var(--color-normal);
    transition: color 0.3s;
}

.pressure-bar {
    display: flex;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.pressure-bar-segment {
    flex: 1;
}

.pressure-bar-segment.hipotensao { background: var(--color-hipotensao); }
.pressure-bar-segment.normal { background: var(--color-normal); }
.pressure-bar-segment.pre { background: var(--color-pre); }
.pressure-bar-segment.estagio1 { background: var(--color-estagio1); }
.pressure-bar-segment.estagio2 { background: var(--color-estagio2); }

.pressure-indicator {
    font-size: 20px;
    margin-top: 8px;
    transition: transform 0.3s;
}

/* ===== INPUTS ===== */
.inputs-container {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 100%;
}

.input-group {
    background: #fff;
    border-radius: 16px;
    padding: 16px 8px;
    text-align: center;
    flex: 1;
    min-width: 0;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
}

.input-group .unit {
    font-size: 12px;
    color: var(--color-text-light);
    margin-bottom: 8px;
    display: block;
}

.number-picker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.number-picker input {
    width: 60px;
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    border: none;
    background: none;
    color: var(--color-primary);
    -moz-appearance: textfield;
}

.number-picker input::-webkit-outer-spin-button,
.number-picker input::-webkit-inner-spin-button { -webkit-appearance: none; }

.btn-adjust {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--color-bg);
    font-size: 18px;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.btn-adjust:active { background: #e0e0e0; }

/* ===== METADATA ===== */
.metadata-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 100%;
}

.metadata-item {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.metadata-item .icon { font-size: 16px; }

.metadata-item input,
.metadata-item select {
    border: none;
    background: none;
    font-size: 14px;
    color: var(--color-text);
    width: 100%;
    outline: none;
    font-family: inherit;
}

/* ===== BUTTONS ===== */
.btn-primary {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--color-primary);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 16px;
    transition: background 0.2s;
}

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

.btn-secondary {
    padding: 12px 20px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}

.btn-camera {
    width: 100%;
    padding: 14px;
    border: 2px dashed var(--color-primary);
    border-radius: 12px;
    background: rgba(74,109,255,0.05);
    color: var(--color-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.camera-icon { font-size: 20px; }

#file-input { display: none; }

.ocr-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 12px;
    color: var(--color-text-light);
    font-size: 13px;
}

.ocr-divider::before,
.ocr-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* ===== REFERENCE TABLE ===== */
.reference-table {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.ref-header {
    display: grid;
    grid-template-columns: 20px 1fr 70px 70px;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text-light);
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
    min-width: 280px;
}

.ref-row {
    display: grid;
    grid-template-columns: 20px 1fr 70px 70px;
    gap: 8px;
    align-items: center;
    padding: 8px 0;
    font-size: 14px;
    color: var(--color-text-light);
    min-width: 280px;
}

.ref-row.active {
    font-weight: 700;
    color: var(--color-text);
}

.ref-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

/* ===== HISTORY ===== */
.history-header {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.search-box {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-box input {
    border: none;
    background: none;
    font-size: 14px;
    width: 100%;
    outline: none;
    font-family: inherit;
}

#filter-zone {
    border: none;
    background: #fff;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--color-primary);
    font-weight: 600;
    font-family: inherit;
    outline: none;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.history-badge {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.history-badge .top { font-size: 16px; }

.history-info {
    flex: 1;
}

.history-info .category {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}

.history-info .meta {
    font-size: 13px;
    color: var(--color-text-light);
}

.history-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.history-actions .tag-icon {
    font-size: 12px;
    color: var(--color-text-light);
}

.history-actions .delete-btn {
    background: none;
    border: none;
    color: #ccc;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state.hidden { display: none; }

.empty-icon { font-size: 48px; margin-bottom: 12px; }

.empty-state p { font-size: 16px; font-weight: 600; }

.empty-state .empty-sub {
    font-size: 14px;
    color: var(--color-text-light);
    font-weight: 400;
    margin-top: 4px;
}

/* ===== STATISTICS ===== */
.stats-circles {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
}

.stat-circle {
    text-align: center;
}

.circle-bg {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 4px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.circle-label {
    font-size: 11px;
    color: var(--color-text-light);
    font-weight: 600;
}

.circle-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
}

.circle-sublabel {
    font-size: 12px;
    font-weight: 700;
}

.stat-circle:nth-child(1) .circle-sublabel { color: var(--color-estagio2); }
.stat-circle:nth-child(2) .circle-sublabel { color: var(--color-normal); }
.stat-circle:nth-child(3) .circle-sublabel { color: var(--color-hipotensao); }

.stats-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.stats-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-light);
    cursor: pointer;
    font-family: inherit;
}

.stats-tab.active {
    color: var(--color-primary);
}

.chart-container {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    height: 280px;
    position: relative;
}

.chart-container canvas { max-height: 100%; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #fff;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--color-text-light);
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}

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

.nav-icon { font-size: 20px; }

/* ===== MODALS ===== */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.active { display: flex; }

.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    background: #fff;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 1;
    padding: 24px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.menu-content { padding: 0; overflow: hidden; }

.menu-header {
    padding: 24px;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-header img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.menu-user-info {
    display: flex;
    flex-direction: column;
}

.menu-user-info span:first-child {
    font-weight: 700;
    font-size: 16px;
}

.menu-user-info span:last-child {
    font-size: 13px;
    color: var(--color-text-light);
}

.menu-items { padding: 8px 0; }

.menu-item {
    width: 100%;
    padding: 14px 24px;
    border: none;
    background: none;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    color: var(--color-text);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.menu-item:hover { background: #f9f9f9; }

.menu-icon { font-size: 20px; width: 28px; text-align: center; }

.menu-danger { color: var(--color-estagio2); }

.menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: 8px 0;
}

.btn-close-menu {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.1);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    z-index: 2;
}

#menu-user-photo, #user-photo { display: none; }
#menu-user-photo[src]:not([src=""]), #user-photo[src]:not([src=""]) { display: block; }

/* Manual Entry Modal */
.manual-content h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.modal-sub {
    font-size: 13px;
    color: var(--color-text-light);
    margin-bottom: 16px;
}

.manual-entry-row {
    display: grid;
    grid-template-columns: 1.3fr 1fr 0.8fr 0.8fr 0.8fr;
    gap: 6px;
    margin-bottom: 8px;
}

.manual-entry-row input,
.manual-entry-row select {
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    width: 100%;
}

.btn-add-row {
    width: 100%;
    padding: 12px;
    border: 1px dashed var(--color-border);
    border-radius: 8px;
    background: none;
    color: var(--color-primary);
    font-size: 14px;
    cursor: pointer;
    margin-bottom: 16px;
    font-family: inherit;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* OCR Modal */
.ocr-preview {
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
    max-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ocr-preview img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
}

.ocr-status {
    text-align: center;
    padding: 20px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.ocr-results.hidden { display: none; }
.ocr-status.hidden { display: none; }

.ocr-values { margin: 12px 0; }

.ocr-values div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}

.ocr-values input {
    width: 80px;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
}

/* Import file input */
#import-file { display: none; }

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 300;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Settings placeholder */
.settings-placeholder {
    text-align: center;
    padding: 60px 20px;
}

/* Responsive */
@media (max-width: 360px) {
    .number-picker input { width: 50px; font-size: 24px; }
    .circle-bg { width: 76px; height: 76px; }
    .circle-value { font-size: 20px; }
    .ref-header,
    .ref-row {
        grid-template-columns: 16px 1fr 60px 60px;
        gap: 4px;
        font-size: 12px;
    }
}

/* ===== UPDATE BANNER ===== */
.update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 500;
    background: var(--color-primary);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    transform: translateY(-100%);
    transition: transform 0.4s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.update-banner.show {
    transform: translateY(0);
}

.update-icon {
    font-size: 18px;
}

.update-text {
    font-weight: 600;
}

.update-btn {
    background: #fff;
    color: var(--color-primary);
    border: none;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
    font-family: inherit;
}

.update-btn:active {
    opacity: 0.8;
}
