:root {
    --em-blue: #0055ff;
    --em-dark-blue: #003db3;
    --em-light-blue: #eef4ff;
    --em-bg: #f8fafc;
    --em-white: #ffffff;
    --em-text-main: #1e293b;
    --em-text-muted: #64748b;
    --em-border: #e2e8f0;
    --em-accent: #10b981;
    --em-danger: #ef4444;
    --sidebar-width: 280px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--em-bg); color: var(--em-text-main); line-height: 1.5; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background: var(--em-white); border-right: 1px solid var(--em-border); height: 100vh; position: fixed; display: flex; flex-direction: column; z-index: 1000; }
.sidebar-brand { padding: 1.5rem; display: flex; align-items: center; gap: 0.75rem; border-bottom: 1px solid var(--em-border); color: var(--em-blue); }
.sidebar-brand h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }

.nav-section { padding: 1rem 0; flex: 1; overflow-y: auto; }
.nav-label { padding: 1rem 1.5rem 0.5rem; font-size: 0.7rem; font-weight: 800; color: var(--em-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.nav-item { padding: 0.75rem 1.5rem; display: flex; align-items: center; gap: 0.75rem; color: var(--em-text-main); cursor: pointer; font-weight: 500; font-size: 0.9rem; transition: 0.2s; }
.nav-item:hover { background: var(--em-light-blue); color: var(--em-blue); }
.nav-item.active { background: var(--em-blue); color: white; }
.nav-item i { width: 20px; text-align: center; font-size: 1rem; }

/* Main Content */
.main-stage { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }
.header { height: 64px; background: white; border-bottom: 1px solid var(--em-border); display: flex; align-items: center; justify-content: space-between; padding: 0 2rem; position: sticky; top: 0; z-index: 900; }
.search-bar { flex: 1; max-width: 450px; position: relative; }
.search-bar i { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--em-text-muted); }
.search-bar input { width: 100%; padding: 0.5rem 1rem 0.5rem 2.5rem; border: 1px solid var(--em-border); border-radius: 8px; background: var(--em-bg); outline: none; }

.content { padding: 2rem; max-width: 1200px; margin: 0 auto; width: 100%; }
.page-title { margin-bottom: 2rem; }
.page-title h2 { font-size: 1.5rem; font-weight: 700; }

/* Cards */
.em-card { background: white; border-radius: 12px; border: 1px solid var(--em-border); margin-bottom: 1.5rem; overflow: hidden; }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--em-border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 0.95rem; }
.card-body { padding: 1.5rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: white; padding: 1.25rem; border-radius: 12px; border: 1px solid var(--em-border); }
.stat-val { font-size: 1.5rem; font-weight: 700; color: var(--em-blue); }
.stat-lab { font-size: 0.75rem; font-weight: 600; color: var(--em-text-muted); text-transform: uppercase; margin-top: 0.25rem; }

/* Buttons */
.btn { padding: 0.5rem 1rem; border-radius: 6px; font-weight: 600; cursor: pointer; border: none; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.5rem; }
.btn-primary { background: var(--em-blue); color: white; }
.btn-primary:hover { background: var(--em-dark-blue); }
.btn-ghost { background: transparent; color: var(--em-blue); border: 1px solid var(--em-blue); }
.btn-ghost:hover { background: var(--em-light-blue); }
.btn-danger { background: var(--em-danger); color: white; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }

/* Tables */
.em-table { width: 100%; border-collapse: collapse; }
.em-table th { text-align: left; padding: 0.75rem 1.5rem; background: var(--em-bg); color: var(--em-text-muted); font-size: 0.7rem; text-transform: uppercase; font-weight: 800; }
.em-table td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--em-border); font-size: 0.9rem; }

/* Scripts */
.script-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.script-badge { font-size: 0.65rem; font-weight: 800; background: var(--em-light-blue); color: var(--em-blue); padding: 0.2rem 0.5rem; border-radius: 4px; text-transform: uppercase; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-content { background: white; width: 100%; max-width: 900px; border-radius: 12px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); max-height: 90vh; display: flex; flex-direction: column; }
.modal-body { padding: 2rem; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }

.hidden { display: none !important; }

