/* ============================================
   AMBRA DOCENTE - Mobile-First Styles
   ============================================ */

:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --primary-dark: #1a252f;
    --accent: #3498db;
    --accent-light: #5dade2;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #868e96;
    --gray-700: #495057;
    --gray-800: #343a40;
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --sidebar-width: 240px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- Reset & Base ---- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
}

/* ---- Splash Screen ---- */
.splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.splash-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.splash-content h1 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
}

.splash-content p {
    font-size: 1rem;
    opacity: 0.8;
    margin: 0.25rem 0 0;
}

/* ---- Login ---- */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

.login-header i {
    font-size: 3rem;
}

.login-logo {
    max-height: 80px;
    max-width: 200px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.login-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0.5rem 0 0;
}

.login-header p {
    opacity: 0.8;
    margin: 0.25rem 0 0;
}

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

#login-form .input-group-text {
    background: white;
    border-right: 0;
    color: var(--gray-600);
}

#login-form .form-control {
    border-left: 0;
    font-size: 1rem;
    padding: 0.75rem;
}

#login-form .form-control:focus {
    box-shadow: none;
    border-color: var(--accent);
}

#login-form .btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    padding: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

#login-form .btn-primary:active {
    background: var(--accent-light);
}

/* ---- App Shell ---- */
#app-shell {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#app-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-right .btn-link {
    font-size: 1.3rem;
    padding: 0.25rem;
    text-decoration: none;
}

#notification-badge {
    position: absolute;
    top: -2px;
    right: -4px;
    font-size: 0.65rem;
    padding: 0.2em 0.45em;
}

/* ---- Main Content ---- */
#app-content {
    flex: 1;
    overflow-y: auto;
    margin-top: var(--header-height);
    margin-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding: 1rem;
}

/* ---- Modal fix per iOS/mobile ----
   Bootstrap aggiunge padding-right a body per compensare la scrollbar,
   ma con overflow:hidden non c'è scrollbar — lo azzeriamo.
   Il modal viene spostato a <body> via JS (show.bs.modal), quindi
   non è più vincolato dall'overflow di #app-content. */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0 !important;
}

/* ---- Bottom Navigation ---- */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-around;
    border-top: 1px solid var(--gray-200);
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

#bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 0.4rem 0;
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.2s;
}

#bottom-nav .nav-item i {
    font-size: 1.4rem;
    margin-bottom: 0.15rem;
}

#bottom-nav .nav-item.active {
    color: var(--accent);
}

#bottom-nav .nav-item:active {
    color: var(--accent-light);
}

/* ---- Cards ---- */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1rem;
}

.card-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    border-radius: 12px 12px 0 0 !important;
    padding: 0.875rem 1rem;
}

.card-body {
    padding: 1rem;
}

/* ---- Stat Cards (Dashboard) ---- */
.stat-card {
    text-align: center;
    padding: 1.25rem 0.75rem;
}

.stat-card .stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-top: 0.25rem;
}

/* ---- List Items ---- */
.list-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

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

.list-item:active {
    background: var(--gray-50);
}

.list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 0.875rem;
    flex-shrink: 0;
}

.list-item-body {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: 0.8rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-right {
    text-align: right;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

/* ---- Badges ---- */
.badge-presenza {
    font-size: 0.75rem;
    padding: 0.3em 0.6em;
    border-radius: 6px;
}

/* ---- Section Header ---- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.section-header a {
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--accent);
}

/* ---- Disponibilità - Time Slots ---- */
.time-slot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: white;
}

.time-slot-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.time-slot-day {
    font-weight: 600;
    min-width: 80px;
}

.time-slot-hours {
    color: var(--gray-600);
    font-size: 0.9rem;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    margin: 0;
    font-size: 0.95rem;
}

/* ---- Pull to refresh indicator ---- */
.pull-indicator {
    text-align: center;
    padding: 0.5rem;
    color: var(--gray-500);
    font-size: 0.85rem;
}

/* ---- Floating Action Button ---- */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 1rem);
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
    z-index: 500;
    transition: transform 0.2s;
}

