/* ══════════════════════════════════════════════════════════════════
   VITALINK - DESIGN SYSTEM
   ══════════════════════════════════════════════════════════════════ */

:root {
    --primary: #4F8CF7;
    --primary-dark: #3A6FD8;
    --primary-light: #E8F0FE;
    --primary-glow: rgba(79, 140, 247, 0.3);
    --success: #34C759;
    --success-light: #E5F9ED;
    --warning: #FF9F0A;
    --warning-light: #FFF3E0;
    --danger: #FF3B30;
    --danger-light: #FFE5E3;
    --info: #5AC8FA;
    --info-light: #E3F6FD;

    --bg: #F5F7FA;
    --bg-card: #FFFFFF;
    --bg-sidebar: #1A1D2E;
    --bg-sidebar-hover: #252840;
    --bg-sidebar-active: #2D3154;

    --text: #1A1D2E;
    --text-secondary: #5A6178;
    --text-muted: #9CA3B8;
    --text-sidebar: #B8BDD0;
    --text-sidebar-active: #FFFFFF;

    --border: #E2E6EF;
    --border-light: #F0F2F7;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
}

/* ═══ RESET & BASE ═══ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

input, select, button, textarea {
    font-family: inherit;
    font-size: inherit;
}

.hidden { display: none !important; }

/* ═══ SCREEN MANAGEMENT ═══ */
.screen {
    display: none;
    min-height: 100vh;
}
.screen.active {
    display: flex;
}

/* ══════════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════════════════════════════════ */

.login-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.login-left {
    flex: 1;
    background: linear-gradient(135deg, #1A1D2E 0%, #2D3154 50%, #4F8CF7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.login-left::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(79, 140, 247, 0.15) 0%, transparent 50%);
    animation: floatBg 15s ease-in-out infinite;
}

@keyframes floatBg {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -20px); }
}

.brand-hero {
    text-align: center;
    color: white;
    position: relative;
    z-index: 1;
}

.logo-pulse {
    width: 120px;
    height: 120px;
    margin: 0 auto 2rem;
}

.logo-svg {
    width: 100%;
    height: 100%;
}

.pulse-ring {
    animation: pulse 2s ease-in-out infinite;
    transform-origin: center;
}

@keyframes pulse {
    0% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.05); }
    100% { opacity: 0.3; transform: scale(1); }
}

.brand-name {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 0.75rem;
}

.brand-name span {
    color: var(--primary);
}

.brand-tagline {
    font-size: 1.1rem;
    opacity: 0.8;
    max-width: 360px;
    margin: 0 auto 2rem;
    line-height: 1.6;
}

.feature-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.pill {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.15);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.85rem;
    backdrop-filter: blur(4px);
}

.login-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
}

.login-card h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group label small {
    font-weight: 400;
    color: var(--text-muted);
}

.input-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon > svg {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.input-icon input {
    width: 100%;
    padding: 0.8rem 3.1rem 0.8rem 2.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: var(--transition);
    background: var(--bg-card);
}

.input-icon input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.toggle-pass {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 2;
}
.toggle-pass svg {
    position: static;
    width: 18px;
    height: 18px;
    color: inherit;
    pointer-events: none;
}
.toggle-pass:hover { color: var(--primary); }
.toggle-pass:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.error-msg {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.demo-hint {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--primary-light);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
}

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
}
.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 0.9rem;
    font-size: 1rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

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

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: #2AA84A;
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════════ */

#screen-dashboard {
    display: none;
}
#screen-dashboard.active {
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand {
    color: white;
    font-size: 1.2rem;
    letter-spacing: -0.5px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
}
.sidebar-toggle:hover {
    background: var(--bg-sidebar-hover);
}

.sidebar-menu {
    list-style: none;
    padding: 0.75rem 0.5rem;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin: 2px 0;
    color: var(--text-sidebar);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    font-size: 0.9rem;
}

.menu-item:hover {
    background: var(--bg-sidebar-hover);
    color: white;
}

