/* === Base === */
html, body { height: 100%; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, Arial, sans-serif; background: #0b1220; color: #e6e9ef; }
* { box-sizing: border-box; }
a { color: #5b9cf5; text-decoration: none; }
a:hover { text-decoration: underline; }

.container { width: 100%; min-height: 100vh; margin: 0; padding: 16px; }
.index-container { display: grid; grid-template-rows: auto auto auto 1fr; gap: 10px; height: 100vh; }

/* === Components === */
.box { background: #121a2b; border: 1px solid #1f2a44; border-radius: 8px; padding: 12px; margin: 0; }
h2 { margin: 8px 0; font-size: 17px; }
h3 { margin: 8px 0; font-size: 15px; }
ul, ol { padding-left: 18px; margin: 6px 0 0; }
li { margin: 4px 0; line-height: 1.4; }
.small { opacity: .85; font-size: 13px; }

/* === Buttons === */
button, .btn { background: #2b6de8; color: #fff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; }
button:hover, .btn:hover { opacity: .9; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #1a243a; border: 1px solid #2b6de8; color: #5b9cf5; }
.btn-secondary.active { background: #dc3545; border-color: #dc3545; color: #fff; }
.btn-warning { background: #f59e0b; color: #000; }
.btn-small { background: #1a243a; border: 1px solid #1f2a44; color: #e6e9ef; padding: 4px 10px; border-radius: 4px; font-size: 12px; cursor: pointer; }
.btn-small:hover { background: #22335a; }
.btn-link { display: inline-block; padding: 8px 12px; color: #5b9cf5; font-size: 14px; }
.btn-export { background: #1a6d3a; }

/* === Inputs === */
.input-dark { background: #0e1626; color: #e6e9ef; border: 1px solid #1f2a44; border-radius: 6px; padding: 8px 10px; font-size: 14px; outline: none; }
.input-dark:focus { border-color: #2b6de8; }
textarea.textarea-dark { width: 100%; height: 100%; min-height: 0; background: #0e1626; color: #e6e9ef; border: 1px solid #1f2a44; border-radius: 6px; padding: 10px 12px; font-family: inherit; font-size: 15px; line-height: 1.4; outline: none; resize: none; }

/* === Layout: Top Row === */
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* === Layout: Grid === */
.grid-main { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: 0; overflow: hidden; }
.column-left, .column-right { min-width: 0; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
#transcriptBox { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
#transcriptBody { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; position: relative; }
.partial-text { position: absolute; bottom: 4px; left: 12px; right: 12px; color: #5b9cf5; font-style: italic; font-size: 14px; pointer-events: none; }

/* === Microphone === */
.mic-btn { font-size: 20px; padding: 8px 14px; background: #1a243a; border: 2px solid #2b6de8; transition: all .2s; }
.mic-btn:hover { background: #22335a; }
.mic-btn.recording { background: #dc3545; border-color: #dc3545; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* === Speaker indicator === */
.speaker-indicator { font-size: 12px; padding: 2px 8px; border-radius: 10px; margin-left: 8px; }

/* === Patient bar === */
.patient-bar { display: flex; align-items: center; gap: 10px; position: relative; }
.patient-label { font-size: 14px; color: #5b9cf5; }
.patient-results { position: absolute; top: 100%; left: 0; z-index: 100; background: #121a2b; border: 1px solid #1f2a44; border-radius: 6px; max-height: 200px; overflow-y: auto; width: 300px; }
.patient-results.hidden { display: none; }
.patient-item { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.patient-item:hover { background: #1a243a; }

/* === Confidence bar === */
.conf-bar { display: inline-flex; align-items: center; gap: 6px; width: 120px; }
.conf-bar .conf-fill { height: 8px; border-radius: 4px; transition: width .3s; }
.conf-bar span { font-size: 12px; font-weight: 600; min-width: 35px; }

/* === Red flags === */
.red-flag-banner { background: #2d0a0a; border: 2px solid #dc3545; border-radius: 8px; padding: 12px 16px; display: flex; align-items: flex-start; gap: 12px; animation: rfPulse 2s infinite; }
.red-flag-banner.hidden { display: none; }
.red-flag-icon { background: #dc3545; color: #fff; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; flex-shrink: 0; }
.red-flag-content { flex: 1; }
.red-flag-close { background: none; border: none; color: #e6e9ef; font-size: 20px; cursor: pointer; padding: 0 4px; }
.rf-item { margin: 4px 0; }
.rf-critical { color: #f87171; }
.rf-high { color: #fb923c; }
.rf-medium { color: #fbbf24; }
.rf-action { font-size: 13px; opacity: .9; margin-top: 2px; }
@keyframes rfPulse { 0%, 100% { border-color: #dc3545; } 50% { border-color: #991b1b; } }

/* === Diff === */
.diff-box { border-color: #2b6de8; }
.diff-added { color: #22c55e; margin: 2px 0; }
.diff-removed { color: #ef4444; margin: 2px 0; text-decoration: line-through; }
.diff-changed { color: #f59e0b; margin: 2px 0; }

/* === Admin grid === */
.grid-admin { display: grid; grid-template-columns: 320px 1fr; gap: 12px; height: calc(100vh - 180px); }
.sidebar { background: #121a2b; border: 1px solid #1f2a44; border-radius: 8px; padding: 10px; overflow-y: auto; }
.sidebar-search { width: 100%; margin-bottom: 10px; }
.detail { background: #121a2b; border: 1px solid #1f2a44; border-radius: 8px; padding: 12px; overflow: auto; }

.sidebar a.enc-item { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #e6e9ef; text-decoration: none; padding: 10px 12px; border-radius: 8px; border: 1px solid #1f2a44; margin-bottom: 8px; background: #0e1626; transition: background .2s; min-height: 42px; }
.sidebar a.enc-item:hover { background: #162433; }
.enc-item .enc-title { font-size: 13px; line-height: 1.2; }
.enc-item .enc-sub { font-size: 11px; opacity: .8; }
.enc-item > div:first-child { flex: 1 1 auto; min-width: 0; }

/* === Kebab menu === */
.kebab { flex-shrink: 0; width: 26px; height: 26px; border-radius: 6px; background: #1a243a; color: #e6e9ef; border: 1px solid #1f2a44; display: flex; justify-content: center; align-items: center; cursor: pointer; }
.kebab:hover { background: #22335a; }
.kebab:after { content: "\22EF"; font-size: 18px; }
.menu { position: absolute; right: 8px; top: calc(100% + 4px); background: #0e1626; border: 1px solid #1f2a44; border-radius: 8px; min-width: 160px; z-index: 1000; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.menu.hidden { display: none; }
.menu .mi { padding: 10px 12px; cursor: pointer; font-size: 13px; }
.menu .mi:hover { background: #162433; }

/* === Panel === */
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.chat { max-height: 340px; overflow-y: auto; background: #0e1626; border: 1px solid #1f2a44; border-radius: 6px; padding: 8px; }
.msg { padding: 6px 8px; margin: 4px 0; border-radius: 4px; background: #1a243a; font-size: 14px; line-height: 1.4; }
.msg-doctor { border-left: 3px solid #2b6de8; }
.msg-patient { border-left: 3px solid #22c55e; }
.msg-speaker { font-weight: 600; font-size: 12px; opacity: .8; }

/* === Badges === */
.badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-active { background: #166534; color: #86efac; }
.badge-completed { background: #1e3a5f; color: #93c5fd; }
.badge-archived { background: #3f3f46; color: #a1a1aa; }

/* === Tabs === */
.tab-bar { display: flex; gap: 4px; margin-bottom: 12px; align-items: center; }
.tab { background: #1a243a; color: #a1a1aa; border: 1px solid #1f2a44; padding: 8px 16px; border-radius: 6px 6px 0 0; cursor: pointer; font-size: 14px; }
.tab.active { background: #121a2b; color: #e6e9ef; border-bottom-color: #121a2b; }
.tab-link { margin-left: auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Filters === */
.filters-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters-bar label { font-size: 14px; }
.filters-bar input, .filters-bar select { max-width: 160px; }

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card { min-height: 200px; }
.stat-card:first-child { grid-column: 1 / -1; }
.stat-chart { margin-top: 8px; }

.bar-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.bar-label { min-width: 120px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { flex: 1; height: 16px; background: #1a243a; border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: #f59e0b; border-radius: 3px; transition: width .3s; }
.bar-fill.bar-blue { background: #2b6de8; }
.bar-fill.bar-green { background: #22c55e; }
.bar-value { min-width: 60px; text-align: right; font-weight: 600; }

/* === Timeline === */
.timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.timeline-card { position: relative; padding-left: 20px; }
.timeline-card::before { content: ''; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: #1f2a44; }
.timeline-card::after { content: ''; position: absolute; left: 2px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: #2b6de8; }
.timeline-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* === Login === */
.login-body { display: flex; justify-content: center; align-items: center; height: 100vh; }
.login-box { width: 360px; background: #121a2b; border: 1px solid #1f2a44; border-radius: 8px; padding: 24px; }
.login-box h2 { text-align: center; margin-bottom: 4px; }
.login-box .note { font-size: 13px; opacity: .8; margin: 8px 0; text-align: center; }
.login-box label { display: block; margin-top: 12px; font-size: 14px; }
.login-box input { width: 100%; margin-top: 6px; }
.login-box button { width: 100%; margin-top: 12px; }
.login-box .status { margin-top: 10px; font-size: 14px; text-align: center; }

/* === Responsive === */
@media (max-width: 1024px) {
  .grid-admin { grid-template-columns: 260px 1fr; }
  .grid-main { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .grid-admin { grid-template-columns: 1fr; height: auto; }
  .sidebar { max-height: 40vh; }
  .grid-main { grid-template-columns: 1fr; }
  .top-row { flex-direction: column; align-items: stretch; }
  .patient-bar { flex-wrap: wrap; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-bar input, .filters-bar select { max-width: 100%; }
}
