/* ================================================================
   g!Tracker — Master Stylesheet
   Professional dark-blue/navy theme · Bootstrap 5.3 overrides
   Responsive: mobile (<768) · tablet (768-1024) · desktop (>1024)
   ================================================================ */

/* ----------------------------------------------------------------
   1. CSS Custom Properties
   ---------------------------------------------------------------- */
:root {
    /* Brand */
    --gt-primary:       #1e3a5f;
    --gt-primary-light: #2c5282;
    --gt-primary-dark:  #0f2942;
    --gt-accent:        #3b82f6;
    --gt-accent-hover:  #2563eb;

    /* Surfaces */
    --gt-body-bg:       #f1f5f9;
    --gt-card-bg:       #ffffff;
    --gt-border:        #e2e8f0;

    /* Text */
    --gt-text-primary:  #0f172a;
    --gt-text-secondary:#475569;
    --gt-text-muted:    #94a3b8;

    /* Sidebar */
    --sidebar-width:           260px;
    --sidebar-collapsed-width: 60px;
    --sidebar-bg:              #0f172a;
    --sidebar-hover:           #1e293b;
    --sidebar-active:          #3b82f6;

    /* Layout */
    --navbar-height: 60px;
}

/* ----------------------------------------------------------------
   2. Base & Typography
   ---------------------------------------------------------------- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--gt-body-bg);
    margin: 0;
    overflow-x: hidden;
}

/* ----------------------------------------------------------------
   3. Layout — Sidebar
   ---------------------------------------------------------------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1040;
    transition: width 0.25s ease, transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-brand {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-brand h2 {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    transition: font-size 0.25s ease;
}
.sidebar-brand h2 i {
    color: var(--gt-accent);
    margin-right: 0.5rem;
}
.sidebar-menu {
    padding: 1rem 0;
}
.sidebar-menu .menu-header {
    color: rgba(255,255,255,0.35);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0.75rem 1.25rem 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.25s ease;
}
.sidebar-menu .nav-link {
    color: rgba(255,255,255,0.7);
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.9rem;
    white-space: nowrap;
    min-height: 44px;
}
.sidebar-menu .nav-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
}
.sidebar-menu .nav-link.active {
    color: #fff;
    background: var(--sidebar-hover);
    border-left-color: var(--sidebar-active);
}
.sidebar-menu .nav-link i {
    width: 24px;
    min-width: 24px;
    margin-right: 0.75rem;
    text-align: center;
    font-size: 1rem;
}
.sidebar-menu .nav-link span {
    transition: opacity 0.2s ease;
}

/* ----------------------------------------------------------------
   4. Layout — Top Navbar
   ---------------------------------------------------------------- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}
.top-navbar {
    height: var(--navbar-height);
    background: #fff;
    border-bottom: 1px solid var(--gt-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.top-navbar .navbar-left {
    display: flex;
    align-items: center;
}
.top-navbar .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gt-text-primary);
    margin: 0;
}
.top-navbar .user-menu .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gt-text-secondary);
    text-decoration: none;
    font-weight: 500;
}
.top-navbar .user-menu .dropdown-toggle::after {
    display: none;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gt-primary) 0%, var(--gt-primary-light) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

/* ----------------------------------------------------------------
   5. Layout — Content Area
   ---------------------------------------------------------------- */
.content-area {
    padding: 1.5rem;
}
.content-header {
    margin-bottom: 1.5rem;
}
.content-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gt-text-primary);
    margin: 0;
}
.content-header .breadcrumb {
    margin: 0;
    font-size: 0.85rem;
}

/* ----------------------------------------------------------------
   6. Components — Cards
   ---------------------------------------------------------------- */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.card-header {
    background: var(--gt-card-bg);
    border-bottom: 1px solid #f1f5f9;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Stat cards (dashboard) */
.stat-card {
    border-radius: 12px;
    padding: 1.5rem;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.stat-card .stat-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    opacity: 0.2;
}
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 0.25rem;
}

