:root {
    --primary: #1a1a2e;
    --primary-light: #2d2d4a;
    --primary-lighter: #3d3d5c;
    --accent: #10b981;
    --accent-light: #34d399;
    --accent-glow: rgba(16, 185, 129, 0.12);
    --accent-glow-strong: rgba(16, 185, 129, 0.25);
    --text: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --bg: #f8fafb;
    --bg-alt: #f1f5f9;
    --card: #ffffff;
    --card-hover: #fafbfc;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --danger: #ef4444;
    --warn: #f59e0b;
    --good: #10b981;
    --sidebar-w: 250px;
    --topbar-h: 60px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    color-scheme: dark;
    --primary: #0f0f1a;
    --primary-light: #1a1a2e;
    --primary-lighter: #2d2d4a;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --bg: #0f1117;
    --bg-alt: #161b22;
    --card: #1c2128;
    --card-hover: #222830;
    --border: #2d333b;
    --border-light: #21262d;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
}

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

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

/* ===== Layout ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
    overflow: hidden;
}

.sidebar-glow {
    position: absolute;
    top: -50%; right: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle at 70% 30%, rgba(16,185,129,0.06) 0%, transparent 50%);
    pointer-events: none;
    animation: sidebarPulse 6s ease-in-out infinite;
}

@keyframes sidebarPulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1.4rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: relative;
    z-index: 1;
}

.brand-icon {
    width: 38px; height: 38px;
    background: rgba(16,185,129,0.12);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid rgba(16,185,129,0.2);
    transition: transform 0.3s, box-shadow 0.3s;
}

.brand-icon:hover { transform: scale(1.05); box-shadow: 0 0 12px var(--accent-glow-strong); }
.brand-icon svg { width: 20px; height: 20px; }
.brand-text { font-size: 1.1rem; font-weight: 600; color: #fff; letter-spacing: -0.01em; }

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.8rem;
    display: flex; flex-direction: column; gap: 0.15rem;
    position: relative; z-index: 1;
}

.nav-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-size: 0.86rem;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }

.nav-item.active {
    background: rgba(16,185,129,0.12);
    color: var(--accent);
}

.nav-item.active::before {
    content: '';
    position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 60%; border-radius: 0 3px 3px 0;
    background: var(--accent);
}

.nav-svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 0.8rem 0.5rem; }

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    position: relative; z-index: 1;
}

.sidebar-version { font-family: 'DM Mono', monospace; font-size: 0.65rem; color: rgba(255,255,255,0.25); margin-bottom: 0.3rem; }
.sidebar-disclaimer { font-size: 0.68rem; color: rgba(255,255,255,0.3); line-height: 1.5; }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
    border: none;
    cursor: default;
    padding: 0;
}

/* ===== Main Area ===== */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

.top-bar {
    height: var(--topbar-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 50;
    backdrop-filter: blur(8px);
    background: rgba(255,255,255,0.85);
}

[data-theme="dark"] .top-bar { background: rgba(28,33,40,0.85); }

.menu-toggle {
    display: none;
    background: none; border: none;
    cursor: pointer; color: var(--text);
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    display: none; align-items: center; justify-content: center;
    transition: background var(--transition);
}

.menu-toggle:hover { background: var(--bg-alt); }
.menu-toggle svg { width: 20px; height: 20px; }

.top-bar-right { display: flex; align-items: center; gap: 0.5rem; }

.top-btn {
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    border: none; background: none;
    cursor: pointer; color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.top-btn:hover { background: var(--bg-alt); color: var(--text); }
.top-btn svg { width: 20px; height: 20px; }

/* Theme toggle icons */
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: block; }

.notification-badge {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    background: var(--danger); color: #fff;
    font-size: 0.6rem; font-weight: 600;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* User Menu */
.user-menu { position: relative; }

.user-btn {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    border: none; background: none;
    cursor: pointer; color: var(--text);
    font-family: inherit; font-size: 0.82rem;
    transition: background var(--transition);
}

.user-btn:hover { background: var(--bg-alt); }

.user-avatar {
    width: 30px; height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 600;
}

.user-name { font-weight: 500; }

.user-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: 0.4rem;
    display: none;
    animation: dropIn 0.2s ease;
    z-index: 200;
}

.user-dropdown.show { display: block; }

@keyframes dropIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition);
    width: 100%;
    border: none;
    background: none;
    font-family: inherit;
    text-align: left;
}

