/* ══════════════════════════════════════════════════════════
   Tablet / small desktop
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .tooth { max-width: 55px; min-width: 35px; }
    .tooth-id-button { max-width: 55px; min-width: 35px; }
}

/* ══════════════════════════════════════════════════════════
   Mobile — 768px
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Header ─────────────────────────────────────────── */
    .header { position: relative; }

    .header-content {
        padding: 0.7rem 1rem;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.5rem;
        align-items: center;
    }

    /* Logo — flex: 1 so it fills space between logo and right side */
    .title { flex: 1; min-width: 0; }

    /* Hide the "Odontograma" subtitle on very small screens */
    .title .logo-text span:last-child { display: none; }

    /* Shrink logo image a bit */
    .title img.logo-svg { height: 28px; }

    /* User area — stay in one row, truncate name */
    .header-user { gap: 0.5rem; }
    .header-user-name { max-width: 90px; font-size: 0.75rem; }
    .btn-upgrade-header { padding: 0.2rem 0.5rem; font-size: 0.65rem; }
    .btn-upgrade-header i { margin-right: 0.2rem; }

    /* Settings menu — better positioning on mobile */
    .settings-menu { right: -0.5rem; }
    .settings-menu-item { padding: 0.5rem 0.875rem; font-size: 0.85rem; }

    /* ── Main layout ────────────────────────────────────── */
    .layout { padding: 0 0.875rem; gap: 1rem; }

    .main-cards {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .procedures-accordion { max-height: 300px; }

    /* ── Legend ─────────────────────────────────────────── */
    .legend-items {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem 0.75rem;
    }

    /* ── Modal — compact padding for small screens ───────── */
    .modal-content { width: 95%; margin: 0.75rem; max-height: 95vh; }
    .modal-header { padding: 0.875rem 1rem; }
    .modal-title { font-size: 1rem; }
    .modal-body { padding: 1rem; }
    .modal-footer { padding: 0.75rem 1rem; gap: 0.5rem; }

    /* ── Procedures filters — horizontal scroll ─────────── */
    .procedures-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.25rem;
    }

    .procedures-filters::-webkit-scrollbar { display: none; }

    .filter-btn { flex-shrink: 0; }

    /* ── Odontogram — mobile 3-line tooth layout ─────────── */
    .teeth-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(45px, 1fr));
        gap: 0.5rem;
        justify-items: center;
        overflow-x: visible;
        padding: 1rem 0;
    }

    .tooth-container.mobile-left-molars  { grid-row: 1; }
    .tooth-container.mobile-non-molars   { grid-row: 2; }
    .tooth-container.mobile-right-molars { grid-row: 3; }

    .tooth { max-width: 50px; min-width: 45px; height: 50px; min-height: 45px; }

    .tooth-id-button {
        max-width: 50px; min-width: 45px;
        font-size: 0.7rem; padding: 0.3rem 0.4rem;
        height: auto; min-height: 24px;
        cursor: pointer;
    }

    .tooth-id-button:hover, .tooth-id-button:active {
        transform: scale(1.05);
        box-shadow: 0 2px 4px rgba(0,0,0,.2);
    }
    .tooth-id-button:active { transform: scale(0.95); }

    .tooth-area { min-height: 12px; min-width: 12px; border-width: 1.5px; }
    .tooth-area:hover, .tooth-area:active { transform: scale(1.05); box-shadow: 0 2px 4px rgba(0,0,0,.2); z-index: 2; position: relative; }
    .tooth-area:active { transform: scale(0.95); }

    .teeth-section { margin-bottom: 2.5rem; }
    .teeth-section .section-label { margin-bottom: 1.2rem; font-size: 1.1rem; font-weight: 600; }

    .odontogram-wrapper { padding: 1.5rem 1rem; overflow-x: visible; }

    /* ── Editor topbar — compact on mobile ───────────────── */
    .editor-topbar { gap: 0.5rem; }

    /* ── Subscription modal — compact body ───────────────── */
    .sub-mgmt-body { padding: 0.875rem 0; }

    /* ── Upgrade modal body — less padding ───────────────── */
    .upgrade-modal-body { padding: 1.5rem 1.25rem 1.25rem !important; }
}

