@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    /* --- Premium Colors --- */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-muted: #f1f5f9;
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    
    --border-light: #e2e8f0;
    --border-hover: #cbd5e1;
    
    /* Brand Accent */
    --accent: #0284c7;
    --accent-hover: #0369a1;
    --accent-soft: #f0f9ff;
    
    /* Semantic Colors */
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --success: #10b981;
    --success-soft: #dcfce7;
    --success-text: #166534;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --warning-text: #b45309;
    
    /* --- Premium Shadows (Apple Style) --- */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.03), 0 2px 4px -2px rgb(0 0 0 / 0.03);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --shadow-xl: 0 20px 40px -10px rgba(15, 23, 42, 0.08);
    --shadow-modal: 0 24px 48px rgba(15, 23, 42, 0.2);
    
    /* --- Focus & Radius --- */
    --focus-ring: 0 0 0 3px rgba(56, 189, 248, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-xxl: 24px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* --- Авторизация --- */
.auth-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-main); }
.auth-box {
    background: var(--bg-surface); padding: 48px 40px; border-radius: var(--radius-xxl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light); width: 380px; text-align: center;
}
.auth-box h1 { color: var(--text-primary); margin-bottom: 8px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.auth-box p { color: var(--text-secondary); margin-bottom: 32px; font-size: 15px; }
.auth-box input {
    width: 100%; padding: 14px 16px; background: var(--bg-muted); border: 1px solid transparent;
    border-radius: var(--radius-md); font-size: 15px; margin-bottom: 16px; outline: none; transition: all 0.2s;
}
.auth-box input:focus {
    background: var(--bg-surface); border-color: #38bdf8;
    box-shadow: var(--focus-ring);
}
.auth-box .error { color: var(--danger); font-size: 13px; margin-bottom: 16px; font-weight: 500; }

/* --- Layout: sidebar + main --- */
.app { display: none; height: 100vh; }
.app.visible { display: grid; grid-template-columns: 260px 1fr; }

/* --- Sidebar (Light Premium) --- */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}

/* Кастомный скроллбар */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

.sidebar-header {
    padding: 32px 24px 24px;
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo-mark {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 800;
    color: white;
    line-height: 1;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}

.sidebar-logo span { color: var(--accent); }

.sidebar-sub {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
    margin-top: 6px;
    margin-left: 44px;
}

/* Навигация */
.sidebar-nav {
    flex: 1;
    padding: 0 16px;
    overflow-y: auto;
}

.nav-group { margin-bottom: 12px; }

.nav-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    padding: 12px 12px 8px;
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    width: 100%;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    font-family: inherit;
    position: relative;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg-main);
    color: var(--text-primary);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: all 0.2s;
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 600;
}

.nav-item.active svg {
    opacity: 1;
    color: var(--accent);
}

.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--danger);
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    margin-left: auto;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}

/* Футер с переключателем ролей */
.sidebar-footer {
    padding: 20px 16px;
    border-top: 1px solid var(--border-light);
}

.sidebar-role-panel {
    margin-bottom: 16px;
}

.role-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 8px;
    padding-left: 4px;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    width: 100%;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.logout-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