.dropdown-item:hover { background: var(--bg-alt); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 0.3rem 0; }

/* Notification Panel */
.notification-panel {
    position: absolute; top: calc(var(--topbar-h) + 4px); right: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 320px;
    display: none;
    animation: dropIn 0.2s ease;
    z-index: 200;
}

.notification-panel.show { display: block; }

.notif-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem; font-weight: 600;
}

.notif-clear { background: none; border: none; color: var(--accent); font-size: 0.75rem; cursor: pointer; font-family: inherit; }
.notif-list { max-height: 300px; overflow-y: auto; padding: 0.5rem; }
.notif-empty { text-align: center; padding: 2rem; color: var(--text-light); font-size: 0.82rem; }

.notif-item {
    display: flex; gap: 0.6rem; padding: 0.7rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.notif-item:hover { background: var(--bg-alt); }
.notif-icon { font-size: 1.1rem; flex-shrink: 0; }
.notif-text { font-size: 0.78rem; color: var(--text-muted); }
.notif-time { font-size: 0.65rem; color: var(--text-light); margin-top: 0.2rem; }

/* ===== Page Content ===== */
.page-content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Page transition */
.page-enter {
    animation: pageIn 0.3s ease both;
}

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

/* ===== Page Header ===== */
.page-header { margin-bottom: 1.8rem; }

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.page-desc { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ===== Stats Row ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem 1.5rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

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

.stat-card.mini { padding: 1rem 1.2rem; flex-direction: column; align-items: flex-start; gap: 0.2rem; }
.stat-icon { font-size: 1.5rem; }

.stat-value {
    font-family: 'DM Mono', monospace;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text);
}

.stat-card.mini .stat-value { font-size: 1.2rem; }

.stat-label {
    font-size: 0.72rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-good { color: var(--good); }
.status-warn { color: var(--warn); }
.status-danger { color: var(--danger); }
.status-neutral { color: var(--text-muted); }

/* ===== Section ===== */
.section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.2rem;
    box-shadow: var(--shadow-sm);
}

.section-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
    display: flex; align-items: center; gap: 0.5rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    display: inline-flex; align-items: center; gap: 0.4rem;
}

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

[data-theme="dark"] .btn-primary { background: var(--accent); color: #fff; }

.btn-primary:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26,26,46,0.2);
}

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

.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.76rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ===== Forms ===== */
.form-row {
    display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
}

.form-group { flex: 1; min-width: 140px; }

.form-group label {
    display: block;
    font-size: 0.73rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all var(--transition);
}

.form-group input:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--card);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%236b7280' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
}

.form-action { min-width: auto; flex: 0; }

/* ===== Tags ===== */
.tag {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 500;
    background: var(--bg-alt);
    color: var(--text-muted);
}

