:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-body: #f3f4f6;
    --bg-surface: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --info: #3b82f6;
}

html {
    scroll-behavior: smooth;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


.sidebar nav {
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.42) rgba(255, 255, 255, 0.08);
    -ms-overflow-style: auto;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding-right: 0.375rem;
    scrollbar-gutter: stable;
}

.sidebar nav::-webkit-scrollbar {
    width: 7px;
}

.sidebar nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
}

.sidebar nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.42);
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.sidebar nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.6);
}


body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    line-height: 1.5;
}

* {
    box-sizing: border-box;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary);
    color: white;
    border-radius: 0.5rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background-color: var(--primary-hover);
    color: white;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--border);
    color: var(--text-main);
}

.btn-block {
    display: block;
    width: 100%;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.btn-solid-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary);
    color: white;
    border-radius: 0.5rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-solid-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background-color: transparent;
    color: var(--text-muted);
    border-radius: 0.5rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ghost:hover {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.btn-ghost-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    border-radius: 0.5rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ghost-primary:hover {
    background-color: rgba(99, 102, 241, 0.2);
    transform: translateY(-1px);
}

.input-group {
    margin-bottom: 1.25rem;
}

.label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.input {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
}

.input:focus {
    border-color: var(--primary);
}

/* Layouts */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.auth-card {
    background-color: var(--bg-surface);
    padding: 2.5rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

.app-layout {
    --sidebar-width: 280px;
    --header-height: 70px;
    display: flex;
    min-height: 100vh;
}

/* Sidebar & Navigation */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0.75rem; /* Restored horizontal padding for alignment */
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    overflow: hidden; /* Prevent sidebar from scrolling, only internal nav scrolls */
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: width, padding;
}

.content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: margin-left;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem; /* Increased base padding for better collapse transition */
    margin-bottom: 0.25rem;
    border-radius: 0.5rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    text-decoration: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-link.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

/* Sidebar Footer & User Info */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 1.25rem 0.75rem;
    background: var(--bg-surface);
    z-index: 51;
    margin-top: auto; /* Push to bottom of sidebar flex container */
}

.sidebar-user-info {
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.sidebar-user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .sidebar-footer {
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); /* Safe Area for iPhone etc */
    }
}

.card {
    background-color: var(--bg-surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-muted);
}

.quick-action-card:hover {
    color: var(--primary);
}

.quick-action-icon {
    font-size: 1.5rem;
}

