/* ==========================================================================
   Guia Medico Três Lagoas — Responsive Design System
   Mobile-first: base (<768px) → 768px → 1024px → 1280px
   Premium SaaS Healthcare Marketplace
   ========================================================================== */


/* ==========================================================================
   GRID SYSTEM — Mobile-first
   ========================================================================== */
.grid-2,
.grid-3,
.grid-4 {
    display: grid;
    gap: 20px;
}

/* Mobile defaults */
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }


/* ==========================================================================
   LAYOUT HELPERS
   ========================================================================== */
.content-with-sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.content-area {
    flex: 1;
    min-width: 0;
}

.sidebar-area {
    width: 100%;
}


/* ==========================================================================
   VISIBILITY UTILITIES
   ========================================================================== */
.hide-mobile       { display: none !important; }
.hide-desktop      { display: block !important; }
.show-mobile        { display: block !important; }
.show-desktop       { display: none !important; }
.show-mobile-flex   { display: flex !important; }
.show-desktop-flex  { display: none !important; }


/* ==========================================================================
   MOBILE FILTER DRAWER
   ========================================================================== */
.filter-sidebar-mobile {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: var(--bg);
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-xl);
    padding: 24px;
}

.filter-open .filter-sidebar-mobile {
    transform: translateX(0);
}

.filter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 43, 70, 0.55);
    z-index: 899;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.filter-open .filter-overlay {
    opacity: 1;
    visibility: visible;
}

.filter-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.filter-mobile-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
}

.filter-mobile-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius);
    transition: background var(--transition);
}

.filter-mobile-close:hover {
    background: var(--bg-alt);
}

.filter-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}


/* ==========================================================================
   MOBILE NAV DRAWER
   ========================================================================== */
.mobile-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 800;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                visibility 0.3s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px;
}

.nav-open .mobile-nav {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}


/* ==========================================================================
   PANEL / ADMIN SIDEBAR — Mobile drawer
   ========================================================================== */
.panel-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 850;
    background: var(--primary);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-open .panel-sidebar {
    transform: translateX(0);
}

.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 43, 70, 0.55);
    z-index: 849;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.sidebar-open .panel-overlay {
    opacity: 1;
    visibility: visible;
}

.panel-content {
    margin-left: 0;
    transition: margin-left 0.3s ease;
}

.panel-main {
    padding: 20px 16px;
}


/* ==========================================================================
   MOBILE BASE STYLES (<768px)
   ========================================================================== */

/* Typography scale-down */
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }

/* Section padding reduction */
.section     { padding: 32px 0; }
.section-lg  { padding: 40px 0; }

/* Larger-touch checkboxes/radios on mobile */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}
.checkbox-label,
label.checkbox-card {
    min-height: 44px;
    cursor: pointer;
}

/* Form rows stack */
.form-row {
    flex-direction: column;
    gap: 0;
}

/* Footer — single column */
.footer-grid {
    grid-template-columns: 1fr;
    text-align: center;
}

.footer-links {
    align-items: center;
}

.footer-contact-item {
    justify-content: center;
}

/* Table — horizontal scroll (default) */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 600px;
}

/* Table as cards — opt-in via `.table-cards` on <table>.
   In mobile (<768px), each row becomes a stacked card with
   data-label headers in front of each td. */
.table-responsive:has(.table-cards) {
    overflow-x: visible;
}
.table-cards {
    min-width: 0 !important;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.table-cards thead { display: none; }
.table-cards tbody,
.table-cards tr,
.table-cards td { display: block; width: 100%; }
.table-cards tr {
    background: #fff;
    border: 1px solid #e5e9f0;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.table-cards td {
    padding: 6px 0;
    border: none !important;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    font-size: .875rem;
}
.table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .3px;
    flex-shrink: 0;
    min-width: 90px;
}
.table-cards td[data-label=""]::before,
.table-cards td:not([data-label])::before { display: none; }
.table-cards td[colspan] {
    justify-content: center;
    text-align: center;
}
.table-cards td[colspan]::before { display: none; }

/* Admin dropdown user-menu — prevent viewport overflow on mobile */
.panel-topbar-right .dropdown-menu {
    max-width: 90vw;
    right: 0;
}

/* Avatar upload — stack vertically on very small screens */
@media (max-width: 479px) {
    .avatar-upload { flex-direction: column; align-items: flex-start; gap: 12px; }
    .profile-avatar-group { text-align: center; }
}

/* Modal — fullscreen on mobile */
.modal-backdrop {
    padding: 0;
}

.modal {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    border-radius: 0;
    margin: 0;
}

/* Pagination — compact on mobile */
.pagination {
    gap: 4px;
}

.page-link {
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    font-size: 0.8125rem;
}