/* --- Main area --- */
.main {
    overflow-y: auto; height: 100vh; background: var(--bg-main);
}
.content { max-width: 1120px; margin: 0 auto; padding: 32px 32px; }
.section { display: none; animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.section.active { display: block; }

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

/* --- Карточки --- */
.card {
    background: var(--bg-surface); border-radius: var(--radius-xl); padding: 32px; margin-bottom: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}
.card h2 { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 24px; letter-spacing: -0.02em; }
.card h3 { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 16px; }

/* --- Формы --- */
label {
    display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 8px; margin-top: 24px;
}
label:first-child { margin-top: 0; }
input, select, textarea {
    width: 100%; padding: 12px 16px; background: var(--bg-main); border: 1px solid var(--border-light);
    border-radius: var(--radius-md); font-size: 14px; outline: none; font-family: inherit;
    color: var(--text-primary); transition: all 0.2s;
}
select {
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6L8 10L12 6' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 14px center; background-size: 16px;
    padding-right: 40px; cursor: pointer;
}
input:focus, select:focus, textarea:focus {
    background: var(--bg-surface); border-color: #38bdf8;
    box-shadow: var(--focus-ring);
}
textarea { resize: vertical; min-height: 100px; }

/* --- Кнопки --- */
.btn {
    display: inline-flex; justify-content: center; align-items: center;
    padding: 12px 24px; border-radius: var(--radius-md); border: none; font-size: 14px;
    font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--text-primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: #1e293b; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-secondary { background: var(--bg-muted); color: var(--text-secondary); }
.btn-secondary:hover { background: var(--border-light); color: var(--text-primary); }
.btn-small { padding: 8px 16px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-row { margin-top: 32px; display: flex; gap: 12px; flex-wrap: wrap; }

/* --- Списки --- */
.patient-list { list-style: none; }
.patient-item {
    padding: 16px; border-bottom: 1px solid var(--bg-muted); display: flex;
    align-items: center; justify-content: space-between; cursor: pointer;
    transition: all 0.2s; border-radius: var(--radius-md); margin-bottom: 4px;
}
.patient-item:hover { background: var(--bg-main); transform: translateX(4px); border-bottom-color: transparent; }
.patient-name { font-weight: 600; color: var(--text-primary); font-size: 15px; }
.patient-phone { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

.record-item {
    padding: 16px; background: var(--bg-surface); border: 1px solid var(--border-light);
    border-radius: var(--radius-md); margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.record-item .date { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.record-item .procedure { font-weight: 700; color: var(--text-primary); margin: 8px 0 4px; font-size: 15px; }
.record-item .meta { font-size: 13px; color: var(--text-secondary); }

/* --- Прочее --- */
.search-input { margin-bottom: 24px; }
.msg { padding: 14px 16px; border-radius: var(--radius-md); margin-top: 16px; font-size: 14px; font-weight: 500; }
.msg-ok { background: var(--success-soft); color: var(--success-text); border: 1px solid #dcfce7; }
.msg-err { background: var(--danger-soft); color: var(--danger); border: 1px solid #fee2e2; }
.empty { text-align: center; color: var(--text-tertiary); padding: 48px; font-size: 15px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; margin-right: 6px; }
.badge-cyan { background: var(--accent-soft); color: var(--accent-hover); }
.badge-amber { background: var(--warning-soft); color: var(--warning-text); }
.badge-green { background: var(--success-soft); color: var(--success-text); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: var(--bg-muted); color: var(--text-secondary); }
.hidden { display: none; }

/* --- Дашборд --- */
.dashboard-metrics {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px;
}
.metric-card {
    background: var(--bg-surface); border-radius: var(--radius-lg); padding: 24px;
    border: 1px solid var(--border-light); box-shadow: var(--shadow-sm);
}
.metric-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.metric-value { font-size: 32px; font-weight: 700; color: var(--text-primary); margin: 8px 0 4px; letter-spacing: -0.02em; }
.metric-trend { font-size: 13px; font-weight: 600; }
.trend-up { color: var(--success); }
.trend-neutral { color: var(--text-secondary); }

.dashboard-body { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.dashboard-sidebar { display: flex; flex-direction: column; gap: 16px; }
.dashboard-sidebar .card { margin-bottom: 0; }
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }
.sidebar-actions .btn { width: 100%; justify-content: center; }

.today-schedule { display: flex; flex-direction: column; gap: 12px; }
.schedule-item {
    display: flex; align-items: center; gap: 16px; padding: 16px;
    background: var(--bg-main); border-radius: var(--radius-md); border: 1px solid var(--border-light);
}
.schedule-time { font-size: 16px; font-weight: 700; color: var(--accent); min-width: 50px; }
.schedule-info { flex: 1; }
.schedule-patient { font-weight: 600; color: var(--text-primary); font-size: 14px; }
.schedule-procedure { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.schedule-doctor { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* --- Переключатель ролей (iOS Segmented Control) --- */
.role-switcher {
    display: flex;
    background: var(--bg-main);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}
.role-btn {
    flex: 1; padding: 6px 4px; border: none; background: transparent;
    font-size: 11px; font-weight: 600; color: var(--text-secondary);
    cursor: pointer; border-radius: 8px; transition: all 0.2s;
    font-family: inherit; white-space: nowrap;
}
.role-btn:hover { color: var(--text-primary); }
.role-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* Скрытие элементов по ролям */
.app.role-doctor [data-role-hide~="doctor"],
.app.role-admin [data-role-hide~="admin"] { display: none !important; }

/* --- Канбан --- */
.kanban-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; min-height: 400px; }
.kanban-column {
    background: var(--bg-main); border-radius: var(--radius-lg); padding: 16px;
    border: 2px dashed transparent; transition: border-color 0.2s;
}
.kanban-column.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.kanban-column-header {
    font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px;
    display: flex; justify-content: space-between; align-items: center;
}
.kanban-count { font-size: 11px; font-weight: 600; color: var(--text-tertiary); background: var(--border-light); padding: 2px 8px; border-radius: 10px; }
.kanban-card {
    background: var(--bg-surface); border-radius: var(--radius-md); padding: 14px; margin-bottom: 10px;
    border: 1px solid var(--border-light); cursor: grab; transition: all 0.15s;
    box-shadow: var(--shadow-sm);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.kanban-card.dragging { opacity: 0.5; }
.kanban-card-name { font-weight: 600; font-size: 14px; color: var(--text-primary); margin-bottom: 4px; }
.kanban-card-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.kanban-progress { height: 6px; background: var(--border-light); border-radius: 3px; overflow: hidden; }
.kanban-progress-bar { height: 100%; background: var(--success); border-radius: 3px; transition: width 0.3s; }
.kanban-card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 11px; color: var(--text-tertiary); }

/* --- Command Palette --- */
.cmd-palette { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding-top: 20vh; }
.cmd-palette.hidden { display: none; }
.cmd-backdrop { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); }
.cmd-dialog {
    position: relative; background: var(--bg-surface); border-radius: var(--radius-lg); width: 560px; max-width: 90vw;
    box-shadow: var(--shadow-modal); border: 1px solid var(--border-light); overflow: hidden;
}
.cmd-input-wrap {
    display: flex; align-items: center; gap: 10px; padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
}
.cmd-input-wrap input {
    flex: 1; border: none; outline: none; font-size: 15px; background: transparent;
    padding: 0; margin: 0; box-shadow: none;
}
.cmd-kbd {
    font-size: 10px; font-weight: 600; color: var(--text-tertiary); background: var(--bg-muted);
    padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border-light);
}
.cmd-results { max-height: 320px; overflow-y: auto; }
.cmd-group-label {
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-tertiary); padding: 10px 18px 4px;
}
.cmd-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 18px;
    cursor: pointer; transition: background 0.1s; font-size: 14px; color: var(--text-primary);
}
.cmd-item:hover, .cmd-item.cmd-active { background: var(--accent-soft); }
.cmd-item-icon { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; }
.cmd-item-label { flex: 1; }
.cmd-item-hint { font-size: 11px; color: var(--text-tertiary); }
.cmd-empty { padding: 24px 18px; text-align: center; color: var(--text-tertiary); font-size: 14px; }

/* --- Skeleton loaders --- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--border-light) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm);
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text-lg { height: 32px; margin-bottom: 8px; }
.skeleton-card { height: 72px; margin-bottom: 12px; border-radius: var(--radius-md); }
.skeleton-metric { height: 80px; border-radius: var(--radius-lg); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* --- Расписание-календарь --- */
.schedule-header {
    display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.schedule-date-info {
    flex: 1; text-align: center; display: flex; align-items: center; justify-content: center; gap: 12px;
}
.schedule-date-text { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.schedule-grid {
    display: grid; gap: 0; border: 1px solid var(--border-light); border-radius: var(--radius-md); overflow: hidden;
}
.schedule-cell {
    padding: 4px 6px; border-bottom: 1px solid var(--bg-muted); border-right: 1px solid var(--bg-muted);
    min-height: 32px; font-size: 12px; position: relative;
}
.schedule-corner { background: var(--bg-main); }
.schedule-doctor-header {
    background: var(--bg-main); text-align: center; padding: 10px 6px;
    border-bottom: 2px solid var(--border-light);
}
.schedule-doctor-name { font-weight: 600; font-size: 12px; color: var(--text-primary); }
.schedule-doctor-spec { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; }
.schedule-time {
    font-size: 11px; color: var(--text-tertiary); text-align: right; padding-right: 8px;
    display: flex; align-items: center; justify-content: flex-end;
    background: #fafbfc;
}
.schedule-time-hour { font-weight: 600; color: var(--text-secondary); }
.schedule-empty { cursor: default; }
.schedule-addable { cursor: pointer; transition: background 0.15s; }
.schedule-addable:hover { background: var(--accent-soft); }
.schedule-addable:hover::after {
    content: '+'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    font-size: 16px; color: var(--accent); font-weight: 700; opacity: 0.5;
}
.schedule-visit {
    border-radius: 6px; padding: 4px 8px; cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s; min-height: 32px;
}
.schedule-visit:hover { transform: scale(1.02); box-shadow: var(--shadow-sm); }
.schedule-visit-time { font-size: 10px; font-weight: 600; }
.schedule-visit-patient { font-size: 11px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.schedule-visit-proc { font-size: 10px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.schedule-visit-cont { border-radius: 6px; cursor: pointer; min-height: 32px; }
.schedule-visit-cont:hover { opacity: 0.8 !important; }

/* Popup расписания */
.schedule-popup { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.schedule-popup.hidden { display: none; }
.schedule-popup-backdrop { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px); }
.schedule-popup-dialog {
    position: relative; background: var(--bg-surface); border-radius: var(--radius-xl); padding: 28px;
    box-shadow: var(--shadow-modal); max-width: 480px; width: 90%;
    border: 1px solid var(--border-light);
}

/* --- Универсальная модалка --- */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px); }
.modal-dialog {
    position: relative; background: var(--bg-surface); border-radius: var(--radius-xl); padding: 28px;
    box-shadow: var(--shadow-modal); max-width: 560px; width: 90%;
    border: 1px solid var(--border-light); max-height: 85vh; overflow-y: auto;
    animation: fadeIn 0.2s ease;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; color: var(--text-primary); }
.modal-close {
    background: none; border: none; cursor: pointer; padding: 4px 8px;
    color: var(--text-tertiary); font-size: 20px; line-height: 1; border-radius: var(--radius-sm); transition: all 0.15s;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-muted); }

/* --- Tab-switcher (переиспользуемый) --- */
.tab-switcher {
    display: flex; gap: 2px; background: var(--bg-muted);
    border-radius: 10px; padding: 3px;
}
.tab-btn {
    flex: 1; padding: 8px 12px; border: none; background: transparent;
    font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
    border-radius: var(--radius-sm); transition: all 0.2s; font-family: inherit;
    white-space: nowrap; text-align: center;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { background: var(--bg-surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* Fix: дыра в grid при скрытии метрики выручки */
.app.role-doctor .dashboard-metrics,
.app.role-admin .dashboard-metrics { grid-template-columns: repeat(3, 1fr); }

/* Recall-блок */
.recall-card { border-left: 4px solid var(--warning); }
.recall-list { display: flex; flex-direction: column; gap: 8px; }

/* --- Зубная карта --- */
.tooth-chart-wrapper { overflow-x: auto; }
.tooth-group:hover .tooth-shape { filter: brightness(0.9); }
.tooth-selected .tooth-shape { stroke: var(--accent) !important; stroke-width: 2.5 !important; }

.tooth-legend {
    display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
    margin-top: 16px; padding: 12px; background: var(--bg-main); border-radius: var(--radius-md);
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.legend-dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

.tooth-detail-panel {
    margin-top: 24px; padding: 24px; background: var(--bg-main);
    border: 1px solid var(--border-light); border-radius: var(--radius-lg);
}

.treatment-summary { padding: 20px; background: var(--bg-main); border-radius: var(--radius-md); }
.summary-grid { display: flex; gap: 24px; flex-wrap: wrap; }
.summary-item { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); }
.summary-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.summary-total { margin-top: 16px; font-size: 18px; color: var(--text-primary); padding-top: 16px; border-top: 1px solid var(--border-light); }

/* --- Маркетинг --- */
.segments-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.segment-card {
    padding: 20px; background: var(--bg-main); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    cursor: pointer; transition: all 0.2s;
}
.segment-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.segment-active { border-color: var(--accent) !important; background: var(--accent-soft) !important; box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.1); }
.segment-icon { font-size: 28px; margin-bottom: 8px; }
.segment-name { font-weight: 700; color: var(--text-primary); font-size: 15px; }
.segment-count { font-size: 13px; color: var(--accent); font-weight: 600; margin: 4px 0; }
.segment-desc { font-size: 12px; color: var(--text-tertiary); }

.campaign-funnel { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.funnel-step { text-align: center; }
.funnel-value { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.funnel-label { font-size: 11px; color: var(--text-tertiary); }
.funnel-arrow { color: var(--border-hover); font-size: 18px; }

/* --- Запросы --- */
.request-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.request-icon { font-size: 20px; }
.request-filter { cursor: pointer; transition: all 0.2s; }
.request-filter:hover { border-color: var(--accent); }
.filter-active { border-color: var(--accent) !important; background: var(--accent-soft) !important; }

/* --- Patient Picker (кастомный dropdown) --- */
.patient-picker { position: relative; }
.pp-trigger {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px;
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-md);
    cursor: pointer; transition: all 0.2s; user-select: none;
}
.pp-trigger:hover { border-color: var(--border-hover); background: var(--bg-main); }
.pp-avatar {
    width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
    background: linear-gradient(135deg, #00B4D8, #3A7BD5);
    color: #fff; font-weight: 700; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    letter-spacing: 0.02em;
}
.pp-selected-info { flex: 1; min-width: 0; }
.pp-selected-name { font-weight: 600; font-size: 14px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-selected-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 1px; }

.pp-dropdown {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    overflow: hidden; animation: fadeIn 0.2s ease;
}
.pp-search-wrap { padding: 12px 12px 8px; }
.pp-search {
    width: 100%; padding: 10px 14px; background: var(--bg-main); border: 1px solid var(--border-light);
    border-radius: 10px; font-size: 13px; outline: none; margin: 0;
}
.pp-search:focus { background: var(--bg-surface); border-color: #38bdf8; box-shadow: var(--focus-ring); }
.pp-list { max-height: 280px; overflow-y: auto; padding: 4px 8px 8px; }
.pp-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    border-radius: 10px; cursor: pointer; transition: background 0.15s;
}
.pp-item:hover { background: var(--bg-main); }
.pp-item-active { background: var(--accent-soft); }
.pp-item .pp-avatar { width: 32px; height: 32px; font-size: 11px; border-radius: 8px; }
.pp-item-info { flex: 1; min-width: 0; }
.pp-item-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.pp-item-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 1px; }
.pp-empty { padding: 24px; text-align: center; color: var(--text-tertiary); font-size: 13px; }

/* --- План лечения: split layout --- */
.treatment-split {
    display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start;
}
.treatment-left { min-width: 0; }
.treatment-right { position: sticky; top: 16px; }

/* --- План лечения: прогресс и стоимость --- */
.treatment-progress-card {
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.progress-bar-bg {
    width: 100%; height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden;
}
.progress-bar-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    transition: width 0.4s ease;
}
.treatment-cost-card {
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.cost-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--bg-muted);
}
.cost-row:last-child { border-bottom: none; }

.treatment-teeth-list {
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    padding: 20px; box-shadow: var(--shadow-sm);
}
.tooth-list-item {
    display: flex; align-items: center; gap: 12px; padding: 12px;
    border-radius: var(--radius-md); cursor: pointer; transition: background 0.2s;
    border-bottom: 1px solid var(--bg-muted);
}
.tooth-list-item:last-child { border-bottom: none; }
.tooth-list-item:hover { background: var(--bg-main); }
.tooth-list-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tooth-list-info { flex: 1; }
.tooth-list-name { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.tooth-list-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tooth-list-price { font-weight: 700; font-size: 14px; color: var(--text-primary); white-space: nowrap; }

/* --- Адаптивность --- */
@media (max-width: 1100px) {
    .dashboard-body { grid-template-columns: 1fr; }
    .treatment-split { grid-template-columns: 1fr; }
    .treatment-right { position: static; }
}
@media (max-width: 900px) {
    .app.visible { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: -280px; top: 0; width: 260px; z-index: 100;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: none;
    }
    .sidebar.open { left: 0; box-shadow: 12px 0 40px rgba(0, 0, 0, 0.4); }
    .mobile-header {
        display: flex !important; align-items: center; gap: 12px;
        padding: 16px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border-light);
        position: sticky; top: 0; z-index: 50;
    }
    .mobile-overlay {
        position: fixed; inset: 0; background: rgba(15, 23, 42, 0.3); z-index: 99;
        display: none;
    }
    .mobile-overlay.open { display: block; }
}
@media (min-width: 901px) {
    .mobile-header { display: none !important; }
    .mobile-overlay { display: none !important; }
}
@media (max-width: 768px) {
    .dashboard-metrics { grid-template-columns: repeat(2, 1fr); }
    .segments-grid { grid-template-columns: 1fr; }
    .content { padding: 20px 16px; }
}
@media (max-width: 480px) {
    .dashboard-metrics { grid-template-columns: 1fr; }
    .campaign-funnel { flex-direction: column; gap: 4px; }
    .funnel-arrow { transform: rotate(90deg); }
}