.activity-row {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.activity-row:last-child {
    border-bottom: none;
}

.activity-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.activity-badge {
    font-size: 1.25rem;
}

.activity-name {
    font-weight: 600;
    margin-right: 0.5rem;
}

.activity-type {
    color: var(--text-muted);
}

.activity-time {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.status-indicator {
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-weight: 500;
    font-size: 0.875rem;
}

.status-indicator.in {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.status-indicator.out {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.status-indicator.break {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--border);
}

.btn-success {
    background-color: var(--success);
}

.btn-success:hover {
    background-color: #059669;
    color: white;
}

.btn-danger {
    background-color: var(--danger);
}

.btn-danger:hover {
    background-color: #dc2626;
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 1.25rem 1rem !important;
    text-align: left;
    vertical-align: middle !important;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
}

.table th {
    vertical-align: middle !important;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    text-transform: uppercase;
}

.table tbody tr:hover {
    background-color: rgba(99, 102, 241, 0.05);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.badge-info {
    background: rgba(99, 102, 241, 0.2);
    color: #6366f1;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-surface);
    border-radius: 1rem;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.5rem;
}


/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Response Table Wrapper */
.table-responsive {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Desktop Mini Sidebar Styles */
@media (min-width: 769px) {
    .app-layout {
        /* Unifying transition source */
    }

    .sidebar {
        transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Collapsed State */
    .app-layout.collapsed {
        --sidebar-width: 80px; 
    }

    .app-layout.collapsed .sidebar {
        width: var(--sidebar-width);
        padding-left: 0;
        padding-right: 0;
    }

    .app-layout.collapsed .content {
        margin-left: var(--sidebar-width);
    }

    /* Hide all spans in sidebar when collapsed (logo text, link labels, user info) */
    .app-layout.collapsed .sidebar span,
    .app-layout.collapsed .sidebar-profile-arrow,
    .app-layout.collapsed .sidebar-user-details {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        max-width: 0 !important;
        overflow: hidden !important;
        white-space: nowrap !important;
        margin-left: 0 !important;
    }

    .app-layout.collapsed .sidebar-user-info {
        padding: 0;
        display: flex;
        justify-content: center;
    }

    .app-layout.collapsed .sidebar-profile-link {
        padding: 0.5rem 0 !important;
        justify-content: center;
        width: 100%;
    }
    
    .sidebar span,
    .sidebar-user-info {
        transition: opacity 0.3s ease, visibility 0.3s ease, max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1), margin 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        opacity: 1;
        visibility: visible;
        display: inline-block;
        max-width: 200px;
    }

    .app-layout.collapsed .sidebar-link {
        gap: 0;
        padding-left: 1.5rem; /* Adjusted for centering icons in 80px width */
    }

    .sidebar-link {
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Mobile Menu Button is Hidden on Desktop */
    .mobile-menu-btn {
        display: none !important;
    }

    /* Center icons strictly in collapsed state */
    .app-layout.collapsed .sidebar-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    /* Center Logo container perfectly (clearing all padding) */
    /* Improved Header Centering without Jumps */
    .app-layout.collapsed .sidebar > div:first-child {
        padding-left: 1.5rem !important; /* Matches sidebar-link for stability */
    }

    .app-layout.collapsed .sidebar > div:first-child div {
        gap: 0 !important;
    }
    
    /* Center Footer strictly in collapsed state */
    .app-layout.collapsed .sidebar-footer {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 1rem 0 !important;
    }

    /* Reset Nav Margin Hack in Collapsed State to fix alignment */
    .app-layout.collapsed .sidebar nav {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .app-layout {
        --sidebar-width: 0px; /* Reset for content margin */
    }

    .mobile-menu-btn {
        left: 1rem; /* Reset to left edge on mobile */
    }

    .mobile-menu-btn {
        display: flex;
    }

    /* Sidebar - Slide In */
    .sidebar {
        display: flex; /* Restore flex */
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        width: 280px;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
        padding: 4rem 1rem 1rem 1rem; /* Top padding for menu btn */
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
        padding: 4rem 1rem 1rem 1rem; /* Top padding for menu btn */
    }

    .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* Sidebar Close Button */
.sidebar-close-btn {
    display: none; /* Hidden on Desktop */
}

@media (max-width: 768px) {
    .sidebar-close-btn {
        display: flex; /* Visible on Mobile */
        padding: 0.5rem;
    }
}

/* Sidebar Sticky Toggle Tab (Unified for Desktop & Mobile) */
#sidebar-toggle-btn {
    position: fixed;
    left: var(--sidebar-width);
    top: 24px;
    width: 32px;
    height: 48px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: none; 
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 45;
    margin-left: -4px; /* Default tucked under */
    box-shadow: 4px 0 6px rgba(0,0,0,0.05);
    color: var(--text-muted);
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s, color 0.2s, width 0.2s, margin-left 0.4s;
}

#sidebar-toggle-btn:hover {
    background: #f9fafb;
    color: var(--primary);
    width: 36px;
}

#sidebar-toggle-btn svg {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
    transform: rotate(0deg); /* Points Left < when sidebar is open */
}

/* Base Arrow Logic: 
   Sidebar open (default) -> Arrow points left < (rotate 0deg) 
   Sidebar collapsed -> Arrow points right > (rotate 180deg)
*/
.app-layout.collapsed #sidebar-toggle-btn {
    left: var(--sidebar-width);
    margin-left: 4px; /* Stick out significantly when collapsed */
}

.app-layout.collapsed #sidebar-toggle-btn svg {
    transform: rotate(180deg);
}

/* Mobile Unified Logic */
@media (max-width: 768px) {
    #sidebar-toggle-btn {
        left: 0 !important;
        top: 24px !important;
        margin-left: 4px !important; /* Stick out significantly when closed on mobile */
    }
    
    .sidebar.open + #sidebar-toggle-btn {
        left: 280px !important;
        margin-left: -4px !important; /* Tucked under when open on mobile */
    }
    
    #sidebar-toggle-btn svg {
        transform: rotate(180deg) !important; /* Points Right > initially to indicate "click to open" */
    }
    
    .sidebar.open + #sidebar-toggle-btn svg {
        transform: rotate(0deg) !important; /* Points Left < when open */
    }
}


/* Icon Utilities */
.icon {
    width: 24px;
    height: 24px;
    vertical-align: middle;
    stroke-width: 2;
    display: inline-block;
}

.icon-sm {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

.icon-lg {
    width: 32px;
    height: 32px;
    stroke-width: 1.5;
}

/* AI Assistant Floating Widget */
#ai-assistant-float {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    z-index: 1000;
    transition: transform 0.2s;
}

#ai-assistant-float:hover {
    transform: scale(1.1);
}

.ai-float-btn {
    width: 100%;
    height: 100%;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-window {
    position: fixed;
    bottom: 7rem;
    right: 2rem;
    width: 350px;
    height: 500px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-header {
    padding: 1rem;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-header h3 {
    margin: 0;
    font-size: 1rem;
}

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.ai-messages {
    flex: 1;
    padding: 0 1rem 1rem 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-message {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    max-width: 80%;
    font-size: 0.875rem;
}

.ai-message.system {
    background: var(--bg-body);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 0.25rem;
}

.ai-message.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0.25rem;
}

.ai-input-area {
    padding: 0 1rem 1rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

.ai-input-area input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    outline: none;
}

.btn-send {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1.25rem;
    cursor: pointer;
}

/* Animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Button disabled state */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn:disabled:hover {
    transform: none;
}