.menu-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
}

.menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    width: 3px;
    height: 28px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

.user-role {
    color: var(--text-sidebar);
    font-size: 0.75rem;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
}
.btn-logout:hover {
    background: rgba(255,59,48,0.2);
    color: var(--danger);
}

/* ══════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════════ */

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: var(--transition);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 4px;
}

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

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.device-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.current-time {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ═══ CONTENT SECTIONS ═══ */
.content-section {
    display: none;
    padding: 2rem;
    animation: fadeIn 0.3s ease;
}

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

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

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* ═══ STATS GRID ═══ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-patients .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-meds .stat-icon { background: var(--info-light); color: var(--info); }
.stat-reminders .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-confirmed .stat-icon { background: var(--success-light); color: var(--success); }

.stat-number {
    font-size: 1.75rem;
    font-weight: 800;
    display: block;
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ═══ DASHBOARD GRID ═══ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
}

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

.card-body {
    padding: 1.25rem;
    max-height: 400px;
    overflow-y: auto;
}

/* ═══ EMPTY STATE ═══ */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.95rem;
    margin-top: 0.75rem;
    font-weight: 500;
}

.empty-state small {
    font-size: 0.8rem;
    display: block;
    margin-top: 0.25rem;
}

/* ═══ DATA TABLE ═══ */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg);
}

.data-table th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: 0.85rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: var(--transition);
}

.data-table tbody tr:hover {
    background: var(--primary-light);
}

.data-table .actions {
    display: flex;
    gap: 0.5rem;
}

/* ═══ BADGES ═══ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-waiting { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ═══ TIMELINE ═══ */
.timeline {
    position: relative;
}

.timeline-item {
    display: flex;
    gap: 1rem;
    padding: 1rem 0;
    position: relative;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 19px;
    top: 44px;
    bottom: -8px;
    width: 2px;
    background: var(--border);
}

.timeline-item:last-child::before {
    display: none;
}

.timeline-dot {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
    border: 3px solid var(--bg);
    position: relative;
    z-index: 1;
}

.timeline-dot.pending { background: var(--warning-light); }
.timeline-dot.active { background: var(--primary-light); animation: pulseTimeline 1.5s infinite; }
.timeline-dot.done { background: var(--success-light); }

@keyframes pulseTimeline {
    0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
    50% { box-shadow: 0 0 0 8px transparent; }
}

.timeline-content {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 1rem;
    border: 1px solid var(--border-light);
}

.timeline-content h4 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.timeline-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.timeline-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.timeline-meta span {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ═══ DEVICE PANEL ═══ */
.device-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

.device-visual {
    display: flex;
    justify-content: center;
}

.device-box {
    background: linear-gradient(145deg, #1A1D2E, #2D3154);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.device-screen {
    background: #0D1117;
    border-radius: var(--radius-sm);
    padding: 1rem 1.5rem;
    text-align: center;
    width: 100%;
    border: 1px solid rgba(79, 140, 247, 0.3);
}

.device-time {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    font-family: 'Courier New', monospace;
}

.device-status-text {
    color: var(--text-sidebar);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.compartments {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    width: 100%;
}

.compartment {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    padding: 1rem 0.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.compartment span {
    color: var(--text-sidebar);
    font-size: 0.75rem;
    font-weight: 600;
}

.led {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #333;
    border: 2px solid #444;
    transition: var(--transition);
}

.led.active {
    background: var(--success);
    box-shadow: 0 0 12px var(--success), 0 0 24px rgba(52, 199, 89, 0.3);
    animation: ledPulse 0.8s infinite;
}

@keyframes ledPulse {
    0%, 100% { box-shadow: 0 0 12px var(--success); }
    50% { box-shadow: 0 0 24px var(--success), 0 0 36px rgba(52, 199, 89, 0.3); }
}

.device-buzzer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-sidebar);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    transition: var(--transition);
}

.device-buzzer.active {
    background: rgba(255, 159, 10, 0.2);
    border-color: var(--warning);
    color: var(--warning);
    animation: buzzerAnim 0.5s infinite alternate;
}

@keyframes buzzerAnim {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.confirm-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.1);
    border: 2px solid rgba(255,255,255,0.15);
    color: var(--text-sidebar);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

.confirm-btn:not(:disabled):hover {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.confirm-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.confirm-btn.ready {
    background: var(--success);
    border-color: var(--success);
    color: white;
    animation: pulseBtn 1.5s infinite;
}

@keyframes pulseBtn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.5); }
    50% { box-shadow: 0 0 0 10px transparent; }
}

