/* 
 * Medical Dictation App Styles
 * Clean, professional aesthetic suitable for clinical environment
 * Single-document workflow redesign
 */

:root {
    /* Color palette - clinical/professional */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e9ecef;
    --bg-dark: #1a1d23;
    
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --text-inverse: #f8f9fa;
    
    --accent-primary: #0066cc;
    --accent-primary-hover: #0052a3;
    --accent-secondary: #28a745;
    --accent-danger: #dc3545;
    --accent-warning: #ffc107;
    
    --border-color: #dee2e6;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    
    /* Typography */
    --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', Consolas, monospace;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Sidebar width */
    --sidebar-width: 320px;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   App Layout
   ========================================================================== */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-md);
    gap: var(--space-sm);
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 120px;
}

.header-right {
    justify-content: flex-end;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* Content Row: library panel + main content side by side */
.content-row {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: var(--space-sm);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: var(--space-sm);
    min-height: 0;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    padding: var(--space-md);
}

/* ==========================================================================
   Format Toolbar
   ========================================================================== */

.format-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: var(--space-sm);
}

.format-toolbar-left,
.format-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.btn-fmt {
    padding: 4px 10px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-fmt:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

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

.btn-fmt svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Document Area (editor + sidebar)
   ========================================================================== */

.document-area {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0;
    overflow: hidden;
}

.editor-wrapper {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    transition: flex var(--transition-normal);
}

/* Editor */
.editor {
    min-height: 100%;
    padding: var(--space-md) var(--space-lg);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-primary);
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    font-style: italic;
    pointer-events: none;
}