.fab:active {
    transform: scale(0.92);
}

/* ---- Profile Avatar ---- */
.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.profile-header {
    text-align: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.profile-header h2 {
    margin: 0.75rem 0 0.25rem;
    font-size: 1.25rem;
}

.profile-header p {
    margin: 0;
    opacity: 0.8;
    font-size: 0.9rem;
}

/* ---- Menu list (profilo/sicurezza) ---- */
.menu-list .list-group-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    border: none;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
}

.menu-list .list-group-item:last-child {
    border-bottom: none;
}

.menu-list .list-group-item i {
    font-size: 1.2rem;
    width: 2rem;
    color: var(--gray-600);
}

.menu-list .list-group-item .bi-chevron-right {
    margin-left: auto;
    font-size: 0.85rem;
    color: var(--gray-400);
}

/* ---- Form styles ---- */
.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-700);
}

.form-control, .form-select {
    border-radius: 8px;
    padding: 0.625rem 0.875rem;
    border-color: var(--gray-300);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.15);
}

/* ---- Calendar day grid (disponibilità) ---- */
.day-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
    text-align: center;
}

.day-grid .day-cell {
    padding: 0.5rem 0.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.day-grid .day-cell.has-lessons {
    background: rgba(52, 152, 219, 0.1);
    color: var(--accent);
    font-weight: 600;
}

.day-grid .day-cell.today {
    background: var(--accent);
    color: white;
    font-weight: 700;
}

/* ---- Skeleton loading ---- */
.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 6px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    width: calc(100% - 2rem);
    max-width: 400px;
}

/* ---- Utilities ---- */
.text-accent { color: var(--accent) !important; }
.bg-accent { background-color: var(--accent) !important; }
.bg-accent-light { background-color: rgba(52, 152, 219, 0.1) !important; }
.bg-success-light { background-color: rgba(39, 174, 96, 0.1) !important; }
.bg-warning-light { background-color: rgba(243, 156, 18, 0.1) !important; }
.bg-danger-light { background-color: rgba(231, 76, 60, 0.1) !important; }

.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }

.fw-600 { font-weight: 600; }
.fs-sm { font-size: 0.85rem; }
.gap-1 { gap: 0.25rem; }
.min-w-0 { min-width: 0; }

/* ---- Mobile icon-only buttons ---- */
.btn .btn-label {
    display: none;
}
@media (min-width: 400px) {
    .btn .btn-label {
        display: inline;
    }
}