.device-info-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.info-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow);
}

.info-card h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-indicator.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ═══ ALGORITHM FLOWCHART ═══ */
.algorithm-container {
    overflow-x: auto;
    padding: 1rem 0;
}

.algorithm-flow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    min-width: 600px;
    padding: 2rem;
}

.algo-node {
    position: relative;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    cursor: default;
    max-width: 420px;
    width: 100%;
}

.algo-node:hover {
    transform: scale(1.03);
}

.algo-node.highlight {
    animation: highlightNode 0.6s ease;
}

@keyframes highlightNode {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.algo-terminal {
    background: linear-gradient(135deg, #1A1D2E, #2D3154);
    color: white;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
}

.algo-process {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    color: var(--text);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.algo-decision {
    background: var(--warning-light);
    border: 2px solid var(--warning);
    color: var(--text);
    padding: 1rem 1.5rem;
    transform: none;
    border-radius: var(--radius-sm);
    position: relative;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 260px;
    margin: 0 auto;
}

.algo-decision-text {
    background: var(--warning-light);
    border: 2px solid var(--warning);
    color: var(--text);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
    position: relative;
}

.algo-decision-text::before {
    content: '◆';
    position: absolute;
    left: -24px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--warning);
    font-size: 1.2rem;
}

.algo-io {
    background: var(--primary-light);
    border: 2px solid var(--primary);
    color: var(--text);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
    transform: skewX(-5deg);
}

.algo-io > span {
    display: block;
    transform: skewX(5deg);
}

.algo-connector {
    width: 2px;
    height: 24px;
    background: var(--border);
    position: relative;
}

.algo-connector::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: -4px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--border);
}

.algo-branch {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    width: 100%;
    max-width: 640px;
}

.algo-branch-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.algo-branch-yes,
.algo-branch-no {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.algo-group-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 1rem 0 0.5rem;
    padding: 0.4rem 1rem;
    background: var(--primary-light);
    border-radius: 50px;
}

.algo-loop {
    background: var(--info-light);
    border: 2px dashed var(--info);
    color: var(--text);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-sm);
}

/* ═══ MODALS ═══ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body input,
.modal-body select {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: var(--transition);
    background: var(--bg);
}

.modal-body input:focus,
.modal-body select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ═══ TOAST ═══ */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    font-weight: 500;
    font-size: 0.9rem;
    animation: toastIn 0.4s ease;
    border-left: 4px solid var(--success);
}

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

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

/* ═══ FILTER ═══ */
.filter-group select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--bg-card);
    cursor: pointer;
}

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

/* ═══ UPCOMING REMINDER ITEMS ═══ */
.reminder-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    border-bottom: 1px solid var(--border-light);
}

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

.reminder-item:hover {
    background: var(--bg);
}

.reminder-time {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 55px;
    font-variant-numeric: tabular-nums;
}

.reminder-details {
    flex: 1;
}

.reminder-details .med-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.reminder-details .patient-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.reminder-comp {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 50px;
    background: var(--primary-light);
    color: var(--primary);
}

/* ═══ ACTIVITY ITEM ═══ */
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

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

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

.activity-text {
    flex: 1;
}

.activity-text p {
    font-size: 0.85rem;
    line-height: 1.4;
}

