/* OSHweb Design System */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
    /* Brand Colors */
    --color-primary: #1565c0;
    --color-primary-dark: #0d47a1;
    --color-secondary: #008b94;
    --color-accent: #20b8be;

    /* Functional */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;

    /* Backgrounds */
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-sidebar: #0d182a;

    /* Text */
    --color-text-main: #0d182a;
    --color-text-muted: #4a5d7a;
    --color-text-light: #7e90ac;

    /* Borders & Radius */
    --border-color: #e2e8f0;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 280px;
    --topbar-height: 60px;
}

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

body {
    font-family: 'Poppins', sans-serif;
    background: var(--color-bg);
    color: var(--color-text-main);
    min-height: 100vh;
    /* Removed overflow: hidden and fixed height to allow native page scrolling */
}

body.mobile-nav-open {
    overflow: hidden;
}

/* --- Sidebar --- */
.app-sidebar {
    width: var(--sidebar-width);
    background:
        radial-gradient(130% 48% at 12% 104%, rgba(34, 211, 238, 0.14) 0%, rgba(34, 211, 238, 0) 62%),
        radial-gradient(120% 42% at 88% 96%, rgba(14, 165, 233, 0.12) 0%, rgba(14, 165, 233, 0) 58%),
        radial-gradient(100% 35% at 38% 86%, rgba(125, 211, 252, 0.08) 0%, rgba(125, 211, 252, 0) 60%),
        linear-gradient(180deg, #1b1f2a 0%, #222938 55%, #2b3346 100%) !important;
    color: white;
    display: flex;
    flex-direction: column;
    padding: 0.9rem 0.85rem;

    /* Fixed positioning for sidebar */
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;

    box-shadow: 6px 0 24px rgba(13, 24, 42, 0.28);
    z-index: 50;
    overflow-y: auto;
    overflow-x: hidden;
    position: fixed;
    transition: transform 0.25s ease;
}

.app-sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(140% 30% at -10% 70%, rgba(34, 211, 238, 0.1) 0%, rgba(34, 211, 238, 0) 62%),
        radial-gradient(140% 26% at 120% 62%, rgba(56, 189, 248, 0.08) 0%, rgba(56, 189, 248, 0) 60%),
        radial-gradient(150% 24% at 25% 56%, rgba(125, 211, 252, 0.06) 0%, rgba(125, 211, 252, 0) 58%);
}

.app-sidebar>* {
    position: relative;
    z-index: 1;
}

/* Logo Section */
.brand {
    margin-bottom: 0.55rem;
    text-align: center;
    display: flex;
    justify-content: center;
    padding: 0 0.5rem;
}

.brand-logo-link {
    text-decoration: none;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.35rem 0.55rem;
    border-radius: 12px;
    border: 1px solid rgba(203, 213, 225, 0.95);
    background: rgba(248, 250, 252, 0.96);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.24);
    backdrop-filter: blur(1px);
}

.brand-logo-image {
    max-height: 116px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.2));
}

.brand img {
    max-width: 220px;
    width: auto;
    height: auto;
    background: transparent;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

img[src*="logo_medixec.png"] {
    max-width: min(100%, 340px);
    max-height: 130px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.user-profile-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0.45rem;
    text-align: center;
    width: 100%;
}

.user-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: white;
    border: 3px solid rgba(255, 255, 255, 0.4);
    margin-bottom: 0.35rem;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.user-name {
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.12rem;
    line-height: 1.1;
}

.user-role {
    font-size: 0.72rem;
    opacity: 0.9;
    line-height: 1.1;
}

/* Navigation */
.nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    width: 100%;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.12rem 0.45rem !important;
    color: white;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition);
    font-weight: 500;
    font-size: 0.64rem;
    min-height: 14px !important;
    line-height: 1.05;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(10px);
    transform: translateX(5px);
}

.nav-item i {
    margin-right: 6px;
    width: 12px;
    text-align: center;
    font-size: 0.68rem;
}