/* Gradient helpers */
.bg-gradient-primary { background: linear-gradient(135deg, var(--gt-primary) 0%, var(--gt-primary-light) 100%); }
.bg-gradient-success { background: linear-gradient(135deg, #059669 0%, #34d399 100%); }
.bg-gradient-info    { background: linear-gradient(135deg, #0891b2 0%, #67e8f9 100%); }
.bg-gradient-warning { background: linear-gradient(135deg, #d97706 0%, #fbbf24 100%); }
.bg-gradient-danger  { background: linear-gradient(135deg, #dc2626 0%, #f87171 100%); }

/* ----------------------------------------------------------------
   7. Components — Tables
   ---------------------------------------------------------------- */
.table th {
    font-weight: 600;
    color: var(--gt-text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom-width: 2px;
}

/* ----------------------------------------------------------------
   8. Components — Buttons
   ---------------------------------------------------------------- */
.btn-primary {
    background: linear-gradient(135deg, var(--gt-primary-light) 0%, var(--gt-primary) 100%);
    border: none;
}
.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, var(--gt-accent-hover) 0%, var(--gt-primary-dark) 100%);
    box-shadow: 0 4px 12px rgba(30,58,95,0.35);
}
.btn-primary:active {
    background: linear-gradient(135deg, var(--gt-primary-dark) 0%, var(--gt-primary) 100%);
}

/* ----------------------------------------------------------------
   9. Components — Badges
   ---------------------------------------------------------------- */
.badge-role-superadmin { background: #dc3545; }
.badge-role-admin      { background: #e67e22; }
.badge-role-company    { background: #0d6efd; }
.badge-role-user       { background: #6c757d; }

/* ----------------------------------------------------------------
   10. Components — Forms
   ---------------------------------------------------------------- */
.form-control:focus,
.form-select:focus {
    border-color: var(--gt-accent);
    box-shadow: 0 0 0 0.2rem rgba(59,130,246,0.25);
}

/* ----------------------------------------------------------------
   11. Components — Tracking Report
   ---------------------------------------------------------------- */
/* Report table wrapper — no overflow here so position:sticky works on page scroll */
.rpt-wrap { }

/* Summary tables */
.rpt { font-size: 0.74rem; border-collapse: collapse; width: 100%; }
.rpt th, .rpt td { padding: 4px 6px; white-space: nowrap; vertical-align: middle; }
.rpt th { font-size: 0.7rem; }

/* Sticky header rows — quarter (hq) and month (hm) stick below the navbar on scroll */
.rpt .hq th {
    background: var(--gt-primary-dark); color: #fff; font-weight: 700;
    position: sticky; top: var(--navbar-height); z-index: 10;
}
.rpt .hm th {
    background: var(--gt-primary); color: #fff; font-weight: 600;
    position: sticky; top: calc(var(--navbar-height) + 28px); z-index: 9;
}

.rpt .r-open  td { background: #f3e5f5; }
.rpt .r-alloc td { background: #e8eaf6; }
.rpt .r-used  td { background: #fff3e0; }
.rpt .r-close td { background: #e0f2f1; font-weight: 700; }
.rpt .r-billed td { background: #fff8e1; font-weight: 700; }
.rpt .r-sep   td { background: #fff; padding: 2px 0; border-left: 0; border-right: 0; }

.rpt .cat-hd td { padding: 7px 6px !important; font-weight: 700; border-top: 2px solid #dee2e6; }
.rpt .proj-hd td { background: #37474f; color: #fff; font-weight: 600; font-size: 0.76rem; padding: 6px 6px !important; }
.rpt .proj-cost td { background: #fafafa; }
.rpt .cat-sub td { padding: 6px 6px !important; }
.rpt .grand td { background: var(--gt-primary-dark); color: #fff; font-weight: 700; font-size: 0.88rem; padding: 8px 6px !important; border-top: 3px solid #fbbf24; }
.rpt .grand td.tc { background: var(--gt-primary-dark) !important; color: #fff; }
.rpt .grand td .grand-amt { color: #fbbf24; font-size: 0.82rem; }

.vp { color: #059669; font-weight: 600; }
.vn { color: #dc2626; font-weight: 600; }
.vz { color: #ccc; }
.tc { background: rgba(0,0,0,0.03) !important; }

/* Task breakdown tab */
.tb-card { border: 1px solid #dee2e6; border-radius: 0.375rem; overflow: hidden; margin-bottom: 1rem; }
.tb-card-hd { background: #263238; color: #fff; padding: 8px 12px; font-weight: 600; font-size: 0.8rem; }
.tb-proj-hd { background: #37474f; color: #fff; }
.tb-proj-hd td { font-weight: 600; font-size: 0.78rem; padding: 6px 10px !important; }
.tb-sub td { background: #eceff1; font-weight: 700; font-size: 0.76rem; }
.tb-grand td { background: #263238; color: #fff; font-weight: 700; font-size: 0.8rem; }
.task-desc { max-width: 320px; white-space: normal; word-break: break-word; }
.task-name-badge { background: #dbeafe; color: #1d4ed8; font-size: 0.65rem; padding: 2px 6px; border-radius: 3px; font-weight: 600; }

/* Report tabs */
.report-tabs .nav-link { font-size: 0.85rem; font-weight: 600; color: #546e7a; }
.report-tabs .nav-link.active { color: var(--gt-primary); border-bottom: 2px solid var(--gt-primary); }
.report-tabs .nav-link i { margin-right: 5px; }

/* ----------------------------------------------------------------
   12. Components — AI Chat Widget
   ---------------------------------------------------------------- */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1050;
}
.ai-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gt-primary-light) 0%, var(--gt-primary) 100%);
    border: none;
    color: #fff;
    font-size: 1.4rem;
    box-shadow: 0 4px 15px rgba(30,58,95,0.4);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(30,58,95,0.5);
}
.ai-chat-panel {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    overflow: hidden;
    flex-direction: column;
}
.ai-chat-header {
    background: linear-gradient(135deg, var(--gt-primary-light) 0%, var(--gt-primary) 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ai-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-header-title span {
    font-weight: 600;
    font-size: 0.95rem;
}
.ai-chat-header-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 0.8rem;
}
.ai-chat-header-btn:hover {
    color: #fff;
}
.ai-chat-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
}
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-height: 300px;
    max-height: 360px;
    background: #f8f9fa;
}
.ai-chat-input-area {
    padding: 12px;
    border-top: 1px solid #e9ecef;
    background: #fff;
}
.ai-chat-form {
    display: flex;
    gap: 8px;
}
.ai-chat-input {
    border-radius: 20px !important;
    padding: 8px 16px !important;
    font-size: 0.85rem !important;
}
.ai-chat-send-btn {
    border-radius: 50%;
    width: 36px;
    height: 36px;
    padding: 0;
    background: linear-gradient(135deg, var(--gt-primary-light) 0%, var(--gt-primary) 100%);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ai-chat-send-btn:hover {
    background: linear-gradient(135deg, var(--gt-accent-hover) 0%, var(--gt-primary-dark) 100%);
}
.ai-chat-send-btn i {
    font-size: 0.8rem;
}

/* Chat bubbles */
.ai-bubble-wrap {
    margin-bottom: 12px;
    display: flex;
}
.ai-bubble-wrap.user {
    justify-content: flex-end;
}
.ai-bubble-wrap.assistant {
    justify-content: flex-start;
}
.ai-bubble {
    padding: 10px 14px;
    font-size: 0.85rem;
    max-width: 85%;
    word-break: break-word;
}
.ai-bubble.user {
    background: linear-gradient(135deg, var(--gt-primary-light) 0%, var(--gt-primary) 100%);
    color: #fff;
    border-radius: 12px 12px 2px 12px;
}
.ai-bubble.assistant {
    background: #fff;
    color: #333;
    border-radius: 12px 12px 12px 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.ai-bubble code {
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.8rem;
}

/* Suggested question buttons */
.ai-suggest-btn {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.75rem;
    color: #495057;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.ai-suggest-btn i {
    color: var(--gt-accent);
    font-size: 0.7rem;
}
.ai-suggest-btn:hover {
    background: #eff6ff !important;
    border-color: var(--gt-accent) !important;
    color: var(--gt-accent) !important;
}

/* ----------------------------------------------------------------
   13. Sidebar Toggle
   ---------------------------------------------------------------- */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--gt-text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    margin-right: 0.75rem;
    min-width: 44px;
    min-height: 44px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* ----------------------------------------------------------------
   14. Responsive — Tablet (768px – 1024px)
   ---------------------------------------------------------------- */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Collapsed sidebar: icons only */
    .sidebar {
        width: var(--sidebar-collapsed-width);
    }
    .sidebar .sidebar-brand {
        justify-content: center;
        padding: 0 0.5rem;
    }
    .sidebar .sidebar-brand h2 {
        font-size: 0;
        overflow: hidden;
    }
    .sidebar .sidebar-brand h2 i {
        font-size: 1.25rem;
        margin-right: 0;
    }
    .sidebar .menu-header {
        opacity: 0;
        height: 0;
        padding: 0;
        overflow: hidden;
    }
    .sidebar .nav-link {
        justify-content: center;
        padding: 0.75rem 0.5rem;
    }
    .sidebar .nav-link i {
        margin-right: 0;
        font-size: 1.1rem;
    }
    .sidebar .nav-link span {
        display: none;
    }

    /* Expand on hover */
    .sidebar:hover {
        width: var(--sidebar-width);
        position: fixed;
        z-index: 1050;
        box-shadow: 4px 0 20px rgba(0,0,0,0.25);
    }
    .sidebar:hover .sidebar-brand {
        justify-content: flex-start;
        padding: 0 1.25rem;
    }
    .sidebar:hover .sidebar-brand h2 {
        font-size: 1.25rem;
    }
    .sidebar:hover .sidebar-brand h2 i {
        margin-right: 0.5rem;
    }
    .sidebar:hover .menu-header {
        opacity: 1;
        height: auto;
        padding: 0.75rem 1.25rem 0.5rem;
    }
    .sidebar:hover .nav-link {
        justify-content: flex-start;
        padding: 0.6rem 1.25rem;
    }
    .sidebar:hover .nav-link i {
        margin-right: 0.75rem;
    }
    .sidebar:hover .nav-link span {
        display: inline;
    }

    /* Content area */
    .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }
    .content-area {
        padding: 1.25rem;
    }

    /* Show toggle on tablet */
    .sidebar-toggle {
        display: block;
    }

    /* Touch-friendly targets */
    .btn-sm {
        min-height: 38px;
        padding: 0.4rem 0.75rem;
    }
    .nav-link {
        min-height: 44px;
    }
    .dropdown-item {
        padding: 0.5rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* AI chat panel – narrower on tablet */
    .ai-chat-panel {
        width: 340px;
    }
}

/* ----------------------------------------------------------------
   15. Responsive — Mobile (< 768px)
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .sidebar-toggle {
        display: block;
    }
    .sidebar-overlay.show {
        display: block;
    }
    .content-area {
        padding: 1rem;
    }

    /* Touch targets */
    .btn-sm {
        min-height: 38px;
        padding: 0.4rem 0.75rem;
    }
    .nav-link {
        min-height: 44px;
    }

    /* AI chat panel – full width minus margins */
    .ai-chat-widget {
        bottom: 16px;
        right: 16px;
    }
    .ai-chat-panel {
        width: calc(100vw - 32px);
        right: -8px;
        max-height: 70vh;
    }
    .ai-chat-messages {
        max-height: 50vh;
    }

    /* Stat cards */
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    .stat-card {
        padding: 1.25rem;
    }
}

/* ----------------------------------------------------------------
   16. Print Styles
   ---------------------------------------------------------------- */
@media print {
    .no-print { display: none !important; }
    .sidebar, .top-navbar, .main-header, nav, .main-footer, .ai-chat-widget { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-wrapper { margin-left: 0 !important; padding: 0 !important; }
    body { font-size: 8pt; background: #fff; }
    .rpt { font-size: 7pt; }
    .rpt th, .rpt td { padding: 2px 3px; }
    .card { border: none !important; box-shadow: none !important; }
    .tab-pane { display: block !important; opacity: 1 !important; }
    .tab-pane:not(.active) { page-break-before: always; }
}

/* ----------------------------------------------------------------
   17. Login / Auth Layout
   ---------------------------------------------------------------- */
body.login-page {
    background: linear-gradient(135deg, var(--gt-primary) 0%, var(--gt-primary-dark) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.login-box {
    width: 400px;
    max-width: 95%;
}
.login-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
}
.login-card .card-body {
    padding: 2.5rem;
}
.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-logo h1 {
    color: #fff;
    font-weight: 700;
    font-size: 2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.login-logo p {
    color: rgba(255,255,255,0.8);
    margin: 0;
}
body.login-page .btn-primary {
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
}
body.login-page .btn-primary:hover {
    box-shadow: 0 4px 12px rgba(30,58,95,0.4);
}
body.login-page .form-control {
    border-radius: 8px;
    padding: 0.6rem 1rem;
    border: 1px solid #e0e0e0;
}