/* Disabled state during recording */
.editor--disabled {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

/* Rich text styles within editor */
.editor p { margin-bottom: 0.75em; }
.editor p:last-child { margin-bottom: 0; }
.editor strong { font-weight: 600; }
.editor em { font-style: italic; }
.editor ul, .editor ol { margin-left: 1.5em; margin-bottom: 0.75em; }
.editor li { margin-bottom: 0.25em; }
.editor h1 { font-size: 1.5rem; font-weight: 600; margin: 1em 0 0.5em; }
.editor h2 { font-size: 1.25rem; font-weight: 600; margin: 1em 0 0.5em; }
.editor h3 { font-size: 1.1rem; font-weight: 600; margin: 1em 0 0.5em; }

/* ==========================================================================
   Error Inline Highlights
   ========================================================================== */

.error-highlight {
    background: rgba(220, 53, 69, 0.12);
    border-bottom: 2px solid var(--accent-danger);
    border-radius: 2px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.error-highlight:hover,
.error-highlight.highlight--active {
    background: rgba(220, 53, 69, 0.22);
}

/* ==========================================================================
   Error Hover Tooltip
   ========================================================================== */

.error-tooltip {
    position: fixed;
    z-index: 500;
    background: var(--bg-dark);
    color: var(--text-inverse);
    border-radius: var(--border-radius);
    padding: var(--space-sm) var(--space-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: 0.85rem;
    max-width: 320px;
    pointer-events: auto;
}

.error-tooltip-suggested {
    font-family: var(--font-mono);
    color: #6ee7b7;
    font-weight: 500;
    flex: 1;
}

.error-tooltip-actions {
    display: flex;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.tooltip-btn {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.tooltip-btn--accept {
    background: rgba(40, 167, 69, 0.2);
    color: #6ee7b7;
}

.tooltip-btn--accept:hover {
    background: rgba(40, 167, 69, 0.4);
}

.tooltip-btn--ignore {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

.tooltip-btn--ignore:hover {
    background: rgba(220, 53, 69, 0.3);
    color: #fca5a5;
}

/* ==========================================================================
   Check Sidebar
   ========================================================================== */

.check-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
    animation: sidebar-in var(--transition-normal);
}

@keyframes sidebar-in {
    from { width: 0; min-width: 0; opacity: 0; }
    to { width: var(--sidebar-width); min-width: var(--sidebar-width); opacity: 1; }
}

.check-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.check-sidebar-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.check-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

/* ==========================================================================
   Check Results (shared by sidebar)
   ========================================================================== */

.check-summary {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
}

.check-summary--clear {
    background: rgba(40, 167, 69, 0.1);
    color: var(--accent-secondary);
    border: 1px solid rgba(40, 167, 69, 0.25);
}

.check-summary--issues {
    background: rgba(220, 53, 69, 0.08);
    color: var(--accent-danger);
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.check-block {
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    background: var(--bg-secondary);
}

.check-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.check-block-label {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.check-block-count {
    color: var(--accent-danger);
    font-weight: 500;
}

.check-error {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.check-error:last-child {
    border-bottom: none;
}

.check-error--active {
    background: rgba(0, 102, 204, 0.05);
}

.check-error-original {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--accent-danger);
    margin-bottom: var(--space-xs);
}

.check-error-arrow {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.check-error-suggested {
    font-family: var(--font-mono);
    color: var(--accent-secondary);
    font-weight: 500;
}

.check-error-reason {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.check-error-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-xs);
}

.check-error-action {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.check-error-confidence {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 3px;
}

.confidence--high {
    background: rgba(220, 53, 69, 0.12);
    color: var(--accent-danger);
}

.confidence--medium {
    background: rgba(255, 193, 7, 0.15);
    color: #856404;
}

.confidence--low {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Accept / Ignore buttons */
.fix-btn {
    padding: 3px 9px;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.fix-btn--accept {
    color: var(--accent-primary);
    background: rgba(0, 102, 204, 0.08);
    border: 1px solid rgba(0, 102, 204, 0.25);
}

.fix-btn--accept:hover {
    background: rgba(0, 102, 204, 0.15);
    border-color: rgba(0, 102, 204, 0.4);
}

.fix-btn--ignore {
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-color);
}

.fix-btn--ignore:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.fix-applied {
    display: flex;
    align-items: center;
    color: var(--accent-secondary);
    cursor: default;
}

.check-error--fixed {
    opacity: 0.55;
}

.check-error--ignored {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ==========================================================================
   Action Bar (bottom)
   ========================================================================== */

.action-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.action-bar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 var(--space-xs);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-primary-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-icon {
    padding: var(--space-sm);
    background: transparent;
    color: var(--text-secondary);
}

.btn-icon:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Check button */
.btn-check {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
    font-size: 0.875rem;
    border-radius: var(--border-radius);
}

.btn-check:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
}

/* Process/Format button */
.btn-process {
    padding: var(--space-sm) var(--space-md);
    background: linear-gradient(135deg, var(--accent-primary) 0%, #0077e6 100%);
    color: white;
    font-size: 0.875rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.btn-process:hover:not(:disabled) {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-process:active:not(:disabled) {
    transform: translateY(0);
}

/* Shared loading state */
.btn-check .btn-loading,
.btn-process .btn-loading {
    display: none;
}

/* Spinner */
.spinner {
    animation: spin 1s linear infinite;
}

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

/* ==========================================================================
   Status Indicator
   ========================================================================== */

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-secondary);
    transition: background var(--transition-normal);
}

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

.status-indicator.status--ready .status-dot      { background: var(--accent-secondary); }
.status-indicator.status--recording .status-dot  { background: var(--accent-danger); animation: pulse 0.8s ease-in-out infinite; }
.status-indicator.status--transcribing .status-dot { background: var(--accent-warning); animation: pulse 1s ease-in-out infinite; }
.status-indicator.status--processing .status-dot { background: var(--accent-primary); animation: pulse 1s ease-in-out infinite; }
.status-indicator.status--error .status-dot      { background: var(--accent-danger); }

/* ==========================================================================
   Audio Level
   ========================================================================== */

.audio-level {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
    opacity: 0.3;
    transition: opacity var(--transition-normal);
}

.audio-level.active {
    opacity: 1;
}

.level-bar {
    width: 3px;
    height: 4px;
    background: var(--accent-secondary);
    border-radius: 1px;
    transition: height 100ms ease;
}

.audio-level.active .level-bar:nth-child(1) { height: 6px; }
.audio-level.active .level-bar:nth-child(2) { height: 10px; }
.audio-level.active .level-bar:nth-child(3) { height: 14px; }
.audio-level.active .level-bar:nth-child(4) { height: 10px; }
.audio-level.active .level-bar:nth-child(5) { height: 6px; }

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-dark);
    color: var(--text-inverse);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slide-up 0.3s ease;
}

.toast.error   { background: var(--accent-danger); }
.toast.success { background: var(--accent-secondary); }

@keyframes slide-up {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.7;
}

.toast-close:hover { opacity: 1; }

/* ==========================================================================
   Settings Modal
   ========================================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fade-in 0.2s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: modal-in 0.3s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

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

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    flex: 1;
    padding: var(--space-lg);
    overflow-y: auto;
}

.modal-body label {
    display: block;
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.modal-body textarea {
    width: 100%;
    padding: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    resize: vertical;
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
}

/* Tabs */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--space-lg);
}

.modal-tab {
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: -1px;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.modal-tab:hover { color: var(--text-primary); }

.modal-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.tab-pane {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.tab-description {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ==========================================================================
   Token Counter
   ========================================================================== */

.token-counter {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.token-count--over {
    color: var(--accent-danger);
    font-weight: 600;
}

.token-warning {
    color: var(--accent-danger);
    font-family: var(--font-sans);
}

/* ==========================================================================
   Utility
   ========================================================================== */

.hidden {
    display: none !important;
}

/* ==========================================================================
   Library Panel
   ========================================================================== */

/* Narrow strip shown when library panel is closed */
.library-reopen-btn {
    width: 28px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border: none;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.library-reopen-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.library-panel {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    transition: width var(--transition-normal), min-width var(--transition-normal), opacity var(--transition-fast);
}

.library-panel.library-panel--closed {
    width: 0 !important;
    min-width: 0 !important;
    opacity: 0;
    pointer-events: none;
}

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: var(--space-sm);
}

.library-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.lib-close-btn {
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.lib-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.library-sort {
    display: flex;
    gap: 2px;
}

.library-sort-btn {
    padding: 2px 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.library-sort-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.library-list {
    flex: 1;
    overflow-y: auto;
}

/* Patient rows */
.lib-patient-row {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
    gap: var(--space-xs);
}

.lib-patient-row:hover {
    background: var(--bg-tertiary);
}

.lib-patient-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    width: 12px;
}

.lib-patient-row--expanded .lib-patient-chevron {
    transform: rotate(90deg);
    color: var(--text-secondary);
}

.lib-patient-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lib-patient-actions {
    display: none;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.lib-patient-row:hover .lib-patient-actions {
    display: flex;
}

/* Unassigned section */
.lib-unassigned-header {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-top: 2px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    gap: var(--space-xs);
}

.lib-unassigned-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    flex: 1;
}

/* Letter rows */
.lib-letters-container {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.lib-letter-row {
    display: flex;
    align-items: center;
    padding: 6px var(--space-md) 6px calc(var(--space-md) + 16px);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-color);
    gap: var(--space-xs);
}

.lib-letter-row:last-child {
    border-bottom: none;
}

.lib-letter-row:hover {
    background: #eef2f7;
}

.lib-letter-row--active {
    background: rgba(0, 102, 204, 0.07);
    border-left: 3px solid var(--accent-primary);
    padding-left: calc(var(--space-md) + 13px);
}

.lib-letter-info {
    flex: 1;
    min-width: 0;
}

.lib-letter-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lib-letter-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.lib-letter-actions {
    display: none;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.lib-letter-row:hover .lib-letter-actions {
    display: flex;
}

/* Shared action icon buttons */
.lib-action-btn {
    width: 22px;
    height: 22px;
    background: transparent;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
    padding: 0;
    flex-shrink: 0;
}

.lib-action-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.lib-action-btn--danger:hover {
    background: rgba(220, 53, 69, 0.1);
    color: var(--accent-danger);
}

/* New letter button (inside expanded patient) */
.lib-new-letter-btn {
    display: block;
    width: 100%;
    padding: 6px var(--space-md) 6px calc(var(--space-md) + 16px);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--accent-primary);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition-fast);
}

.lib-new-letter-btn:hover {
    background: rgba(0, 102, 204, 0.05);
}

/* New patient button (bottom of panel) */
.lib-new-patient-btn {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    border-top: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--accent-primary);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.lib-new-patient-btn:hover {
    background: rgba(0, 102, 204, 0.05);
}

/* Move-to-patient dropdown */
.lib-move-dropdown {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    max-height: 280px;
    overflow-y: auto;
}

.lib-move-item {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition-fast);
}

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

.lib-move-item:hover {
    background: var(--bg-tertiary);
}

.lib-move-item--new {
    color: var(--accent-primary);
    font-weight: 500;
}

.lib-move-separator {
    height: 1px;
    background: var(--border-color);
}

/* Patient indicator (below format toolbar) */
.patient-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 4px var(--space-sm);
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.patient-indicator-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.patient-indicator-name {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}

.patient-indicator-name--unassigned {
    font-weight: 400;
    color: var(--text-muted);
    font-style: italic;
}

.patient-indicator-btn {
    padding: 1px 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: all var(--transition-fast);
}

.patient-indicator-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .app-container {
        padding: var(--space-sm);
    }

    .check-sidebar {
        /* Future: bottom sheet on mobile */
        width: 100%;
        min-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        max-height: 50vh;
    }

    .document-area {
        flex-direction: column;
    }

    .action-bar {
        flex-wrap: wrap;
    }
}