@media (max-height: 760px) {
    .app-sidebar {
        padding-top: 0.6rem;
        padding-bottom: 0.6rem;
    }

    .brand {
        margin-bottom: 0.35rem;
    }

    .brand-logo-link {
        padding: 0.26rem 0.4rem;
    }

    .brand-logo-image {
        max-height: 98px;
    }

    .nav-links {
        gap: 0.08rem;
    }

    .nav-item {
        min-height: 14px !important;
        font-size: 0.69rem;
        padding: 0.12rem 0.45rem !important;
        line-height: 1.05;
    }

    .user-avatar {
        width: 48px;
        height: 48px;
        margin-bottom: 0.22rem;
    }

    .user-name {
        font-size: 0.75rem;
    }

    .user-role {
        font-size: 0.65rem;
    }

    .user-profile-summary span {
        display: none;
    }
}

/* --- Main Content --- */
.app-main {
    margin-left: var(--sidebar-width);
    /* Offset for fixed sidebar */
    padding: calc(2rem + var(--topbar-height)) 3rem 2rem;
    position: relative;
    background: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
}

.app-main img {
    max-width: 100%;
    height: auto;
}

/* --- Global Top Bar --- */
.global-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 70;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    gap: 0.8rem;
}

.sidebar-mobile-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    border: 1px solid #dbe6f2;
    border-radius: 10px;
    background: #ffffff;
    color: #1e293b;
    z-index: 95;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    max-width: 560px;
    background: #f8fbff;
    border: 1px solid #dbe6f2;
    border-radius: 12px;
    padding: 0.55rem 0.8rem;
    min-width: 230px;
}

.topbar-search i {
    color: #6c829a;
}

.topbar-search input {
    border: none;
    background: transparent;
    width: 100%;
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
    color: #1e293b;
}

.topbar-search input:focus {
    outline: none;
    box-shadow: none;
}

.global-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 1.5rem;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow: hidden;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 38px;
    padding: 0.5rem 0.95rem;
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}

.global-topbar-actions .topbar-btn {
    height: 38px;
    box-sizing: border-box;
}

.global-topbar-actions .topbar-btn i {
    font-size: 0.95rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.topbar-btn.topbar-support {
    color: #0f766e;
    background: #ecfeff;
    border: 1px solid #99f6e4;
}

.topbar-btn.topbar-support:hover {
    background: #cffafe;
}

.topbar-btn.topbar-whatsapp {
    color: #065f46;
    background: #ecfdf5;
    border: 1px solid #86efac;
    padding-top: 0;
    padding-bottom: 0;
}

.topbar-btn.topbar-whatsapp:hover {
    background: #d1fae5;
}

.topbar-btn.topbar-whatsapp i {
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    transform: none !important;
}

.topbar-btn.topbar-primary {
    color: #ffffff;
    background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
    border: 1px solid #0d47a1;
}

.topbar-btn.topbar-primary:hover {
    filter: brightness(0.96);
}

.topbar-icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid #dbe6f2;
    background: #ffffff;
    color: #475569;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.topbar-icon-btn:hover {
    background: #f8fafc;
}

.topbar-user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    background: #f8fbff;
    border: 1px solid #dbe6f2;
    border-radius: 999px;
    padding: 0.25rem 0.55rem 0.25rem 0.25rem;
    font-size: 0.82rem;
    color: #334155;
    font-weight: 600;
    max-width: 260px;
}

.topbar-user-pill img {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: contain;
    background: #ffffff;
    padding: 2px;
    display: block;
    flex-shrink: 0;
}

.topbar-user-pill span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-btn.topbar-logout {
    color: #ffffff;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 1px solid #dc2626;
    padding-top: 0;
    padding-bottom: 0;
}

.topbar-btn.topbar-logout:hover {
    filter: brightness(0.95);
}