/* ══════════════════════════════════════════════════════════
   Mobile — 640px (small tablets / large phones)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* ── Profile modal — force single-column layout ──────── */
    .profile-grid-container {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    /* ── Subscription plan cards stack sooner ─────────────── */
    .subscription-plan-grid { grid-template-columns: 1fr; }
    .subscription-free-card { flex-direction: column; align-items: flex-start; }

    /* ── Team modal add form — single column ─────────────── */
    .team-add-grid { grid-template-columns: 1fr !important; }

    /* ── Clinic seats modal — no min-width on inner cards ─── */
    .clinic-seats-cards { flex-direction: column; }
    .clinic-seats-card { min-width: 0 !important; width: 100%; }

    /* ── Editor topbar — smaller gap, allow wrap ─────────── */
    .editor-topbar {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding-bottom: 0.5rem;
    }
    .editor-patient-label {
        order: 3;
        flex-basis: 100%;
        font-size: 0.8rem;
    }

    /* ── Quick chart banner — tighter ────────────────────── */
    .quick-chart-banner { padding: 0.5rem 0.875rem; font-size: 0.75rem; }
    .quick-chart-banner-actions { flex-wrap: wrap; }

    /* ── Modal tabs — horizontal scroll on narrow screens ─── */
    .modal-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .modal-tabs::-webkit-scrollbar { display: none; }
    .modal-tab {
        flex-shrink: 0;
        padding: 0.75rem 0.875rem;
        font-size: 0.78rem;
    }
}

/* ══════════════════════════════════════════════════════════
   Mobile — 480px (small phones)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .header-content { padding: 0.6rem 0.875rem; }

    .title img.logo-svg { height: 26px; }

    .plan-badge { display: none; }

    .header-user-name { max-width: 60px; }

    .layout { padding: 0 0.75rem; }

    .legend-items { grid-template-columns: repeat(2, 1fr); }

    .card { padding: 0.875rem; }

    .teeth-row {
        grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
        gap: 0.4rem; padding: 0.8rem 0;
    }

    .tooth { max-width: 45px; min-width: 40px; height: 45px; min-height: 40px; }

    .tooth-id-button {
        max-width: 45px; min-width: 40px;
        font-size: 0.65rem; padding: 0.25rem 0.3rem; min-height: 22px;
    }

    .tooth-id-button:hover, .tooth-id-button:active { transform: scale(1.1); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
    .tooth-id-button:active { transform: scale(0.9); }

    .tooth-area { min-height: 10px; min-width: 10px; border-width: 1px; }
    .tooth-area:hover, .tooth-area:active { transform: scale(1.1); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
    .tooth-area:active { transform: scale(0.9); }

    .teeth-section { margin-bottom: 2rem; }
    .odontogram-wrapper { padding: 1rem 0.5rem; }

    /* ── Modal footer — stack buttons vertically ─────────── */
    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .modal-footer .btn { justify-content: center; width: 100%; }

    /* ── Modal body — minimal padding ────────────────────── */
    .modal-body { padding: 0.875rem; }
    .modal-header { padding: 0.75rem 0.875rem; }

    /* ── Hide back button label (icon stays) ─────────────── */
    .back-btn-label { display: none; }

    /* ── Team add form — single column ───────────────────── */
    .team-add-grid { grid-template-columns: 1fr !important; }

    /* ── Upgrade modal body — minimal padding ─────────────── */
    .upgrade-modal-body { padding: 1.25rem 0.875rem 1rem !important; }

    /* ── Clinic seats — full width ───────────────────────── */
    #clinicSeatsModal .modal-content { border-radius: 12px !important; }

    /* ── Subscription billing switch — full width ─────────── */
    .subscription-billing-switch { width: 100%; }
    .subscription-billing-switch button { flex: 1; }
}

/* ══════════════════════════════════════════════════════════
   Print
   ══════════════════════════════════════════════════════════ */
@media print {
    .header-actions, .btn, .modal, .debug-card { display: none !important; }
    .container { box-shadow: none; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}