/* Map hidden by default on mobile */
.search-map-section {
    display: none;
}

.search-map-mobile {
    display: block;
}

/* Doctor card — compact horizontal layout on mobile */
.doctor-card {
    flex-direction: row;
    align-items: stretch;
}

.doctor-card-avatar {
    width: 120px;
    min-width: 120px;
    max-width: 120px;
    height: auto;
    align-self: stretch;
}

.doctor-card-avatar .avatar-placeholder {
    width: 64px;
    height: 64px;
    font-size: 1.625rem;
}

.doctor-card-body {
    padding: 14px 14px 14px 16px;
    min-width: 0;
}

.doctor-card-name {
    font-size: 1rem;
    line-height: 1.25;
}

.doctor-card-specialty {
    font-size: 0.75rem;
    margin-bottom: 6px;
}

.doctor-card-location {
    font-size: 0.75rem;
    margin-bottom: 8px;
}

.doctor-card-rating {
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.doctor-card-footer,
.doctor-card-actions {
    padding-top: 10px;
    gap: 8px;
    flex-wrap: wrap;
}

.doctor-card-price .price-value {
    font-size: 1rem;
}

/* Very small screens — make footer stack if needed */
@media (max-width: 360px) {
    .doctor-card-avatar {
        width: 96px;
        min-width: 96px;
        max-width: 96px;
    }

    .doctor-card-body {
        padding: 12px;
    }

    .doctor-card-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .doctor-card-footer .btn {
        width: 100%;
    }
}

/* Dashboard cards — 1-2 columns */
.dashboard-cards {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

/* Register cards — single column */
.register-cards {
    grid-template-columns: 1fr;
}

/* Header — hamburger visible, nav hidden */
.header-nav {
    display: none;
}

.hamburger {
    display: flex;
}


/* ==========================================================================
   TABLET — 768px+
   ========================================================================== */
@media (min-width: 768px) {

    /* --- Typography --- */
    h1 { font-size: 2rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }

    /* --- Grid --- */
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    /* --- Sections --- */
    .section    { padding: 48px 0; }
    .section-lg { padding: 64px 0; }

    /* --- Header/Nav --- */
    .header-nav {
        display: flex;
    }

    .hamburger {
        display: none;
    }

    .mobile-nav {
        display: none !important;
    }

    /* --- Visibility --- */
    .hide-mobile       { display: block !important; }
    .hide-mobile-flex  { display: flex !important; }
    .hide-desktop      { display: none !important; }
    .show-mobile        { display: none !important; }
    .show-desktop       { display: block !important; }
    .show-mobile-flex   { display: none !important; }
    .show-desktop-flex  { display: flex !important; }

    /* --- Footer — 3 columns --- */
    .footer-grid {
        grid-template-columns: 1.5fr 1fr 1fr;
        text-align: left;
    }

    .footer-links {
        align-items: flex-start;
    }

    .footer-contact-item {
        justify-content: flex-start;
    }

    /* --- Form rows side-by-side --- */
    .form-row {
        flex-direction: row;
        gap: 16px;
    }

    /* --- Doctor cards — horizontal layout --- */
    .doctor-card {
        flex-direction: row;
        align-items: stretch;
    }

    .doctor-card-avatar {
        width: 180px;
        min-width: 180px;
        max-width: 180px;
        height: auto;
        align-self: stretch;
    }

    .doctor-card-body {
        padding: 20px 24px;
    }


    /* --- Modal — centered card --- */
    .modal-backdrop {
        padding: 40px 20px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal {
        width: auto;
        max-width: 520px;
        min-height: auto;
        border-radius: var(--radius-lg);
        margin: auto;
        box-shadow: var(--shadow-xl);
    }

    /* --- Map — visible on tablet --- */
    .search-map-section {
        display: block;
    }

    /* --- Filter sidebar — still drawer on tablet portrait --- */
    .filter-toggle-btn {
        display: inline-flex;
    }

    /* --- Register cards — 2 columns --- */
    .register-cards {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }

    /* --- Auth card restored padding --- */
    .auth-card {
        padding: 40px 36px;
    }

    /* --- Dashboard cards — 2-3 columns --- */
    .dashboard-cards {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    /* --- Pagination --- */
    .page-link {
        min-width: 40px;
        height: 40px;
        font-size: 0.875rem;
    }

    /* --- Panel sidebar — still off-screen on tablet --- */
    .panel-sidebar {
        transform: translateX(-100%);
    }

    .panel-content {
        margin-left: 0;
    }
}


/* ==========================================================================
   DESKTOP — 1024px+
   ========================================================================== */
@media (min-width: 1024px) {

    /* --- Grid --- */
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }

    /* --- Sidebar layout --- */
    .content-with-sidebar {
        flex-direction: row;
    }

    .sidebar-area {
        width: 280px;
        flex-shrink: 0;
    }

    /* --- Filter sidebar — inline on desktop --- */
    .filter-sidebar-mobile {
        position: static;
        transform: none;
        box-shadow: none;
        width: 100%;
        max-width: none;
        padding: 0;
        overflow-y: visible;
    }

    .filter-overlay {
        display: none !important;
    }

    .filter-mobile-header {
        display: none;
    }

    .filter-toggle-btn {
        display: none;
    }

    /* --- Search layout — sidebar + content side by side --- */
    .search-layout {
        flex-direction: row;
    }

    /* --- Profile card — row layout on desktop --- */
    .profile-card-top {
        flex-direction: row;
        align-items: flex-start;
        text-align: left;
    }

    .profile-card-info {
        align-items: flex-start;
    }

    .profile-rating {
        justify-content: flex-start;
    }

    .profile-card-insurances {
        justify-content: flex-start;
    }

    .profile-actions {
        justify-content: flex-start;
    }

    /* --- Panel/Admin sidebar — fixed inline --- */
    .panel-sidebar {
        transform: translateX(0);
        position: fixed;
    }

    .panel-content {
        margin-left: 260px;
    }

    .panel-sidebar-toggle {
        display: none;
    }

    .panel-overlay {
        display: none !important;
    }

    /* --- Typography --- */
    h1 { font-size: 2.25rem; }

    /* --- Panel main padding --- */
    .panel-main {
        padding: 32px;
    }

    /* --- Dashboard cards — 4 columns --- */
    .dashboard-cards {
        grid-template-columns: repeat(4, 1fr);
    }

    /* --- Metric cards — 4 columns --- */
    .metric-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}


/* ==========================================================================
   WIDE DESKTOP — 1280px+
   ========================================================================== */
@media (min-width: 1280px) {

    /* --- Container --- */
    .container {
        padding-left: 32px;
        padding-right: 32px;
    }

    /* --- Sidebar wider --- */
    .sidebar-area {
        width: 300px;
    }

    /* --- Grid gaps --- */
    .grid-2,
    .grid-3,
    .grid-4 {
        gap: 24px;
    }

    /* --- Panel sidebar wider --- */
    .panel-sidebar {
        width: 280px;
    }

    .panel-content {
        margin-left: 280px;
    }

    /* --- Search map taller --- */
    .search-map {
        height: 480px;
    }

    /* --- Profile section wider --- */
    .profile-section {
        max-width: 860px;
    }
}


/* ==========================================================================
   SMALL MOBILE — <375px
   ========================================================================== */
@media (max-width: 374px) {
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }

    .grid-4 {
        grid-template-columns: 1fr;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 12px 24px;
    }

    .card-body {
        padding: 16px;
    }

    .doctor-card-body {
        padding: 16px;
    }

    .pagination {
        gap: 2px;
    }

    .page-link {
        min-width: 34px;
        height: 34px;
        padding: 0 6px;
        font-size: 0.75rem;
    }

    .dashboard-cards {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 24px 16px;
    }

    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.125rem; }

    /* Tighter sections & topbar on tiny screens */
    .section    { padding: 24px 0; }
    .section-lg { padding: 28px 0; }
    .panel-topbar { padding: 0 12px !important; }

    /* Admin sidebar logo fits narrower drawer */
    .admin-sidebar .panel-sidebar-header img {
        max-width: 180px;
        height: auto;
    }
}


/* ==========================================================================
   PRINT STYLES
   ========================================================================== */
@media print {
    /* Hide interactive elements */
    .site-header,
    .site-footer,
    .hamburger,
    .mobile-nav,
    .panel-sidebar,
    .panel-topbar,
    .panel-sidebar-toggle,
    .btn,
    .alert-flash,
    .filter-sidebar,
    .filter-sidebar-mobile,
    .filter-overlay,
    .filter-toggle-btn,
    .pagination,
    .search-mobile-controls,
    .profile-actions,
    .quick-links,
    .breadcrumb,
    .directions-btn,
    .review-form-container,
    .search-bar-form {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 12pt;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    main {
        padding-top: 0;
    }

    .panel-content {
        margin-left: 0;
    }

    .card,
    .dashboard-card,
    .review-card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }

    .profile-header {
        color: #000;
    }

    .profile-name,
    .profile-specialty,
    .profile-crm,
    .profile-price {
        color: #000;
    }

    a[href]::after {
        content: ' (' attr(href) ')';
        font-size: 0.8em;
        color: #666;
    }

    .profile-tabs {
        border-bottom: 1px solid #ddd;
    }

    .profile-tab.active {
        font-weight: 700;
        color: #000;
        border-bottom-color: #000;
    }
}
