@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #0f172a;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #6366f1;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 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);
    --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.2);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    display: flex;
    min-height: 100vh;
}

/* App Wrapper Layout */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    height: 100vh;
    z-index: 100;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 1.2rem;
    box-shadow: var(--shadow-glow);
}

.brand-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.role-badge {
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    font-weight: 600;
    color: #a5b4fc;
}

.sidebar-nav {
    padding: 20px 12px;
    flex: 1;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    padding: 12px 12px 6px 12px;
}

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

.nav-link:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
    color: white;
    background-color: var(--sidebar-active);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

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

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-mini {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.user-mini-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
}

.user-role {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Main Content Area */
.app-main {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 70px;
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar-title h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
}

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

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background-color: #f1f5f9;
    color: #475569;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-logout:hover {
    background-color: #fee2e2;
    color: #ef4444;
}

/* Content Container */
.content-wrapper {
    padding: 30px;
    flex: 1;
}

/* Alert Notifications */
.alert-banner {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* Grid & Cards */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Stat Cards */
.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: white;
}

.stat-icon.primary { background: linear-gradient(135deg, #4f46e5, #6366f1); }
.stat-icon.success { background: linear-gradient(135deg, #10b981, #059669); }
.stat-icon.warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.info { background: linear-gradient(135deg, #06b6d4, #0891b2); }

.stat-info h4 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-pending { background-color: #fef3c7; color: #92400e; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-info { background-color: #e0f2fe; color: #075985; }

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

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

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

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

/* Digital Clock Widget */
.clock-widget-container {
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    color: white;
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.clock-display {
    display: flex;
    flex-direction: column;
}

.time-text {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    color: #a5b4fc;
}

.date-text {
    font-size: 0.85rem;
    color: #cbd5e1;
}

/* Org Chart Hierarchy Tree */
.org-chart-wrapper {
    overflow-x: auto;
    padding: 20px 0;
}

.org-tree {
    display: flex;
    justify-content: center;
}

.org-tree ul {
    padding-top: 20px;
    position: relative;
    display: flex;
    justify-content: center;

    transition: all 0.5s;
}

.org-tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 10px 0 10px;
    transition: all 0.5s;
}

.org-card {
    border: 1px solid #e2e8f0;
    padding: 16px;
    display: inline-block;
    border-radius: var(--radius-md);
    background-color: white;
    box-shadow: var(--shadow-sm);
    min-width: 200px;
    text-align: center;
}

.org-card img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-bottom: 8px;
}

.org-card .title {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 600;
}

/* Login Page Styling */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a, #1e1b4b);
    width: 100%;
}

.login-card {
    width: 100%;
    max-width: 440px;
    background-color: #ffffff;
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Sidebar Fold / Collapsible Animation & Responsive Layout */
.app-sidebar {
    width: 260px;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-main {
    margin-left: 260px;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo-full {
    display: block;
    height: 38px;
    width: auto;
    max-width: 165px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
    transition: opacity 0.2s ease;
}

.logo-min {
    display: none;
    height: 36px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
    transition: opacity 0.2s ease;
}

/* Folded State Rules */
body.sidebar-folded .app-sidebar,
html.sidebar-folded .app-sidebar {
    width: 76px !important;
}

body.sidebar-folded .app-main,
html.sidebar-folded .app-main {
    margin-left: 76px !important;
}

body.sidebar-folded .logo-full,
html.sidebar-folded .logo-full {
    display: none !important;
}

body.sidebar-folded .logo-min,
html.sidebar-folded .logo-min {
    display: block !important;
}

body.sidebar-folded .nav-text,
html.sidebar-folded .nav-text,
body.sidebar-folded .nav-section-title,
html.sidebar-folded .nav-section-title,
body.sidebar-folded .user-mini-info,
html.sidebar-folded .user-mini-info,
body.sidebar-folded .role-badge,
html.sidebar-folded .role-badge,
body.sidebar-folded .role-badge-wrapper,
html.sidebar-folded .role-badge-wrapper {
    display: none !important;
}

body.sidebar-folded .nav-link,
html.sidebar-folded .nav-link {
    justify-content: center !important;
    padding: 14px 0 !important;
    margin-bottom: 6px !important;
    text-align: center !important;
}

body.sidebar-folded .nav-link i,
html.sidebar-folded .nav-link i {
    margin: 0 !important;
    font-size: 1.45rem !important;
    width: auto !important;
}

body.sidebar-folded .sidebar-header,
html.sidebar-folded .sidebar-header {
    padding: 0.85rem 0.5rem !important;
    align-items: center !important;
    justify-content: center !important;
}

body.sidebar-folded .sidebar-footer,
html.sidebar-folded .sidebar-footer {
    padding: 12px 4px !important;
    justify-content: center !important;
}

/* Separator Line Image Toggle Button */
.sidebar-edge-toggle {
    position: absolute;
    top: 10px;
    right: -37px; /* Centered right on the separator line separating Left Navigation with the page */
    z-index: 120;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.sidebar-edge-toggle img {
    width: 75px;
    height: 75px;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
    transition: transform 0.2s ease, filter 0.2s ease;
    border-radius: 50%;
    pointer-events: none;
}

.sidebar-edge-toggle:hover img {
    transform: scale(1.18);
    filter: drop-shadow(0 4px 10px rgba(79, 70, 229, 0.5));
}

.toggle-img-unfolded {
    display: block;
}

.toggle-img-folded {
    display: none;
}

body.sidebar-folded .toggle-img-unfolded,
html.sidebar-folded .toggle-img-unfolded {
    display: none !important;
}

body.sidebar-folded .toggle-img-folded,
html.sidebar-folded .toggle-img-folded {
    display: block !important;
}

/* Universal Table Pagination Container & Control Buttons */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #e2e8f0);
}

.pg-info {
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
}

.pg-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pg-btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 34px;
    text-align: center;
}

.pg-btn:hover:not(.disabled):not(.active) {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
}

.pg-btn.active {
    background: var(--primary, #4f46e5);
    border-color: var(--primary, #4f46e5);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.pg-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Card Text Metric Contrast Rules */
.metric-row-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.metric-row-label {
    font-size: 0.88rem;
    color: var(--text-muted, #64748b);
    font-weight: 500;
}

.metric-row-value {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main, #0f172a);
}

/* Alert Dismiss Close Button Styling */
.alert-dismiss-btn {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 0 4px;
    margin-left: 12px;
}

.alert-dismiss-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* ==========================================================================
   Cross-Platform Mobile, Tablet & Touch Responsiveness Framework
   ========================================================================== */

:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --min-touch-target: 44px;
}

button, 
.btn, 
.nav-link, 
.pg-btn, 
.alert-dismiss-btn, 
input[type="button"], 
input[type="submit"], 
select, 
.table-action-btn {
    min-height: var(--min-touch-target);
    touch-action: manipulation;
}

.mobile-top-bar {
    display: none;
    height: 60px;
    background: #0f172a;
    color: #ffffff;
    padding: 0 16px;
    padding-top: var(--safe-area-top);
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.mobile-hamburger-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 1.35rem;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1030;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.25);
}

.mobile-bottom-nav .mob-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.7rem;
    gap: 2px;
    flex: 1;
    height: 100%;
    transition: color 0.2s ease;
}

.mobile-bottom-nav .mob-nav-item i {
    font-size: 1.1rem;
}

.mobile-bottom-nav .mob-nav-item.active {
    color: #38bdf8;
    font-weight: 700;
}

/* Responsive Table Card Conversion Layout */
@media (max-width: 767px) {
    .table-responsive-cards thead {
        display: none;
    }

    .table-responsive-cards, 
    .table-responsive-cards tbody, 
    .table-responsive-cards tr, 
    .table-responsive-cards td {
        display: block;
        width: 100%;
    }

    .table-responsive-cards tr {
        background: var(--card-bg, #ffffff);
        border: 1px solid var(--border-color, #e2e8f0);
        border-radius: 10px;
        margin-bottom: 14px;
        padding: 12px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    }

    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 4px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        font-size: 0.88rem;
    }

    .table-responsive-cards td:last-child {
        border-bottom: none;
    }

    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted, #64748b);
        font-size: 0.8rem;
        text-transform: uppercase;
        margin-right: 12px;
    }
}

/* Tablet Adaptive Layout (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .app-sidebar {
        width: 240px;
    }
    
    .app-main {
        margin-left: 240px;
    }

    .dashboard-grid, .grid-2col {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Mobile Layout (< 767px) */
@media (max-width: 767px) {
    .mobile-top-bar {
        display: flex;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -280px;
        width: 280px;
        z-index: 1050;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .app-sidebar.drawer-open {
        left: 0 !important;
    }

    .app-main {
        margin-left: 0 !important;
        padding-top: calc(60px + var(--safe-area-top)) !important;
        padding-bottom: calc(70px + var(--safe-area-bottom)) !important;
    }

    .topbar {
        display: none !important;
    }

    .sidebar-edge-toggle {
        display: none !important;
    }

    .content-wrapper {
        padding: 14px 12px !important;
    }

    .dashboard-grid, .grid-2col, .grid-3col, .grid-4col {
        grid-template-columns: 1fr !important;
    }
}