/* Jiva Health MiniApp - Karuna Theme */
/* Mobile-first, Telegram WebApp adaptive */

:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --primary-dark: #5A4BD1;
    --accent: #00B894;
    --accent-light: #55EFC4;
    --danger: #FF6B6B;
    --danger-light: #FFAAAA;
    --warning: #FDCB6E;
    --bg: var(--tg-theme-bg-color, #FAFAFA);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #F0F0F0);
    --text: var(--tg-theme-text-color, #2D3436);
    --text-secondary: var(--tg-theme-hint-color, #636E72);
    --card: #FFFFFF;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --border: #E0E0E0;
    --radius: 12px;
    --radius-sm: 8px;
    --spacing: 16px;
    --header-height: 0px; /* Telegram handles header */
}

/* Reset */
*, *::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, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    padding: 0 var(--spacing);
    padding-bottom: calc(var(--spacing) * 5);
    -webkit-font-smoothing: antialiased;
}

/* Typography */
h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 8px; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 4px; }
p { margin-bottom: 8px; }
small { font-size: 0.85rem; color: var(--text-secondary); }

/* Links */
a {
    color: var(--primary);
    text-decoration: none;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
    box-shadow: var(--card-shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.97);
}

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

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

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

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

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

.btn-block {
    display: flex;
    width: 100%;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.9rem;
}

.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
}

/* Quick action grid */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: var(--spacing);
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    background: var(--card);
    border-radius: var(--radius);
    border: none;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    transform: scale(0.96);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.action-btn .icon {
    font-size: 1.8rem;
    line-height: 1;
}

.action-btn .label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.action-btn.emergency {
    background: linear-gradient(135deg, #FF6B6B, #EE5A24);
    color: white;
}

.action-btn.emergency .label {
    color: white;
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing);
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
}

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

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* Tags / Chips */
.tag-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.tag {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 1.5px solid var(--border);
    background: var(--card);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

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

.tag:active {
    transform: scale(0.95);
}

/* Progress bar */
.progress-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    padding: 0 4px;
}

.progress-step {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    transition: background 0.3s;
}

.progress-step.active {
    background: var(--primary);
}

.progress-step.done {
    background: var(--accent);
}

/* Consultation list */
.consult-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 8px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text);
}

.consult-item:active {
    background: var(--bg-secondary);
}

.consult-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.consult-icon.completed { background: #E8F5E9; }
.consult-icon.in_progress { background: #FFF3E0; }
.consult-icon.emergency { background: #FFEBEE; }

.consult-info {
    flex: 1;
    min-width: 0;
}

.consult-title {
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.consult-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.consult-arrow {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #E8F5E9; color: #2E7D32; }
.badge-warning { background: #FFF3E0; color: #E65100; }
.badge-danger { background: #FFEBEE; color: #C62828; }
.badge-info { background: #E3F2FD; color: #1565C0; }

/* Health metric card */
.metric-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.metric-unit {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.metric-alert {
    padding: 8px 12px;
    background: #FFF3E0;
    border-left: 3px solid var(--warning);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
    margin-top: 4px;
}

.metric-alert.danger {
    background: #FFEBEE;
    border-color: var(--danger);
}

/* Report sections */
.report-tabs {
    display: flex;
    gap: 0;
    margin-bottom: var(--spacing);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.report-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.report-tab.active {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.report-content {
    display: none;
}

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

.report-section {
    margin-bottom: 20px;
}

.report-section h3 {
    color: var(--primary);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

/* Vitals chart container */
.chart-container {
    background: var(--card);
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
    box-shadow: var(--card-shadow);
}

.chart-canvas {
    width: 100%;
    height: 200px;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

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

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Tab nav (bottom) */
.tab-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    -webkit-tap-highlight-color: transparent;
}

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

.tab-item .tab-icon {
    font-size: 1.3rem;
}

/* Inline button group */
.inline-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inline-btn {
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.inline-btn.active {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    color: var(--primary);
}

/* Severity colors */
.severity-mild { color: var(--accent); }
.severity-moderate { color: var(--warning); }
.severity-severe { color: #E17055; }
.severity-emergency { color: var(--danger); font-weight: 700; }

/* Section header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    margin-top: 20px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.section-link {
    font-size: 0.85rem;
    color: var(--primary);
}

/* Page header */
.page-header {
    padding: 16px 0 12px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.page-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Welcome banner */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary), #8B7CF6);
    color: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: var(--spacing);
}

.welcome-name {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.welcome-sub {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Disclaimer */
.disclaimer {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-top: 20px;
    text-align: center;
    line-height: 1.4;
}

/* Patient cards */
.patient-card {
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 8px;
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.patient-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.patient-card-header:active {
    background: var(--bg-secondary);
}

.patient-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.patient-header-info {
    flex: 1;
    min-width: 0;
}

.patient-name {
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.patient-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.patient-actions-header {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.patient-detail {
    padding: 0 14px 14px;
    border-top: 1px solid var(--border);
}

.patient-detail-row {
    padding: 6px 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.detail-label {
    font-weight: 500;
    color: var(--primary);
}

/* Small icon buttons */
.btn-icon-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon-sm:active {
    transform: scale(0.9);
}

.btn-icon-sm.btn-icon-danger {
    color: var(--danger);
}

.btn-icon-sm.btn-icon-danger:active {
    background: var(--danger-light);
}

/* Consultation item with delete */
.consult-item-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.consult-item-wrapper .consult-item {
    margin-bottom: 0;
}

.btn-delete-consult {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.btn-delete-consult:active {
    background: #FFEBEE;
    border-color: var(--danger);
    color: var(--danger);
    transform: scale(0.95);
}

/* Patient selector in welcome banner */
.patient-selector-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.patient-selector-label {
    font-size: 0.85rem;
    opacity: 0.9;
    white-space: nowrap;
}

.patient-selector-select {
    flex: 1;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 0.85rem;
    -webkit-appearance: none;
    appearance: none;
}

.patient-selector-select option {
    background: var(--card);
    color: var(--text);
}

/* File upload area */
.file-upload-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-preview-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.file-preview-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.file-preview-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Attachment items (report page) */
.attachment-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.attachment-thumb {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
    flex-shrink: 0;
}

.attachment-info {
    flex: 1;
    min-width: 0;
}

.attachment-name {
    font-size: 0.9rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