/* Forms */
.field-label { display: block; font-size: 0.7rem; font-weight: 800; color: var(--em-text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.field-hint { font-size: 0.8rem; color: var(--em-text-muted); margin-bottom: 1rem; }
.em-input { width: 100%; padding: 0.75rem; border: 1px solid var(--em-border); border-radius: 8px; font-size: 0.9rem; font-family: inherit; color: var(--em-text-main); background: white; resize: vertical; }
.em-input:focus { outline: 2px solid var(--em-blue); outline-offset: -1px; }
textarea.em-input { line-height: 1.5; }
.form-group { margin-bottom: 1.25rem; }
.form-group .em-input { margin-top: 0.25rem; }

/* Output */
.output-panel { margin-top: 1rem; padding: 1rem 1.25rem; background: var(--em-bg); border: 1px solid var(--em-border); border-radius: 8px; white-space: pre-wrap; font-size: 0.9rem; line-height: 1.65; color: var(--em-text-main); max-height: 420px; overflow: auto; }
.output-panel.error { background: #fef2f2; border-color: #fecaca; color: var(--em-danger); }
.output-panel.placeholder { color: var(--em-text-muted); }
.output-foot { margin-top: 0.6rem; font-size: 0.72rem; color: var(--em-text-muted); font-style: italic; }

/* Chat */
.chat-log { height: 380px; overflow: auto; border: 1px solid var(--em-border); border-radius: 8px; background: var(--em-bg); padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.msg { max-width: 82%; padding: 0.6rem 0.9rem; border-radius: 10px; font-size: 0.9rem; line-height: 1.55; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--em-blue); color: white; }
.msg.assistant { align-self: flex-start; background: white; border: 1px solid var(--em-border); }
.msg.loading { align-self: flex-start; color: var(--em-text-muted); font-style: italic; }
.chat-input { display: flex; gap: 0.6rem; }
.chat-input input { flex: 1; margin: 0; }

/* Tool shortcuts grid on hub */
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.tool-tile { padding: 1rem; border: 1px solid var(--em-border); border-radius: 10px; background: white; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 0.75rem; }
.tool-tile:hover { background: var(--em-light-blue); border-color: var(--em-blue); color: var(--em-blue); }
.tool-tile i { width: 22px; text-align: center; color: var(--em-blue); font-size: 1.1rem; }

.info-row { display: flex; justify-content: space-between; padding: 0.6rem 0; border-bottom: 1px solid var(--em-border); font-size: 0.85rem; }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--em-text-muted); flex-shrink: 0; }
.info-row .v { font-weight: 600; min-width: 0; overflow-wrap: anywhere; text-align: right; margin-left: 1rem; }

/* Two-column helper layouts (collapsed to one column on mobile) */
.two-col, .split-cols { display: grid; gap: 1.5rem; }
.two-col { grid-template-columns: 1fr 1fr; }
.split-cols { grid-template-columns: 1.4fr 1fr; align-items: start; }

/* Session scribe */
#rec-btn.recording { background: var(--em-danger); }
#rec-btn.recording i { animation: pulse 1.2s ease-in-out infinite; }
.session-item { padding: 1rem 1.5rem; border-bottom: 1px solid var(--em-border); cursor: pointer; transition: 0.15s; }
.session-item:hover { background: var(--em-light-blue); }
.session-item .s-title { font-weight: 600; font-size: 0.9rem; display: flex; justify-content: space-between; gap: 0.75rem; }
.session-item .s-title .badge { font-size: 0.65rem; font-weight: 800; background: var(--em-light-blue); color: var(--em-blue); padding: 0.15rem 0.5rem; border-radius: 4px; text-transform: uppercase; flex-shrink: 0; }
.session-item .s-preview { font-size: 0.8rem; color: var(--em-text-muted); margin-top: 0.35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Mobile */
.hamburger { display: none; align-items: center; justify-content: center; width: 40px; height: 40px; border: none; background: transparent; color: var(--em-text-main); font-size: 1.4rem; cursor: pointer; border-radius: 8px; }
.hamburger:hover { background: var(--em-light-blue); color: var(--em-blue); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); z-index: 800; }
.sidebar-overlay.active { display: block; }
@media (max-width: 768px) {
    .sidebar { display: none; }
    .sidebar.mobile-open { display: flex !important; transform: translateX(0) !important; }
    .main-stage { margin-left: 0; }
    .header { padding: 0 1rem; }
    .hamburger { display: flex !important; }
    .search-bar { display: none; }
    .content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .tool-grid { grid-template-columns: 1fr; }
    .two-col, .split-cols { grid-template-columns: 1fr; }
    .cal-nav { flex-wrap: wrap; }
    .cal-title { min-width: 0; }
}

/* Splash Screen */
.splash-screen { position: fixed; inset: 0; background: linear-gradient(135deg, var(--em-dark-blue), var(--em-blue)); display: flex; align-items: center; justify-content: center; z-index: 9999; transition: opacity 0.3s ease; }
.splash-screen.hidden { opacity: 0; pointer-events: none; }
.splash-content { text-align: center; color: #fff; }
.splash-content i { font-size: 4rem; margin-bottom: 1rem; animation: pulse 1.5s ease-in-out infinite; }
.splash-content h2 { font-size: 1.8rem; margin-bottom: 0.5rem; }
.loading-dots { font-size: 1.2rem; }
.loading-dots span { animation: blink 1.5s infinite; opacity: 0; }
.loading-dots span:nth-child(2) { animation-delay: 0.25s; }
.loading-dots span:nth-child(3) { animation-delay: 0.5s; }
@keyframes blink { 0%,100% { opacity: 0 } 50% { opacity: 1 } }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1) } 50% { opacity: 0.5; transform: scale(0.8) } }

