/* =====================================================
   DentalCare Pro - Professional Stylesheet
   ===================================================== */

:root {
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --primary-light: #EEF2FF;
    --secondary: #0EA5E9;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #06B6D4;
    --dark: #1E293B;
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1E293B;
    --gray-900: #0F172A;
    --sidebar-width: 270px;
    --topbar-height: 64px;
    --border-radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--gray-50);
    color: var(--gray-800);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--gray-900) 0%, var(--gray-800) 100%);
    color: #fff;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-600) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-600); border-radius: 4px; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 10px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-brand i {
    font-size: 1.5rem;
    color: var(--secondary);
}

.sidebar-close {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1.25rem;
    cursor: pointer;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    margin: 8px 12px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--border-radius);
}

.sidebar-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
}

.sidebar-user-info h6 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
}

.sidebar-user-info small {
    color: var(--gray-400);
    font-size: 0.75rem;
}

.sidebar-nav {
    list-style: none;
    padding: 8px 12px;
    margin: 0;
}

.sidebar-nav-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gray-500);
    padding: 20px 12px 6px;
}

.sidebar-nav-item { margin-bottom: 2px; }

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-nav-link.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79,70,229,0.4);
}

.sidebar-nav-link i {
    width: 20px;
    text-align: center;
    font-size: 0.9rem;
}

.sidebar-nav-link .badge {
    font-size: 0.65rem;
    padding: 3px 8px;
}

/* =====================================================
   MAIN CONTENT
   ===================================================== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin 0.3s ease;
}

/* =====================================================
   TOPBAR
   ===================================================== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-toggler {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--gray-600);
    cursor: pointer;
    display: none;
    padding: 6px;
}

.topbar-title {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 1.1rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-icon {
    position: relative;
    background: none;
    border: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--gray-500);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.topbar-icon:hover {
    background: var(--gray-100);
    color: var(--primary);
}

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: var(--danger);
    color: #fff;
    border-radius: 50%;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.notification-dropdown {
    width: 340px;
    max-height: 400px;
    overflow-y: auto;
    padding: 0;
}

.notification-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px !important;
    border-bottom: 1px solid var(--gray-100);
}

.notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    font-size: 0.8rem;
}

.notification-content p {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.4;
}

.notification-content small {
    font-size: 0.75rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: 50px;
    padding: 4px 14px 4px 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.topbar-user:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.topbar-user img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

.topbar-user span {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

/* =====================================================
   PAGE CONTENT
   ===================================================== */
.page-content {
    padding: 24px;
}

/* =====================================================
   CARDS
   ===================================================== */
