/* ╔══════════════════════════════════════╗ */
/* ║          CSS VARIABLES               ║ */
/* ╚══════════════════════════════════════╝ */
:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-light: #DBEAFE;
    --secondary: #0F172A;
    --danger: #DC2626;
    --danger-hover: #B91C1C;
    --success: #16A34A;
    --warning: #F59E0B;
    --bg: #F8FAFC;
    --bg-card: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-light: #94A3B8;
    --border: #E2E8F0;
    --border-hover: #CBD5E1;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 150ms ease;
}

/* ╔══════════════════════════════════════╗ */
/* ║          RESET & BASE                ║ */
/* ╚══════════════════════════════════════╝ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ╔══════════════════════════════════════╗ */
/* ║          SCREENS                     ║ */
/* ╚══════════════════════════════════════╝ */
.screen {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* ╔══════════════════════════════════════╗ */
/* ║          HEADER                      ║ */
/* ╚══════════════════════════════════════╝ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--secondary);
}

/* ╔══════════════════════════════════════╗ */
/* ║          CONTENT                     ║ */
/* ╚══════════════════════════════════════╝ */
.content {
    padding: 16px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

/* ╔══════════════════════════════════════╗ */
/* ║          LOGIN                       ║ */
/* ╚══════════════════════════════════════╝ */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--secondary);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

#login-form {
    width: 100%;
    max-width: 360px;
}

/* ╔══════════════════════════════════════╗ */
/* ║          FORMS                       ║ */
/* ╚══════════════════════════════════════╝ */
.form-group {
    margin-bottom: 16px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text);
    background: white;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
    resize: vertical;
}

.form-row {
    display: flex;
    gap: 12px;
}

.error-text {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 12px;
    text-align: center;
}

/* ╔══════════════════════════════════════╗ */
/* ║          BUTTONS                     ║ */
/* ╚══════════════════════════════════════╝ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
    background: #1E293B;
}

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

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

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

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

.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: #FEF2F2;
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.icon {
    font-size: 1.2rem;
    font-weight: 600;
}

/* ╔══════════════════════════════════════╗ */
/* ║          CARDS                       ║ */
/* ╚══════════════════════════════════════╝ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-header h3 {
    margin-bottom: 0;
}

.card-content {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
    word-break: break-word;
}

.card-content p {
    margin: 0 0 0.5em;
}

.card-content p:last-child {
    margin-bottom: 0;
}

.card-content ul,
.card-content ol {
    margin: 0.25em 0 0.5em;
    padding-left: 1.4em;
}

.card-content li {
    margin-bottom: 0.2em;
}

.card-content strong {
    font-weight: 600;
}

.card-content h1, .card-content h2, .card-content h3,
.card-content h4, .card-content h5, .card-content h6 {
    margin: 0.5em 0 0.25em;
    font-weight: 600;
    line-height: 1.3;
}

.card-content h4 {
    font-size: 0.95rem;
}

.card-content h5, .card-content h6 {
    font-size: 0.9rem;
}

/* ╔══════════════════════════════════════╗ */
/* ║          PATIENT INFO CARD           ║ */
/* ╚══════════════════════════════════════╝ */
.patient-card .patient-info {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.patient-card .info-item {
    font-size: 0.85rem;
}

.patient-card .info-label {
    color: var(--text-light);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.patient-card .info-value {
    color: var(--text);
    font-weight: 500;
}

/* ╔══════════════════════════════════════╗ */
/* ║          RECORDING CONTROLS          ║ */
/* ╚══════════════════════════════════════╝ */
.recording-card {
    text-align: center;
}

.recording-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
}

.recording-status.active .status-dot {
    background: var(--danger);
    animation: pulse 1s infinite;
}

.recording-timer {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    min-width: 45px;
}

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

/* ── Waveform Visualizer ── */
.waveform-container {
    margin: 0 auto 16px;
    width: 100%;
    max-width: 400px;
    height: 80px;
    border-radius: var(--radius-sm);
    background: #0F172A;
    overflow: hidden;
    position: relative;
}

.waveform-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.recorder-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
}

.btn-record {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg);
    border: 3px solid var(--danger);
    color: var(--danger);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-record:hover {
    background: #FEF2F2;
}

.btn-stop {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--danger);
    border: 3px solid var(--danger);
    color: white;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-stop:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

/* ╔══════════════════════════════════════╗ */
/* ║          SOAP NOTE                   ║ */
/* ╚══════════════════════════════════════╝ */
.soap-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.soap-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.soap-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary);
    margin-bottom: 8px;
}

/* ╔══════════════════════════════════════╗ */
/* ║          CASES LIST                  ║ */
/* ╚══════════════════════════════════════╝ */
.cases-list {
    margin-top: 16px;
}

.case-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.case-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.case-item-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.case-item-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.case-item-arrow {
    color: var(--text-light);
    font-size: 1.2rem;
}

.placeholder-text {
    text-align: center;
    color: var(--text-light);
    padding: 32px 16px;
    font-size: 0.9rem;
}

/* ╔══════════════════════════════════════╗ */
/* ║          PAST RECORDINGS             ║ */
/* ╚══════════════════════════════════════╝ */
.recording-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.recording-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.recording-item-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.recording-item-info strong {
    color: var(--text);
}

/* ╔══════════════════════════════════════╗ */
/* ║          LOADING OVERLAY             ║ */
/* ╚══════════════════════════════════════╝ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ╔══════════════════════════════════════╗ */
/* ║          TOAST                       ║ */
/* ╚══════════════════════════════════════╝ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    z-index: 2000;
    box-shadow: var(--shadow-md);
    transition: opacity 300ms ease;
}

.toast.success {
    background: var(--success);
}

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

/* ╔══════════════════════════════════════╗ */
/* ║          UTILITIES                   ║ */
/* ╚══════════════════════════════════════╝ */
.hidden {
    display: none !important;
}

.copy-btn {
    font-size: 1rem;
    padding: 4px 8px;
}

/* ╔══════════════════════════════════════╗ */
/* ║          RESPONSIVE                  ║ */
/* ╚══════════════════════════════════════╝ */
@media (min-width: 768px) {
    .content {
        padding: 24px;
    }

    .card {
        padding: 20px;
    }

    .login-container {
        padding: 48px;
    }
}

@media (max-width: 480px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .patient-card .patient-info {
        grid-template-columns: 1fr 1fr;
    }
}