.sidebar { transition: transform 0.3s ease; }

/* Calendar */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.5rem; align-items: start; }
.cal-layout > .cal-main, .cal-layout > .cal-queue { min-width: 0; }
@media (max-width: 1100px) {
    .cal-layout { grid-template-columns: 1fr; }
    .cal-queue { position: static; }
}
.cal-queue { position: sticky; top: 5rem; }
.cal-queue .card-body { max-height: 60vh; overflow: auto; }
.q-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--em-border); cursor: pointer; transition: 0.15s; }
.q-row:last-child { border-bottom: none; }
.q-row:hover { background: var(--em-light-blue); }
.q-time { font-size: 0.7rem; font-weight: 700; color: var(--em-text-muted); flex-shrink: 0; min-width: 4rem; }
.cal-nav { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.cal-nav .btn { padding: 0.4rem 0.8rem; }
.cal-title { font-size: 1.1rem; font-weight: 700; min-width: 200px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--em-border); border: 1px solid var(--em-border); border-radius: 8px; overflow: hidden; }
.cal-header { background: var(--em-bg); padding: 0.5rem; text-align: center; font-size: 0.7rem; font-weight: 800; color: var(--em-text-muted); text-transform: uppercase; }
.cal-day { background: white; min-height: 100px; padding: 0.4rem; cursor: pointer; transition: 0.15s; }
.cal-day:hover { background: var(--em-light-blue); }
.cal-day.today { background: #eff6ff; }
.cal-day.other-month { opacity: 0.4; }
.cal-day-num { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--em-text-main); }
.cal-event { padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.65rem; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; color: white; cursor: pointer; }
.cal-event.blue { background: var(--em-blue); }
.cal-event.yellow { background: #f59e0b; }
.cal-event.green { background: var(--em-accent); }
.cal-event.red { background: var(--em-danger); }
.cal-more { font-size: 0.6rem; color: var(--em-text-muted); padding: 0.1rem 0.3rem; cursor: pointer; }

/* Week/Day time grid */
.cal-time-grid { display: grid; gap: 1px; background: var(--em-border); border: 1px solid var(--em-border); border-radius: 8px; overflow: hidden; }
.cal-time-label { background: var(--em-bg); padding: 0.3rem 0.5rem; font-size: 0.7rem; font-weight: 600; color: var(--em-text-muted); text-align: right; border-bottom: 1px solid var(--em-border); }
.cal-time-slot { background: white; border-bottom: 1px solid var(--em-border); min-height: 48px; position: relative; }
.cal-day-col { position: relative; background: white; border-bottom: 1px solid var(--em-border); min-height: 48px; }
.cal-week-header { background: var(--em-bg); padding: 0.5rem; text-align: center; font-size: 0.7rem; font-weight: 800; color: var(--em-text-muted); text-transform: uppercase; border-bottom: 1px solid var(--em-border); }
.cal-week-header .day-label { font-weight: 600; color: var(--em-text-main); font-size: 0.8rem; }
.cal-event-block { position: absolute; left: 2px; right: 2px; padding: 0.3rem 0.5rem; border-radius: 4px; font-size: 0.75rem; color: white; overflow: hidden; z-index: 1; }
.cal-event-block .ev-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event-block .ev-sub { font-size: 0.65rem; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Event detail panel */
.cal-detail { background: white; border: 1px solid var(--em-border); border-radius: 8px; padding: 1.5rem; margin-top: 1rem; }
.cal-detail-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; }
.cal-detail-row { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--em-border); font-size: 0.85rem; }
.cal-detail-row:last-child { border-bottom: none; }
.cal-detail-row .label { color: var(--em-text-muted); }
.cal-detail-row .value { font-weight: 600; }