/* ---- QR Scanner ---- */
.qr-scanner-container {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.qr-scanner-container video {
    width: 100%;
    display: block;
}

.qr-scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.qr-scanner-overlay .scan-area {
    width: 200px;
    height: 200px;
    border: 2px solid var(--accent);
    border-radius: 16px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
}

.qr-result {
    text-align: center;
    padding: 1rem;
}

.qr-result .bi-check-circle-fill { font-size: 3rem; }
.qr-result .bi-x-circle-fill { font-size: 3rem; }

/* ============================================
   SIDEBAR (hidden on mobile, visible on desktop)
   ============================================ */

#sidebar {
    display: none;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand i {
    font-size: 1.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0.5rem 0;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.sidebar-item.active {
    background: rgba(255,255,255,0.12);
    color: white;
    border-left-color: var(--accent);
}

.sidebar-item i {
    font-size: 1.15rem;
    width: 1.5rem;
    text-align: center;
}

/* ============================================
   DESKTOP LAYOUT (>=992px)
   ============================================ */

@media (min-width: 992px) {
    /* Show sidebar */
    #sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        background: var(--primary);
        z-index: 1100;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    }

    /* Hide bottom nav */
    #bottom-nav {
        display: none !important;
    }

    /* Shift header */
    #app-header {
        left: var(--sidebar-width);
    }

    /* Shift content */
    #app-content {
        margin-left: var(--sidebar-width);
        margin-bottom: 0;
        padding: 1.5rem 2rem;
        max-width: calc(900px + var(--sidebar-width));
    }

    /* FAB adjust */
    .fab {
        bottom: 1.5rem;
        right: 2rem;
    }

    /* Toast adjust */
    .toast-container {
        left: calc(var(--sidebar-width) + 50%);
        transform: translateX(calc(-50% - var(--sidebar-width) / 2));
    }

    /* Allow viewport scrolling */
    html, body {
        overflow: auto;
    }

    /* Wider cards */
    .card {
        border-radius: 12px;
    }

    /* Login centered card on desktop */
    .login-container {
        background: var(--gray-100);
    }

    #login-form {
        background: white;
        padding: 2rem;
        border-radius: 16px;
        box-shadow: 0 4px 24px rgba(0,0,0,0.1);
        max-width: 400px;
    }

    .login-header {
        color: var(--primary);
    }

    /* Dashboard stats bigger */
    .stat-card .stat-value {
        font-size: 2rem;
    }

    /* Profile header wider */
    .profile-header {
        max-width: 600px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Modal max width */
    .modal-dialog {
        max-width: 500px;
    }
}

/* ============================================
   CALENDARIO
   ============================================ */

.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0 0.75rem;
}

.cal-month-label {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--gray-800);
    text-transform: capitalize;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--gray-600);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1;
}
.btn-icon:hover { background: var(--gray-100); }

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-header {
    margin-bottom: 4px;
}

.cal-header > div {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-600);
    padding: 2px 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.cal-day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 2px;
    border-radius: 10px;
    cursor: pointer;
    min-height: 48px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.cal-day:hover { background: var(--gray-100); }

.cal-day--empty { cursor: default; }
.cal-day--empty:hover { background: none; }

.cal-day--weekend .cal-day-num { color: var(--gray-600); }

.cal-day--today .cal-day-num {
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.cal-day--selected {
    background: rgba(44,62,80,0.08);
    border: 1.5px solid var(--primary);
}

.cal-day-num {
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 26px;
    width: 26px;
    text-align: center;
}

.cal-dots {
    display: flex;
    gap: 3px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2px;
}

.cal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cal-loading {
    grid-column: span 7;
    text-align: center;
    padding: 2rem;
}

.cal-day-events {
    margin-top: 0.75rem;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--gray-200);
}

.cal-day-header {
    padding: 0.6rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-600);
    background: var(--gray-100);
    text-transform: capitalize;
    border-bottom: 1px solid var(--gray-200);
}

.cal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.5rem 0;
}

.cal-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--gray-600);
}

@media (min-width: 992px) {
    .cal-grid { gap: 4px; }
    .cal-day { min-height: 60px; padding: 6px 4px; }
    .cal-day-num { font-size: 0.9rem; }
}

/* ============================================
   CHAT — Lista conversazioni
   ============================================ */

.conv-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
}
.conv-item:last-child { border-bottom: none; }
.conv-item:active { background: var(--gray-50); }

.conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    margin-right: 0.875rem;
}
.conv-avatar--sm {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
}

.conv-body {
    flex: 1;
    min-width: 0;
}
.conv-name {
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-preview {
    font-size: 0.8rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.1rem;
}

.conv-item.is-unread .conv-name { font-weight: 700; color: var(--gray-800); }
.conv-item.is-unread .conv-preview { color: var(--gray-700); font-weight: 500; }
.conv-item.is-unread .conv-time { color: var(--accent); font-weight: 600; }

.conv-right {
    text-align: right;
    flex-shrink: 0;
    margin-left: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}
.conv-time {
    font-size: 0.72rem;
    color: var(--gray-500);
    white-space: nowrap;
}
.conv-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.2em 0.55em;
    border-radius: 999px;
    min-width: 1.4em;
    text-align: center;
    line-height: 1.4;
}