.activity-text small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .device-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .login-container {
        flex-direction: column;
    }
    .login-left {
        padding: 2rem;
        min-height: auto;
    }
    .brand-name {
        font-size: 2rem;
    }
    .login-right {
        padding: 2rem;
    }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-menu-btn {
        display: block;
    }
    .content-section {
        padding: 1rem;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .topbar {
        padding: 0.75rem 1rem;
    }
    .section-header {
        flex-direction: column;
    }
    .algo-branch {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .compartments {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ═══ AUTENTICACIÓN REAL: registro y verificación ═══ */
.auth-switch { text-align: center; margin-top: 1.2rem; color: var(--text-secondary); font-size: .88rem; }
.auth-link { background: none; border: none; color: var(--primary-dark); font-weight: 700; cursor: pointer; text-decoration: underline; padding: .15rem; }
.auth-link:hover { color: var(--primary); }
.auth-field { width: 100%; background: var(--bg-card); border: 2px solid var(--border); border-radius: var(--radius-sm); padding: .82rem 1rem; outline: none; }
.auth-field:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-glow); }
.auth-message { margin: .8rem 0 1rem; padding: .85rem 1rem; border-radius: var(--radius-sm); font-size: .87rem; line-height: 1.5; background: var(--danger-light); color: #a5211a; }
.auth-message.success { background: var(--success-light); color: #166a33; }
.auth-message.warning { background: var(--warning-light); color: #7a4c00; }
.auth-message.info { background: var(--primary-light); color: #28539a; }

/* ═══ REGISTRO: mostrar contraseña y validación visual ═══ */
.register-password-wrap { position: relative; }
.register-password-wrap .auth-field { padding-right: 3.4rem; }
.register-password-wrap .register-toggle-pass { right: 10px; top: 50%; transform: translateY(-50%); }
.password-match-feedback { margin-top: .45rem; font-size: .82rem; line-height: 1.4; }
.password-match-feedback.is-valid { color: #166a33; }
.password-match-feedback.is-invalid { color: #b42318; }
#register-confirm[aria-invalid="true"] { border-color: var(--danger); }
#register-confirm[aria-invalid="false"]:not(:placeholder-shown) { border-color: var(--success); }

/* ═══ RECUPERACIÓN DE CONTRASEÑA ═══ */
#new-password-confirm[aria-invalid="true"] { border-color: var(--danger); }
#new-password-confirm[aria-invalid="false"]:not(:placeholder-shown) { border-color: var(--success); }
#new-password-submit:disabled { opacity: .55; cursor: not-allowed; }


/* ═══ AYUDA PARA CORREOS: sugerencias y verificación antes de enviarlos ═══ */
.email-help {
    margin-top: .55rem;
    padding: .7rem .85rem;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    line-height: 1.6;
    background: var(--primary-light);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.email-help.email-help-warning { background: var(--warning-light); color: #764300; border-color: #f3d6a6; }
.email-help.email-help-error { background: var(--danger-light); color: #a5211a; border-color: #f4bbb8; }
.email-help-action {
    display: inline-block;
    margin: .25rem .45rem 0 0;
    padding: .18rem .3rem;
    background: none;
    border: 0;
    color: var(--primary-dark);
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}
.email-help-action-muted { color: var(--text-secondary); }
.email-help-action:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.auth-field[aria-invalid="true"], #login-email[aria-invalid="true"] { border-color: var(--danger); }

/* VitaLink V3: estado real de sincronización (no del ESP32) */
.cloud-status-row { display:flex; align-items:center; flex-wrap:wrap; gap:0.75rem; padding:0.8rem 2rem 0; }
.cloud-banner { flex:1; font-size:0.82rem; color:#20588f; padding:0.65rem 1rem; background:#e8f0fe; border:1px solid #bad3fd; border-radius:8px; }
.cloud-banner.cloud-error { background:#ffe5e3; color:#a5221d; border-color:#ffbdb9; }
@media (max-width:768px) { .cloud-status-row {padding:0.75rem 1rem 0;} }