/* Calendar event status classes */
.cal-scheduled { background: var(--em-blue); color: white; }
.cal-inprogress { background: #f59e0b; color: white; }
.cal-completed { background: var(--em-accent); color: white; }
.cal-cancelled { background: var(--em-danger); color: white; }

/* List rows (patients, claims, records) */
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--em-border);
  transition: 0.12s; cursor: default;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--em-light-blue); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 0.85rem; font-weight: 600; color: var(--em-text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 0.75rem; color: var(--em-text-muted); margin-top: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta { display: flex; align-items: center; gap: 0.5rem; margin-left: 1rem; flex-shrink: 0; }
.list-badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px;
  font-size: 0.7rem; font-weight: 700; background: var(--em-bg); color: var(--em-text-main);
  white-space: nowrap;
}
.list-id { font-size: 0.7rem; color: var(--em-text-muted); white-space: nowrap; }

/* Transcript validation flags */
.screc-validation { background: #fef3c7; border: 1px solid #f59e0b; border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.screc-validation.hidden { display: none; }
.validation-flags { display: flex; flex-direction: column; gap: 0.4rem; }
.validation-flag { font-size: 0.8rem; padding: 0.35rem 0.6rem; background: white; border-radius: 4px; border-left: 3px solid #f59e0b; }
.validation-flag .vf-original { color: var(--em-danger); font-weight: 600; text-decoration: line-through; }
.validation-flag .vf-suggested { color: var(--em-accent); font-weight: 600; }
.validation-flag .vf-reason { color: var(--em-text-muted); font-size: 0.75rem; }
.validation-clinical { background: #fee2e2; border-color: var(--em-danger); }
.validation-clinical .vf-original { color: var(--em-danger); }

/* Patient workspace context card */
.pat-ctx-card .card-body { padding: 1.25rem 1.5rem; }
.pat-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.pat-name { font-size: 1.05rem; font-weight: 700; color: var(--em-text-main); }
.pat-idline { font-size: 0.72rem; color: var(--em-text-muted); margin-top: 0.15rem; }
.pat-stats { display: flex; gap: 0.5rem; flex-shrink: 0; }
.pat-stat { font-size: 0.75rem; color: var(--em-text-main); background: var(--em-light-blue); border-radius: 6px; padding: 0.35rem 0.6rem; white-space: nowrap; }
.pat-stat b { color: var(--em-blue); }
.pat-history { margin-top: 0.75rem; }
.pat-picker-row { display: flex; gap: 0.5rem; }

/* Practitioner sign-in gate */
.login-screen {
  position: fixed; inset: 0; z-index: 2000;
  background: linear-gradient(135deg, var(--em-dark) 0%, #0b1d3a 100%);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 380px; background: white; border-radius: 16px;
  padding: 2.25rem 2rem; box-shadow: 0 24px 60px rgba(0,0,0,.35);
  text-align: center;
}
.login-card h2 { font-size: 1.3rem; margin: 0.4rem 0 0.1rem; color: var(--em-dark); }
.login-sub { font-size: 0.78rem; color: var(--em-text-muted); margin: 0 0 1.4rem; }
.login-brand {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 14px;
  background: var(--em-blue); display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1.4rem;
}
.login-card .em-input { margin-bottom: 0.7rem; }
.login-error { min-height: 1.1rem; font-size: 0.78rem; color: var(--em-danger); margin-top: 0.6rem; }
.login-screen.hidden { display: none; }
.sidebar-user { padding: 0.5rem 1.5rem 0; font-size: 0.72rem; color: var(--em-text-muted); }
.sidebar-user b { display: block; color: var(--em-text-main); font-size: 0.8rem; }