/* Chat search bar */
.conv-search {
    position: relative;
    padding: 0.625rem 1rem 0.5rem;
    background: #fff;
    border-bottom: 1px solid var(--gray-100);
}
.conv-search input {
    background: var(--gray-100);
    border: none;
    border-radius: 999px;
    padding: 0.45rem 0.9rem 0.45rem 2.1rem;
    font-size: 0.875rem;
    width: 100%;
}
.conv-search input:focus { outline: none; background: var(--gray-200); }
.conv-search .bi {
    position: absolute;
    left: 1.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-500);
    font-size: 0.9rem;
    pointer-events: none;
}

/* FAB per nuova conversazione (sovrascrive posizione .fab generica nel contesto chat) */
.chat-fab {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(52,152,219,0.4);
    z-index: 10;
    transition: transform 0.15s;
}
.chat-fab:active { transform: scale(0.91); }

/* ============================================
   CHAT — Thread
   ============================================ */

/* Remove #app-content padding when chat thread is rendered */
#app-content:has(.chat-screen) {
    padding: 0;
}

.chat-screen {
    display: flex;
    flex-direction: column;
    background: var(--gray-50);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem 0.5rem 0.5rem;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-msg-list {
    flex: 1;
    padding: 0.75rem 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Day separator */
.chat-day-sep {
    text-align: center;
    margin: 0.75rem 0 0.5rem;
}
.chat-day-sep span {
    background: rgba(0,0,0,0.07);
    color: var(--gray-700);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2em 0.75em;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

/* Message rows */
.chat-row {
    display: flex;
    margin-bottom: 0.2rem;
}
.chat-row--out { justify-content: flex-end; }
.chat-row--in  { justify-content: flex-start; }
.chat-row--grouped { margin-bottom: 0.1rem; }
.chat-row--last-in-group { margin-bottom: 0.5rem; }

/* Bubbles */
.chat-bubble {
    max-width: 78%;
    padding: 0.45rem 0.7rem;
    border-radius: 1.1rem;
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.07);
    position: relative;
}
.chat-bubble--out {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 0.3rem;
}
.chat-bubble--in {
    background: #fff;
    color: var(--gray-800);
    border-bottom-left-radius: 0.3rem;
}
/* No tail on grouped bubbles */
.chat-bubble--grouped.chat-bubble--out { border-radius: 1.1rem; }
.chat-bubble--grouped.chat-bubble--in  { border-radius: 1.1rem; }

/* Meta (time + ticks) */
.chat-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem;
    margin-top: 0.2rem;
    font-size: 0.68rem;
    opacity: 0.75;
}
.chat-bubble--out .chat-meta { color: rgba(255,255,255,0.85); }
.chat-bubble--in  .chat-meta { color: var(--gray-500); }

.chat-ticks { font-size: 0.82rem; line-height: 1; }
.chat-ticks.is-read { color: #aee1ff; }

/* Scroll-to-bottom button — floats above the compose bar */
.chat-scroll-down {
    position: absolute;
    top: -48px;
    right: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    cursor: pointer;
    z-index: 10;
    transition: opacity 0.2s;
}

/* Compose bar — sticky at bottom of scroll container */
.chat-compose {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem calc(0.5rem + var(--safe-area-bottom, 0px));
    background: #fff;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.chat-compose-wrap {
    flex: 1;
    background: var(--gray-100);
    border-radius: 1.2rem;
    padding: 0.4rem 0.85rem;
    display: flex;
    align-items: flex-end;
}
.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.925rem;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    padding: 0;
    font-family: inherit;
    color: var(--gray-800);
}
.chat-input::placeholder { color: var(--gray-500); }
.chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}
.chat-send:active { background: var(--accent-light); transform: scale(0.92); }
.chat-send:disabled { background: var(--gray-400); }
@keyframes ctBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}
