/* ─── Reset & Variables ──────────────────────────────────────────── */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --success: #16a34a;
    --warning: #d97706;
    --info: #0891b2;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #94a3b8;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body { overflow-x: hidden; }

/* ─── Typography ────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

/* ─── App Shell ─────────────────────────────────────────────────── */
#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    background: var(--bg);
}

/* ─── Header ────────────────────────────────────────────────────── */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.2rem;
}

.app-logo-icon {
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

#user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.user-info { text-align: right; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-role { font-size: 0.75rem; color: var(--text-muted); }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }

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

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

/* ─── Login View ────────────────────────────────────────────────── */
.login-container {
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    justify-content: center;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-icon {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto 16px;
}

.login-logo h1 { font-size: 1.8rem; }
.login-logo p { color: var(--text-muted); margin-top: 4px; }

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

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

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
    transition: border-color 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* ─── Views ─────────────────────────────────────────────────────── */
.view { display: none; padding-bottom: 80px; }
.view.active { display: block; }

.section { padding: 16px; }
.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

/* ─── Record Button ─────────────────────────────────────────────── */
.record-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
    gap: 12px;
}

#record-btn {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    border: 4px solid var(--danger);
    background: white;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    -webkit-tap-highlight-color: transparent;
}

#record-btn .record-icon {
    font-size: 2.5rem;
    transition: all 0.25s;
}

#record-btn .stop-icon {
    font-size: 1.8rem;
    color: white;
}

#record-btn.recording {
    background: var(--danger);
    border-color: var(--danger-dark);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
    70% { box-shadow: 0 0 0 20px rgba(220,38,38,0); }
    100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}

#record-timer {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-height: 2rem;
}

.status-badge {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-idle { background: #f1f5f9; color: var(--text-muted); }
.status-recording { background: #fef2f2; color: var(--danger); }
.status-processing { background: #eff6ff; color: var(--primary); }
.status-error { background: #fef2f2; color: var(--danger); }

/* ─── Stats Cards ───────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Dictation Card ────────────────────────────────────────────── */
.dictation-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.dictation-card:active {
    transform: scale(0.99);
    background: #f8fafc;
}

.dictation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.dictation-title {
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.3;
}

.dictation-meta {
    display: flex;
    gap: 12px;
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.dictation-preview {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ─── Badges ────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* ─── Detail View ───────────────────────────────────────────────── */
.detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: flex-end;
}

.detail-sheet {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.detail-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.detail-field {
    margin-bottom: 12px;
}

.detail-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-field .value {
    font-size: 0.9rem;
    line-height: 1.5;
}

.transcription-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.85rem;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* ─── Correction View ───────────────────────────────────────────── */
.correction-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 200;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

.correction-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.correction-body { padding: 16px; }

.correction-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ─── Empty State ───────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}

.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* ─── Tabs ──────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    padding: 0 16px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
}

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

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Toast ─────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 400px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transition: opacity 0.3s;
}

.toast-info { background: var(--info); color: white; }
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-fade { opacity: 0; }

/* ─── Nav Tabs (bottom nav) ─────────────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 10px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.15s;
    border: none;
    background: none;
    -webkit-tap-highlight-color: transparent;
}

.nav-item .nav-icon { font-size: 1.3rem; margin-bottom: 2px; }
.nav-item.active { color: var(--primary); }

/* ─── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Textarea ──────────────────────────────────────────────────── */
textarea.form-input {
    min-height: 200px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

/* ─── Hidden helper ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP / TABLET RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════ */

/* Tablet+ : agrandir le conteneur */
@media (min-width: 768px) {
    #app { max-width: 100%; padding: 0 24px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
    .record-area { padding: 32px; }
    #record-btn { width: 100px; height: 100px; }
}

@media (min-width: 1024px) {
    #app { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }

    /* Secretary split view */
    .sec-split { display: flex; gap: 16px; min-height: calc(100vh - 120px); }
    .sec-split-sidebar { width: 380px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); padding-right: 16px; }
    .sec-split-main { flex: 1; overflow-y: auto; }

    /* Admin sidebar layout */
    .admin-layout { display: flex; gap: 24px; min-height: calc(100vh - 120px); }
    .admin-sidebar { width: 220px; flex-shrink: 0; border-right: 1px solid var(--border); padding-right: 16px; }
    .admin-content { flex: 1; }
    .admin-nav-item {
        display: flex; align-items: center; gap: 10px; padding: 12px 16px;
        border-radius: var(--radius-sm); cursor: pointer; transition: all 0.15s;
        font-weight: 500; color: var(--text); border: none; background: none;
        width: 100%; text-align: left; font-size: 0.95rem;
    }
    .admin-nav-item:hover { background: #f1f5f9; }
    .admin-nav-item.active { background: #dbeafe; color: var(--primary); }
    .admin-section { display: none; }
    .admin-section.active { display: block; }
}

/* ─── Admin Styles (applies everywhere) ─────────────────────────── */
.admin-table {
    width: 100%; border-collapse: collapse; font-size: 0.9rem;
    background: var(--surface); border-radius: var(--radius-sm); overflow: hidden;
    border: 1px solid var(--border);
}
.admin-table th {
    background: #f8fafc; text-align: left; padding: 10px 14px;
    font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
    color: var(--text-muted); letter-spacing: 0.05em; border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.admin-table tr:last-child td { border-bottom: none; }

.form-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 20px; margin-bottom: 16px;
}
.form-card h3 { margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }

select.form-input { appearance: auto; }

.badge-ok { background: #dcfce7; color: #166534; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-off { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }

.toast-container { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 400px; }

/* Audit style for login logs */
.log-ok { color: var(--success); }
.log-fail { color: var(--danger); }