.card {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    background: #fff;
    overflow: hidden;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h5, .card-header h6 {
    margin: 0;
    font-weight: 600;
}

.card-body { padding: 20px; }

/* Stat Cards */
.stat-card {
    border: none;
    border-radius: var(--border-radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 16px;
}

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

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-weight: 500;
}

.stat-card.stat-primary { background: #fff; border: 1px solid var(--gray-200); }
.stat-card.stat-primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.stat-primary .stat-value { color: var(--primary); }

.stat-card.stat-success { background: #fff; border: 1px solid var(--gray-200); }
.stat-card.stat-success .stat-icon { background: #D1FAE5; color: var(--success); }
.stat-card.stat-success .stat-value { color: var(--success); }

.stat-card.stat-warning { background: #fff; border: 1px solid var(--gray-200); }
.stat-card.stat-warning .stat-icon { background: #FEF3C7; color: var(--warning); }
.stat-card.stat-warning .stat-value { color: var(--warning); }

.stat-card.stat-info { background: #fff; border: 1px solid var(--gray-200); }
.stat-card.stat-info .stat-icon { background: #CFFAFE; color: var(--info); }
.stat-card.stat-info .stat-value { color: var(--info); }

.stat-card.stat-danger { background: #fff; border: 1px solid var(--gray-200); }
.stat-card.stat-danger .stat-icon { background: #FEE2E2; color: var(--danger); }
.stat-card.stat-danger .stat-value { color: var(--danger); }

/* =====================================================
   TABLES
   ===================================================== */
.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table thead th {
    background: var(--gray-50);
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--gray-200);
    padding: 12px 16px;
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--gray-100);
}

.table tbody tr:hover {
    background: var(--gray-50);
}

.table-responsive {
    border-radius: var(--border-radius);
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 10px;
    padding: 8px 18px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(79,70,229,0.3);
}

.btn-success { background: var(--success); border-color: var(--success); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
    border-radius: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

/* =====================================================
   FORMS
   ===================================================== */
.form-control, .form-select {
    border-radius: 10px;
    border: 1px solid var(--gray-300);
    padding: 10px 14px;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.input-group .form-control {
    border-radius: 10px;
}

.input-group .btn,
.input-group .input-group-text {
    border-radius: 10px;
}

/* =====================================================
   BADGES
   ===================================================== */
.badge {
    font-weight: 600;
    font-size: 0.7rem;
    padding: 5px 10px;
    border-radius: 8px;
    letter-spacing: 0.3px;
}

/* =====================================================
   MODAL
   ===================================================== */
.modal-content {
    border: none;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 24px;
}

.modal-body { padding: 24px; }

.modal-footer {
    border-top: 1px solid var(--gray-200);
    padding: 16px 24px;
}

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
    border-radius: var(--border-radius);
    border: none;
    font-size: 0.875rem;
    padding: 14px 20px;
}

/* =====================================================
   PAGINATION
   ===================================================== */
.pagination .page-link {
    border-radius: 10px !important;
    margin: 0 2px;
    font-size: 0.85rem;
    color: var(--gray-600);
    border-color: var(--gray-200);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* =====================================================
   SIDEBAR OVERLAY (MOBILE)
   ===================================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
    backdrop-filter: blur(2px);
}

/* =====================================================
   EMPTY STATE
   ===================================================== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-400);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state h6 {
    color: var(--gray-600);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.875rem;
    margin-bottom: 20px;
}

/* =====================================================
   APPOINTMENT STATUS TIMELINE
   ===================================================== */
.status-timeline {
    display: flex;
    gap: 4px;
    align-items: center;
}

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

.status-dot.active { background: var(--success); }
.status-dot.current { background: var(--primary); animation: pulse 2s infinite; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(79,70,229,0.4); }
    50% { box-shadow: 0 0 0 6px rgba(79,70,229,0); }
}

/* =====================================================
   PATIENT AVATAR ROW
   ===================================================== */
.patient-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.patient-info img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
}

.patient-info .name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-800);
}

.patient-info .sub {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* =====================================================
   ODONTOGRAM
   ===================================================== */
.odontogram-chart {
    padding: 15px;
    overflow-x: auto;
}

.tooth-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: nowrap;
}

.tooth-row.deciduous {
    margin: 0 auto;
    max-width: 70%;
}

.quadrant-label {
    font-size: 0.65rem;
    color: var(--gray-400);
    min-width: 60px;
    text-align: center;
    white-space: nowrap;
}

.quadrant-divider {
    width: 3px;
    height: 60px;
    background: var(--gray-300);
    margin: 0 4px;
    border-radius: 2px;
}

.teeth-container {
    display: flex;
    gap: 2px;
}

.tooth-cell {
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    position: relative;
    padding: 2px;
    border-radius: 4px;
}

.tooth-cell:hover {
    background: var(--gray-100);
}

.tooth-cell.selected {
    background: var(--primary-light);
    outline: 2px solid var(--primary);
}

.tooth-number {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 1px;
}

.tooth-surface {
    width: 36px;
    height: 36px;
    position: relative;
    margin: 0 auto;
}

.tooth-surface.small-tooth {
    width: 28px;
    height: 28px;
}

.surface {
    position: absolute;
    border: 1px solid var(--gray-300);
    background: #fff;
    cursor: pointer;
    transition: background 0.15s;
}

.surface:hover {
    border-color: var(--primary);
    opacity: 0.8;
}

.surface.marked {
    border-color: rgba(0,0,0,0.3);
}

/* 5-surface layout */
.s-top { top: 0; left: 25%; width: 50%; height: 25%; border-radius: 4px 4px 0 0; }
.s-bottom { bottom: 0; left: 25%; width: 50%; height: 25%; border-radius: 0 0 4px 4px; }
.s-left { top: 25%; left: 0; width: 25%; height: 50%; border-radius: 4px 0 0 4px; }
.s-right { top: 25%; right: 0; width: 25%; height: 50%; border-radius: 0 4px 4px 0; }
.s-center { top: 25%; left: 25%; width: 50%; height: 50%; }

.tooth-condition {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 2;
}

.tooth-cell.tooth-missing .tooth-surface .surface { background: var(--gray-200) !important; }
.tooth-cell.tooth-missing .tooth-condition { color: var(--danger); }
.tooth-cell.tooth-crown .tooth-surface .surface { border-color: var(--info); }
.tooth-cell.tooth-bridge .tooth-surface .surface { border-color: var(--success); }
.tooth-cell.tooth-implant .tooth-surface .surface { border-color: #6f42c1; }

.avatar-lg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.text-purple { color: #6f42c1 !important; }
.wa-badge { background: #25D366; color: #fff; }

.status-connected {
    text-align: center;
    color: var(--success);
    padding: 30px;
}

@media (max-width: 767px) {
    .tooth-surface { width: 28px; height: 28px; }
    .tooth-surface.small-tooth { width: 22px; height: 22px; }
    .tooth-number { font-size: 0.5rem; }
    .quadrant-label { min-width: 40px; font-size: 0.55rem; }
    .tooth-row.deciduous { max-width: 90%; }
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 440px;
    padding: 40px;
}

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

.login-card .logo i {
    font-size: 3rem;
    color: var(--primary);
}

.login-card .logo h3 {
    font-weight: 700;
    color: var(--gray-800);
    margin-top: 8px;
}

.login-card .logo p {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* =====================================================
   CHARTS CONTAINER
   ===================================================== */
.chart-container {
    position: relative;
    height: 280px;
}

/* =====================================================
   QR CODE CONTAINER (WA)
   ===================================================== */
.qr-container {
    text-align: center;
    padding: 30px;
    background: var(--gray-50);
    border-radius: var(--border-radius);
    border: 2px dashed var(--gray-300);
}

.qr-container img {
    max-width: 280px;
    border-radius: 12px;
}

.qr-container .status-connected {
    color: var(--success);
    font-weight: 600;
    font-size: 1.1rem;
}

/* =====================================================
   WHATSAPP BADGE
   ===================================================== */
.wa-badge {
    background: #25D366;
    color: #fff;
}

/* =====================================================
   SEARCH BAR
   ===================================================== */
.search-box {
    position: relative;
    max-width: 300px;
}

.search-box input {
    padding-left: 40px;
    border-radius: 50px;
    background: var(--gray-50);
    border-color: var(--gray-200);
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 0.85rem;
}

/* =====================================================
   SELECT2 OVERRIDES
   ===================================================== */
.select2-container--bootstrap-5 .select2-selection {
    border-radius: 10px !important;
    border-color: var(--gray-300) !important;
    min-height: 42px !important;
}

/* =====================================================
   UTILITY
   ===================================================== */
.text-primary { color: var(--primary) !important; }
.bg-primary-light { background: var(--primary-light) !important; }
.fw-600 { font-weight: 600; }
.fs-sm { font-size: 0.875rem; }
.fs-xs { font-size: 0.75rem; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar-overlay.show {
        display: block;
    }
    .main-content {
        margin-left: 0;
    }
    .topbar-toggler {
        display: block !important;
    }
}

@media (max-width: 767.98px) {
    .page-content {
        padding: 16px;
    }
    .stat-card .stat-value {
        font-size: 1.3rem;
    }
    .topbar {
        padding: 0 16px;
    }
    .card-header {
        padding: 12px 16px;
    }
    .card-body {
        padding: 16px;
    }
    .notification-dropdown {
        width: 300px;
    }
    .table thead th, .table tbody td {
        padding: 10px 12px;
    }
}

@media (max-width: 575.98px) {
    .login-card {
        padding: 24px;
    }
    .stat-card {
        padding: 16px;
    }
}

/* =====================================================
   PRINT
   ===================================================== */
@media print {
    .sidebar, .topbar, .sidebar-overlay, .btn, .no-print {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .page-content {
        padding: 0 !important;
    }
}