@media (max-width: 900px) {
    .global-topbar {
        padding: 0 0.85rem;
        height: auto;
        min-height: var(--topbar-height);
    }

    .topbar-search {
        max-width: 45%;
        min-width: 170px;
    }

    .app-main {
        padding-top: calc(1rem + var(--topbar-height));
    }

    .topbar-btn {
        font-size: 0.78rem;
        padding: 0.45rem 0.75rem;
    }

    .global-topbar-actions {
        margin-right: 0;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .topbar-user-pill {
        max-width: 150px;
    }
}

@media (max-width: 991.98px) {
    .sidebar-mobile-toggle {
        display: inline-flex;
    }

    .app-sidebar {
        transform: translateX(-105%);
        z-index: 92;
    }

    body.mobile-nav-open .app-sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    body.mobile-nav-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .global-topbar {
        left: 0;
        padding-left: 58px;
        min-height: 56px;
    }

    .app-main {
        margin-left: 0;
        padding: calc(1rem + var(--topbar-height)) 1rem 1.5rem;
    }

    .topbar-search {
        min-width: 130px;
        max-width: 100%;
    }

    .global-topbar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 575.98px) {
    .topbar-search,
    .topbar-user-pill {
        display: none;
    }

    .global-topbar {
        padding-right: 0.6rem;
    }

    .global-topbar-actions {
        gap: 0.4rem;
    }

    .topbar-btn {
        min-height: 34px;
        padding: 0.35rem 0.6rem;
        font-size: 0.72rem;
    }
}

@media print {
    .global-topbar {
        display: none !important;
    }

    .app-main {
        padding-top: 0 !important;
    }
}

/* Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title h2 {
    font-size: 2rem;
    color: var(--color-primary-dark);
    letter-spacing: -0.5px;
}

.page-subtitle {
    color: var(--color-text-muted);
    font-size: 1.1rem;
}

/* Search Bar */
.search-container {
    background: white;
    border-radius: var(--radius-full);
    padding: 0.75rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    width: 300px;
    border: 1px solid var(--border-color);
}

.search-container input {
    border: none;
    outline: none;
    margin: 0;
    padding: 0;
    width: 100%;
    font-size: 0.95rem;
}

/* Metrics - Compact Rectangular Badges */
.metrics-grid {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.metric-card-circular {
    background: white;
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.metric-circle {
    font-weight: 700;
    color: var(--color-primary);
    border: none;
    width: auto;
    height: auto;
    border-radius: 0;
    display: inline;
    background: none;
}

.metric-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

/* Cards & Tables */
.card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    text-align: left;
    padding: 1.5rem 1rem;
    color: var(--color-primary-dark);
    font-weight: 600;
    border-bottom: 2px solid var(--color-bg);
}

td {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--color-bg);
    color: var(--color-text-main);
}

tr:hover td {
    background: #f1f5f9;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn.primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.btn.primary:hover {
    box-shadow: 0 6px 16px rgba(6, 182, 212, 0.4);
    transform: translateY(-2px);
}

.btn.secondary {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--color-text-muted);
}

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

/* FAB */
.fab-container {
    position: fixed;
    bottom: 3rem;
    right: 3rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
    z-index: 1000;
}

.fab-options {
    display: none;
    flex-direction: column;
    gap: 0.8rem;
    align-items: flex-end;
}

.fab-options.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.fab-option-btn {
    background: white;
    color: var(--color-text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
}

.fab-option-btn:hover {
    transform: translateX(-5px);
    color: var(--color-primary);
}

.fab-container .fab {
    width: 64px;
    height: 64px;
    background: var(--color-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.fab-container .fab:hover {
    transform: scale(1.1) rotate(90deg);
}

/* Forms */
label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

input:not([type="checkbox"]),
select,
textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #f8fafc;
    transition: var(--transition);
    margin-bottom: 1.25rem;
    font-size: 1rem;
}

input:focus,
select:focus,
textarea:focus {
    background: white;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.1);
    outline: none;
}

/* Auth / Landing Layout Overrides */
body.auth-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
}

.auth-container {
    width: 100%;
    max-width: 450px;
    background: white;
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    margin: 2rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
