/* ============================================
   Encounter Workspace — History Grid Styles
   ============================================ */

/* ─── Grid Table Base ─────────────────────── */
.ew-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

.ew-grid th {
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted, #6b7280);
    background: var(--bg-secondary, #f8f9fc);
    border-bottom: 2px solid var(--border-color, #e5e7eb);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.ew-grid th.ew-col-required::after {
    content: ' *';
    color: var(--danger-color, #ef4444);
}

.ew-grid td {
    padding: 0;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    vertical-align: middle;
    position: relative;
}

.ew-grid tbody tr:hover {
    background-color: rgba(37, 99, 235, 0.03);
}

/* ─── Cell Inputs (borderless, full-cell) ─── */
.ew-cell-input,
.ew-cell-select {
    width: 100%;
    border: none;
    background: transparent;
    padding: 7px 8px;
    font-size: 13px;
    color: var(--text-primary, #111827);
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}

.ew-cell-input:focus,
.ew-cell-select:focus {
    background: rgba(99, 102, 241, 0.04);
    box-shadow: inset 2px 0 0 0 var(--primary-color, #6366F1);
}

.ew-cell-input::placeholder {
    color: var(--text-muted, #9ca3af);
    font-style: italic;
    font-weight: 300;
}

.ew-cell-select {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 12px;
    padding-right: 22px;
}

.ew-cell-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin: 7px 8px;
    accent-color: var(--primary-color, #6366F1);
}

/* ─── New (Empty) Row ─────────────────────── */
.ew-row-new {
    background: rgba(99, 102, 241, 0.02);
}

.ew-row-new td {
    border-bottom: 2px dashed var(--border-color, #e5e7eb);
}

.ew-row-new .ew-cell-input::placeholder {
    color: var(--primary-color, #6366F1);
    opacity: 0.4;
}

.ew-row-new .ew-cell-select option[disabled] {
    color: var(--text-muted, #9ca3af);
    font-style: italic;
}

/* Muted color when placeholder option is selected */
.ew-row-new .ew-cell-select:has(option[disabled]:checked) {
    color: var(--text-muted, #9ca3af);
    font-style: italic;
    font-weight: 300;
}

/* ─── Action Buttons ──────────────────────── */
.ew-grid .ew-cell-actions {
    padding: 4px 6px;
    text-align: center;
    white-space: nowrap;
}

.ew-grid .ew-cell-actions .btn {
    padding: 2px 5px;
    font-size: 12px;
    line-height: 1;
}

/* ─── Save Status Indicator ───────────────── */
.ew-save-status {
    padding: 4px 6px;
    text-align: center;
    white-space: nowrap;
    font-size: 11px;
    min-width: 60px;
}

.ew-save-status .ew-status-idle {
    color: var(--success-color, #10b981);
    opacity: 0.5;
}

.ew-save-status .ew-status-saving {
    color: var(--primary-color, #6366F1);
    animation: ewPulse 1s ease-in-out infinite;
}

.ew-save-status .ew-status-saved {
    color: var(--success-color, #10b981);
    font-weight: 600;
    animation: ewFadeToIdle 2s ease forwards;
}

.ew-save-status .ew-status-error {
    color: var(--danger-color, #ef4444);
    font-weight: 600;
}

@keyframes ewPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes ewFadeToIdle {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* ─── Section Card ────────────────────────── */
.ew-history-card {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    background: var(--card-bg, #fff);
    overflow: visible;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    position: relative;
}

.ew-history-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-secondary, #f8f9fc);
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    gap: 8px;
    flex-wrap: wrap;
}

.ew-history-card-header h6 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.ew-history-card-header .badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
}

.ew-history-card-body {
    overflow: visible;
}

/* Collapsed state (empty sections) */
.ew-history-card.collapsed .ew-history-card-body {
    display: none;
}

.ew-history-card.collapsed .ew-history-card-header {
    border-bottom: none;
    cursor: pointer;
}

.ew-history-card.collapsed .ew-history-card-header:hover {
    background: rgba(99, 102, 241, 0.05);
}

.ew-collapse-hint {
    font-size: 12px;
    color: var(--text-muted, #9ca3af);
    font-style: italic;
}

/* ─── Quick-Add Chips ─────────────────────── */
.ew-chips-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.ew-chips-label {
    font-size: 11px;
    color: var(--text-muted, #6b7280);
    font-weight: 500;
    margin-right: 2px;
    white-space: nowrap;
}

.ew-quick-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    font-size: 11px;
    border-radius: 12px;
    border: 1px solid var(--border-color, #d1d5db);
    background: var(--card-bg, #fff);
    color: var(--text-primary, #374151);
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
    line-height: 1.4;
}

.ew-quick-chip:hover {
    background: var(--primary-color, #6366F1);
    color: #fff;
    border-color: var(--primary-color, #6366F1);
    transform: translateY(-1px);
}

.ew-quick-chip i {
    font-size: 9px;
    margin-right: 3px;
}

.ew-quick-chip.auto-save {
    border-color: var(--success-color, #10b981);
    color: var(--success-color, #10b981);
}

.ew-quick-chip.auto-save:hover {
    background: var(--success-color, #10b981);
    color: #fff;
    border-color: var(--success-color, #10b981);
}

/* ─── Autocomplete in Grid ────────────────── */
.ew-ac-container {
    position: relative;
}

.ew-ac-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 220px;
    overflow-y: auto;
    z-index: 1060;
    min-width: 250px;
}

.ew-ac-results .autocomplete-item {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--bg-secondary, #f3f4f6);
    font-size: 12px;
}

.ew-ac-results .autocomplete-item:last-child {
    border-bottom: none;
}

.ew-ac-results .autocomplete-item:hover,
.ew-ac-results .autocomplete-item.active {
    background: rgba(99, 102, 241, 0.08);
}

.ew-ac-results .ac-primary {
    font-weight: 600;
    color: var(--text-primary, #111827);
}

.ew-ac-results .ac-secondary {
    color: var(--text-muted, #6b7280);
    font-size: 11px;
}

/* ─── Keyboard Hints ──────────────────────── */
.ew-kb-hints {
    font-size: 10px;
    color: var(--text-muted, #9ca3af);
    padding: 4px 14px 6px;
    text-align: right;
}

.ew-kb-hints kbd {
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #c6cbd1;
    background: #e8eaed;
    color: #374151;
    font-family: inherit;
    box-shadow: 0 1px 0 #b0b5bc;
}

/* ─── + Add Button ───────────────────────── */
.ew-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    margin: 6px 10px 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--primary-color, #6366F1);
    background: transparent;
    border: 1px dashed var(--primary-color, #6366F1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    opacity: 0.7;
}

.ew-add-btn:hover {
    background: rgba(99, 102, 241, 0.06);
    opacity: 1;
    border-style: solid;
}

.ew-add-btn:active {
    transform: scale(0.97);
}

.ew-add-btn i {
    font-size: 11px;
}

.ew-add-btn.d-none {
    display: none !important;
}

/* ─── Add Row Action Buttons ─────────────── */
.ew-add-row-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px 4px;
    white-space: nowrap;
}

.ew-btn-save-row,
.ew-btn-save-new,
.ew-btn-cancel-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    transition: all 0.12s ease;
    padding: 4px 8px;
    gap: 3px;
}

.ew-btn-save-row {
    background: var(--success-color, #10b981);
    color: #fff;
}

.ew-btn-save-row:hover {
    background: #059669;
    transform: translateY(-1px);
}

.ew-btn-save-new {
    background: var(--primary-color, #6366F1);
    color: #fff;
}

.ew-btn-save-new:hover {
    background: #4f46e5;
    transform: translateY(-1px);
}

.ew-btn-cancel-row {
    background: transparent;
    color: var(--text-muted, #9ca3af);
    padding: 4px 5px;
}

.ew-btn-cancel-row:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger-color, #ef4444);
}

/* ─── Add Row Slide-In Animation ─────────── */
.ew-row-adding {
    animation: ewRowSlideIn 0.2s ease;
}

@keyframes ewRowSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ─── Row Fade-Out Animation (Delete) ─────── */
.ew-row-removing {
    animation: ewRowFadeOut 0.3s ease forwards;
}

@keyframes ewRowFadeOut {
    to {
        opacity: 0;
        transform: translateX(20px);
        max-height: 0;
        padding: 0;
        overflow: hidden;
    }
}

/* ─── Patient Sticky Notes Panel ─────────── */
.ew-sticky-notes-panel {
    position: fixed;
    top: 60px;
    right: 16px;
    width: 340px;
    max-height: calc(100vh - 80px);
    background: #fff;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    animation: stickySlideIn 0.2s ease-out;
}

@keyframes stickySlideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ew-sticky-notes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: #fffbeb;
    border-radius: 12px 12px 0 0;
}

.ew-sticky-notes-add {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: #fefce8;
}

.ew-sticky-notes-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
    padding: 8px;
}

.ew-sticky-note-item {
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    transition: box-shadow 0.15s;
}

.ew-sticky-note-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.ew-sticky-note-content {
    font-size: 13px;
    color: #1c1917;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.ew-sticky-note-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    font-size: 11px;
    color: #78716c;
}

.ew-sticky-note-meta .btn-link {
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
}

.ew-sticky-note-item:hover .ew-sticky-note-meta .btn-link {
    opacity: 1;
}