.tag-green { background: rgba(16,185,129,0.1); color: #059669; }
.tag-orange { background: rgba(245,158,11,0.1); color: #d97706; }
.tag-red { background: rgba(239,68,68,0.1); color: #dc2626; }
.tag-good { background: rgba(16,185,129,0.1); color: #059669; }
.tag-warn { background: rgba(245,158,11,0.1); color: #d97706; }
.tag-danger { background: rgba(239,68,68,0.1); color: #dc2626; }

/* ===== Quick Grid ===== */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}

.quick-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.quick-card::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, transparent 60%, var(--accent-glow) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.quick-card:hover {
    border-color: var(--accent);
    transform: translateY(-4px) perspective(600px) rotateX(2deg);
    box-shadow: 0 12px 30px var(--accent-glow);
}

.quick-card:hover::after { opacity: 1; }

.quick-icon { font-size: 1.5rem; margin-bottom: 0.6rem; position: relative; z-index: 1; }
.quick-title { font-size: 0.88rem; font-weight: 600; margin-bottom: 0.2rem; position: relative; z-index: 1; }
.quick-desc { font-size: 0.73rem; color: var(--text-muted); position: relative; z-index: 1; }

/* ===== Alerts ===== */
.alert-list { display: flex; flex-direction: column; gap: 0.6rem; }

.alert-item {
    display: flex; align-items: flex-start; gap: 0.7rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    animation: pageIn 0.3s ease both;
}

.alert-danger { background: rgba(239,68,68,0.06); border: 1px solid rgba(239,68,68,0.15); }
.alert-warning { background: rgba(245,158,11,0.06); border: 1px solid rgba(245,158,11,0.15); }
.alert-icon { font-size: 1.1rem; flex-shrink: 0; }
.alert-msg { font-size: 0.84rem; font-weight: 500; color: var(--text); }
.alert-action { font-size: 0.76rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ===== Reminders ===== */
.reminder-list { display: flex; flex-direction: column; gap: 0.5rem; }

.reminder-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.7rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.reminder-item:hover { border-color: var(--accent); }
.reminder-med { font-size: 0.86rem; font-weight: 500; }
.reminder-time { font-size: 0.76rem; color: var(--text-muted); }

/* ===== Chat ===== */
.chat-container {
    display: flex; flex-direction: column;
    height: calc(100vh - var(--topbar-h) - 7rem);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 1rem;
}

.chat-msg { display: flex; gap: 0.7rem; max-width: 85%; }
.chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-assistant { align-self: flex-start; }

.msg-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; flex-shrink: 0;
    background: var(--bg-alt);
    border: 1px solid var(--border);
}

.chat-msg-assistant .msg-avatar { background: var(--accent-glow); border-color: rgba(16,185,129,0.2); }

.msg-bubble {
    padding: 0.8rem 1.1rem;
    border-radius: 14px;
    font-size: 0.86rem;
    line-height: 1.7;
}

.chat-msg-user .msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant .msg-bubble {
    background: var(--bg-alt);
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.msg-badge {
    margin-top: 0.5rem;
    font-size: 0.68rem;
    color: var(--accent);
    font-weight: 500;
    display: flex; align-items: center; gap: 0.3rem;
}

.msg-sources {
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.msg-source-item {
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 0.2rem 0;
}

.msg-suggestions {
    display: flex; flex-wrap: wrap; gap: 0.4rem;
    margin-top: 0.6rem;
}

.suggest-chip {
    padding: 0.3rem 0.7rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 0.72rem;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.suggest-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

.chat-examples {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
}

.examples-title { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.7rem; }

.examples-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.example-btn {
    padding: 0.4rem 0.9rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.76rem;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.example-btn:hover { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

.chat-input-area {
    display: flex; gap: 0.7rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.chat-input {
    flex: 1;
    padding: 0.7rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    font-family: inherit;
    color: var(--text);
    background: var(--card);
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    transition: border-color var(--transition);
}

.chat-input:focus-visible { border-color: var(--accent); }

.chat-send-btn {
    padding: 0.7rem 1.5rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition), transform var(--transition);
    align-self: flex-end;
}

.chat-send-btn:hover { background: var(--primary-light); transform: translateY(-1px); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Typing animation */
.typing-indicator { display: flex; gap: 4px; padding: 0.5rem 0; }
.typing-dot {
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== Data Table ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

.data-table th {
    text-align: left;
    padding: 0.7rem 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table td {
    padding: 0.65rem 0.8rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

.data-table tr:hover td { background: var(--bg-alt); }

/* ===== Risk Card ===== */
.risk-card {
    padding: 1.2rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
}

.risk-good { border-left-color: var(--good); background: rgba(16,185,129,0.04); }
.risk-warn { border-left-color: var(--warn); background: rgba(245,158,11,0.04); }
.risk-danger { border-left-color: var(--danger); background: rgba(239,68,68,0.04); }

.risk-level { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; }
.risk-factors, .risk-recs { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ===== Medication Cards ===== */
.med-card {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.6rem;
    transition: border-color var(--transition);
}

.med-card:hover { border-color: var(--accent); }
.med-name { font-weight: 600; font-size: 0.9rem; }
.med-detail { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }
.med-notes { font-size: 0.73rem; color: var(--text-light); margin-top: 0.2rem; }

/* ===== Recommend Cards ===== */
.recommend-card {
    padding: 1rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.6rem;
    border-left: 3px solid var(--border);
    transition: box-shadow var(--transition);
}

.recommend-card:hover { box-shadow: var(--shadow-sm); }
.priority-good { border-left-color: var(--good); }
.priority-warn { border-left-color: var(--warn); }
.priority-danger { border-left-color: var(--danger); }

.recommend-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.recommend-icon { font-size: 1.1rem; }
.recommend-category { font-weight: 600; font-size: 0.86rem; }
.recommend-text { font-size: 0.82rem; color: var(--text-muted); line-height: 1.6; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 1.2rem; flex-wrap: wrap; }

.filter-btn {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card);
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.filter-btn.active, .filter-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== Knowledge Graph ===== */
.search-bar { display: flex; gap: 0.7rem; }

.search-input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color var(--transition);
}

.search-input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.kg-entity-card {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.8rem;
    transition: border-color var(--transition);
}

.kg-entity-card:hover { border-color: var(--accent); }
.entity-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.entity-name { font-weight: 600; font-size: 0.92rem; }
.entity-attrs { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.attr-item { margin-bottom: 0.2rem; }
.entity-relations { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.relation-tag {
    font-size: 0.68rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg-alt);
    border-radius: 4px;
    color: var(--text-muted);
}

/* ===== Report ===== */
.report-content { font-size: 0.84rem; line-height: 1.7; color: var(--text); }
.report-content h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.report-content h4 { font-size: 0.9rem; margin: 0.8rem 0 0.4rem; }
.report-content li { margin-left: 1.2rem; margin-bottom: 0.3rem; }

/* ===== Empty & Loading ===== */
.empty-state {
    text-align: center;
    padding: 2.5rem;
    color: var(--text-light);
    font-size: 0.84rem;
}

.page-loading { display: flex; justify-content: center; padding: 4rem; }

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

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

/* ===== Skeleton ===== */
.skeleton-page { padding: 0; }
.skeleton-header { height: 32px; width: 200px; background: var(--bg-alt); border-radius: 6px; margin-bottom: 1.5rem; animation: shimmer 1.5s infinite; }
.skeleton-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.skeleton-card { height: 100px; background: var(--bg-alt); border-radius: var(--radius); animation: shimmer 1.5s infinite; }
.skeleton-block { height: 300px; background: var(--bg-alt); border-radius: var(--radius); animation: shimmer 1.5s infinite; }

@keyframes shimmer {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* ===== Toast ===== */
#toast-container {
    position: fixed; top: 1rem; right: 1rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    z-index: 9999;
    pointer-events: none;
}

.toast {
    padding: 0.75rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.toast.show { transform: translateX(0); }
.toast-success { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.toast-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.toast-info { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }

[data-theme="dark"] .toast-success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .toast-error { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
[data-theme="dark"] .toast-info { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .sidebar.open + .sidebar-overlay { display: block; }
    .main-area { margin-left: 0; }
    .menu-toggle { display: flex; }
    .page-content { padding: 1.2rem; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .form-row { flex-direction: column; }
    .form-group { min-width: 100%; }
    .quick-grid { grid-template-columns: 1fr 1fr; }
    .chat-container { height: calc(100vh - var(--topbar-h) - 5rem); }
    .user-name { display: none; }
}

@media (max-width: 480px) {
    .stats-row { grid-template-columns: 1fr; }
    .quick-grid { grid-template-columns: 1fr; }
}

/* ===== Home Hero ===== */
.home-hero {
    display: flex;
    align-items: center;
    gap: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.8rem 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.home-hero::before {
    content: '';
    position: absolute;
    top: -50%; right: -20%;
    width: 300px; height: 300px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    pointer-events: none;
}

.hero-score { flex-shrink: 0; position: relative; z-index: 1; }
.score-ring { width: 120px; height: 120px; }

.hero-info { position: relative; z-index: 1; }
.hero-status { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.3rem; }
.hero-tip { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.hero-bp { font-size: 0.82rem; color: var(--text-muted); }
.hero-bp strong { color: var(--text); font-family: 'DM Mono', monospace; }

/* ===== Home Grid ===== */
.home-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.2rem;
    margin-bottom: 1.2rem;
}

@media (max-width: 768px) {
    .home-grid { grid-template-columns: 1fr; }
    .home-hero { flex-direction: column; text-align: center; }
}

/* ===== Heatmap ===== */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    background: var(--bg-alt);
    transition: transform 0.15s;
}

.heatmap-cell:hover { transform: scale(1.3); }
.heatmap-cell.level-0 { background: var(--bg-alt); }
.heatmap-cell.level-1 { background: rgba(16,185,129,0.25); }
.heatmap-cell.level-2 { background: rgba(16,185,129,0.5); }
.heatmap-cell.level-3 { background: rgba(16,185,129,0.8); }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 0.6rem;
    font-size: 0.65rem;
    color: var(--text-light);
}

.heatmap-legend .heatmap-cell { width: 12px; height: 12px; aspect-ratio: auto; }

/* ===== Quick Card SVG ===== */
.quick-svg {
    width: 28px; height: 28px;
    margin-bottom: 0.6rem;
    color: var(--accent);
    position: relative; z-index: 1;
}

/* ===== Cursor blink (typewriter) ===== */
.cursor-blink {
    animation: blink 0.8s infinite;
    color: var(--accent);
    font-weight: 300;
}

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

/* ===== Timeline ===== */
.timeline { position: relative; padding-left: 1.5rem; }

.timeline::before {
    content: '';
    position: absolute; left: 6px; top: 0; bottom: 0;
    width: 2px; background: var(--border);
}

.timeline-item {
    position: relative;
    padding: 0 0 1.5rem 1.5rem;
}

.timeline-dot {
    position: absolute; left: -1.5rem; top: 4px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--card);
    box-shadow: 0 0 0 2px var(--border);
}

.timeline-item.completed .timeline-dot { background: var(--good); box-shadow: 0 0 0 2px rgba(16,185,129,0.3); }
.timeline-item.pending .timeline-dot { background: var(--warn); box-shadow: 0 0 0 2px rgba(245,158,11,0.3); }

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

.timeline-header {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.timeline-date { font-size: 0.75rem; color: var(--text-muted); font-family: 'DM Mono', monospace; }

.timeline-details {
    font-size: 0.8rem; color: var(--text-muted);
    line-height: 1.7;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* ===== Upcoming Cards ===== */
.upcoming-list { display: flex; flex-direction: column; gap: 0.6rem; }

.upcoming-card {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem 1.2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.upcoming-date { font-family: 'DM Mono', monospace; font-size: 0.82rem; font-weight: 500; color: var(--text); min-width: 90px; }
.upcoming-info { flex: 1; display: flex; align-items: center; gap: 0.5rem; }
.upcoming-notes { font-size: 0.78rem; color: var(--text-muted); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.8rem;
    width: 90%; max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: dropIn 0.25s ease;
}

/* ===== Checkin ===== */
.checkin-list { display: flex; flex-direction: column; gap: 0.5rem; }

.checkin-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.8rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), background var(--transition);
}

.checkin-item.checked { border-color: var(--good); background: rgba(16,185,129,0.04); }

.checkin-info { display: flex; flex-direction: column; }
.checkin-name { font-size: 0.88rem; font-weight: 500; }
.checkin-detail { font-size: 0.73rem; color: var(--text-muted); margin-top: 0.1rem; }

.checkin-btn {
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--text-muted);
    font-family: inherit;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.checkin-btn:hover { border-color: var(--accent); color: var(--accent); }
.checkin-btn.done { background: var(--good); color: #fff; border-color: var(--good); cursor: default; }

.adherence-bar {
    height: 8px;
    background: var(--bg-alt);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.adherence-fill {
    height: 100%;
    background: var(--good);
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ===== Evidence Chain (Chat) ===== */
.evidence-panel {
    margin-top: 0.8rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
}

.evidence-toggle {
    font-size: 0.72rem;
    color: var(--accent);
    cursor: pointer;
    background: none; border: none;
    font-family: inherit;
    font-weight: 500;
    display: flex; align-items: center; gap: 0.3rem;
}

.evidence-toggle:hover { text-decoration: underline; }

.evidence-content {
    margin-top: 0.5rem;
    display: none;
}

.evidence-content.show { display: block; }

.evidence-section {
    margin-bottom: 0.6rem;
}

.evidence-label {
    font-size: 0.68rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.3rem;
}

.evidence-item {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.4rem 0.6rem;
    background: var(--bg-alt);
    border-radius: 4px;
    margin-bottom: 0.3rem;
    line-height: 1.5;
}

.evidence-entity {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    background: var(--accent-glow);
    border: 1px solid rgba(16,185,129,0.2);
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--accent);
    cursor: pointer;
    margin: 0.15rem;
    transition: all var(--transition);
}

.evidence-entity:hover { background: rgba(16,185,129,0.2); }

.confidence-badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 500;
}

.confidence-high { background: rgba(16,185,129,0.1); color: #059669; }
.confidence-partial { background: rgba(245,158,11,0.1); color: #d97706; }
.confidence-none { background: rgba(107,114,128,0.1); color: #6b7280; }

/* ===== Dimension Grid (KG) ===== */
.dimension-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.dimension-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.dimension-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.dimension-card.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.dimension-icon { font-size: 1.5rem; margin-bottom: 0.4rem; }
.dimension-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.dimension-count { font-size: 0.68rem; color: var(--text-light); margin-top: 0.2rem; }
