/* ============================================================================
   AI Medical Recorder – Stylesheet
   ============================================================================
   Prefix: .air-  (AI Recorder)
   Tương thích: OpenEMR 7.x, Bootstrap 3/4, Vanilla UI
   ============================================================================ */

/* ── Host container ──────────────────────────────────────────────────────── */
.air-host {
    display: inline-flex;
    align-items: center;
}

/* ── Primary trigger button ──────────────────────────────────────────────── */
.air-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.air-btn--start {
    background: #2563eb;
    color: #fff;
}
.air-btn--start:hover  { background: #1d4ed8; }
.air-btn--apply        { background: #16a34a; color: #fff; flex: 1; }
.air-btn--apply:hover  { background: #15803d; }
.air-btn--apply:disabled { opacity: 0.6; cursor: not-allowed; }
.air-btn--cancel       { background: #e5e7eb; color: #374151; }
.air-btn--cancel:hover { background: #d1d5db; }

/* ── Modal Overlay ───────────────────────────────────────────────────────── */
.air-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.air-modal-overlay--open {
    opacity: 1;
}

/* ── Modal Box ───────────────────────────────────────────────────────────── */
.air-modal {
    background: #fff;
    border-radius: 12px;
    width: min(680px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    transform: translateY(16px);
    transition: transform 0.25s;
}
.air-modal-overlay--open .air-modal {
    transform: translateY(0);
}

.air-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #1e40af;
    color: #fff;
    flex-shrink: 0;
}
.air-modal__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}
.air-modal__close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.air-modal__close:hover { background: rgba(255,255,255,0.35); }

.air-modal__body {
    padding: 24px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ── Step transitions ────────────────────────────────────────────────────── */
.air-step { animation: airFadeIn 0.25s ease; }
@keyframes airFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Recording Indicator ─────────────────────────────────────────────────── */
.air-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    padding: 14px 0 8px;
}

.air-pulse {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #9ca3af;
    flex-shrink: 0;
}

.air-indicator--active .air-pulse {
    background: #ef4444;
    animation: airPulse 1s infinite;
}
.air-indicator--paused .air-pulse {
    background: #f59e0b;
}
@keyframes airPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.5; transform: scale(1.35); }
}

.air-indicator__label {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}
.air-indicator--active  .air-indicator__label { color: #ef4444; }
.air-indicator--paused  .air-indicator__label { color: #d97706; }

/* ── Timer ────────────────────────────────────────────────────────────────── */
.air-timer {
    text-align: center;
    font-size: 36px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #111827;
    margin: 4px 0;
    letter-spacing: 2px;
}

/* ── Segment badge ───────────────────────────────────────────────────────── */
.air-segment-info {
    text-align: center;
    margin-bottom: 10px;
}
.air-badge {
    display: inline-block;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* ── VU Meter canvas ─────────────────────────────────────────── */
.air-vu-canvas {
    display: none;              /* JS sẽ set display:block khi ghi âm */
    width: 100%;
    margin: 8px 0 6px;
    border-radius: 6px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    box-sizing: border-box;
    cursor: default;
}

/* ── ICD-10 badge ────────────────────────────────────────────── */
.air-icd-badge {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    margin-bottom: 12px;
    box-sizing: border-box;
    line-height: 1.4;
}
.air-icd-badge strong {
    color: #78350f;
    font-weight: 700;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    letter-spacing: 0.02em;
}
.air-icd-note {
    font-size: 11px;
    color: #a16207;
    font-style: italic;
}

/* ── Control buttons (record/pause/resume/stop) ───────────────────────────── */
.air-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.air-ctrl {
    padding: 9px 20px;
    border-radius: 8px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.air-ctrl--record  { background: #ef4444; color: #fff; }
.air-ctrl--record:hover { background: #dc2626; }
.air-ctrl--pause   { background: #f59e0b; color: #fff; }
.air-ctrl--pause:hover  { background: #d97706; }
.air-ctrl--resume  { background: #10b981; color: #fff; }
.air-ctrl--resume:hover { background: #059669; }
.air-ctrl--stop    { background: #6b7280; color: #fff; }
.air-ctrl--stop:hover   { background: #4b5563; }

/* ── Hint ─────────────────────────────────────────────────────────────────── */
.air-hint {
    text-align: center;
    font-size: 12px;
    color: #6b7280;
    margin: 0;
}

/* ── Processing ──────────────────────────────────────────────────────────── */
.air-progress-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 20px 0;
}
.air-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.air-processing__msg {
    font-size: 15px;
    font-weight: 600;
    color: #1f2937;
    text-align: center;
    margin: 0;
}
.air-processing__detail {
    font-size: 12px;
    color: #6b7280;
    margin: 0;
    text-align: center;
}
.air-progress-bar {
    width: 100%;
    max-width: 380px;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}
.air-progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #7c3aed);
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* ── Result Tabs ─────────────────────────────────────────────────────────── */
.air-result__title { font-size: 15px; font-weight: 700; color: #111827; margin: 0 0 4px; }
.air-result__note  { font-size: 12px; color: #6b7280; margin: 0 0 14px; }

.air-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 14px;
}
.air-tab {
    padding: 7px 16px;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 4px 4px 0 0;
    transition: color 0.15s;
}
.air-tab--active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}
.air-tab:hover:not(.air-tab--active) { color: #374151; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.air-field-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.air-field { display: flex; flex-direction: column; gap: 4px; }
.air-field:not(.air-field--short) { grid-column: 1 / -1; }

.air-field__label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.air-field__input {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 9px;
    font-size: 13px;
    color: #111827;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.15s;
}
.air-field__input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

#air-soap-fields .air-field { margin-bottom: 10px; }

.air-transcript-view {
    width: 100%;
    min-height: 140px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px;
    font-size: 13px;
    color: #374151;
    background: #f9fafb;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}

/* ── Result actions ───────────────────────────────────────────────────────── */
.air-result-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #e5e7eb;
}

/* ── Error state ─────────────────────────────────────────────────────────── */
.air-error {
    text-align: center;
    padding: 30px 20px;
}
.air-error__icon { font-size: 40px; margin: 0 0 10px; }
.air-error__msg  { color: #b91c1c; font-size: 14px; margin: 0 0 18px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

/* Tablet (640px → 768px) */
@media (max-width: 768px) {
    .air-modal {
        width: min(560px, 96vw);
    }
    .air-field-grid {
        grid-template-columns: 1fr 1fr;
    }
    .air-field--short {
        grid-column: span 1;
    }
}

/* Small tablet / large phone (520px → 640px) */
@media (max-width: 640px) {
    .air-modal {
        width: 100vw;
        max-height: 100dvh;
        border-radius: 12px 12px 0 0;
        margin-top: auto;
    }
    .air-modal-overlay {
        align-items: flex-end;
    }
    .air-modal-overlay--open .air-modal {
        transform: translateY(0);
    }
    .air-modal__body {
        padding: 16px;
    }
    .air-timer {
        font-size: 28px;
    }
    .air-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .air-ctrl {
        text-align: center;
        padding: 12px 20px;
        font-size: 15px;
    }
    .air-field-grid {
        grid-template-columns: 1fr 1fr;
    }
    .air-field:not(.air-field--short) {
        grid-column: 1 / -1;
    }
    .air-tabs {
        flex-wrap: wrap;
        gap: 2px;
    }
    .air-tab {
        padding: 6px 12px;
        font-size: 12px;
    }
    .air-result-actions {
        flex-direction: column;
    }
    .air-result-actions .air-btn {
        text-align: center;
        width: 100%;
    }
    .air-icd-badge {
        font-size: 12px;
    }
}

/* Phone (≤ 420px) */
@media (max-width: 420px) {
    .air-modal__header {
        padding: 12px 16px;
    }
    .air-modal__title {
        font-size: 14px;
    }
    .air-timer {
        font-size: 24px;
    }
    .air-field-grid {
        grid-template-columns: 1fr;
    }
    .air-field--short {
        grid-column: 1;
    }
    .air-vu-canvas {
        height: 28px !important;
    }
}

/* Desktop / Electron app – hỗ trợ prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .air-modal-overlay,
    .air-modal,
    .air-step,
    .air-progress-bar__fill {
        transition: none !important;
        animation: none !important;
    }
    .air-pulse {
        animation: none !important;
    }
}
