:root {
    --ib-bg: #f1f5f9;
    --ib-surface: #ffffff;
    --ib-border: #e5e7eb;
    --ib-text: #111827;
    --ib-muted: #6b7280;
    --ib-primary: #22c55e;
    --ib-primary-hover: #16a34a;
    --ib-danger: #dc2626;
    --ib-radius: 12px;
    --ib-radius-sm: 10px;
    --ib-shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
    --ib-shadow-sm: 0 6px 16px rgba(17, 24, 39, 0.08);
    --ib-sidebar: #ffffff;
    --ib-sidebar-muted: #111827;
    --ib-sidebar-faint: #f3f4f6;
    --ib-sidebar-border: #e5e7eb;
    --ib-sidebar-link-radius: 12px;
    --ib-sidebar-link-py: 0.50rem;
    --ib-sidebar-link-px: 0.75rem;
    --ib-sidebar-icon-size: 24px;
}

body {
    background-color: var(--ib-bg);
    color: var(--ib-text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

a {
    -webkit-tap-highlight-color: transparent;
}

button,
.btn {
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--ib-text);
    letter-spacing: -0.01em;
}

.text-muted {
    color: var(--ib-muted) !important;
}

/* Overlay for mobile */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
}
.overlay.active {
    display: block;
}

/* Sidebar base */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    background-color: var(--ib-sidebar);
    color: var(--ib-text);
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.3s ease, width 0.3s ease;
    border-right: 1px solid var(--ib-sidebar-border);
}

.sidebar.open {
    transform: translateX(0);
    box-shadow: var(--ib-shadow-sm);
}

.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .label {
    display: none;
}

@media (min-width: 768px) {
    .sidebar {
        transform: translateX(0);
    }
    .sidebar.collapsed .sidebar-header {
        padding-left: 10px !important;
        padding-right: 10px !important;
        justify-content: center;
    }

    .sidebar.collapsed .sidebar-logo {
        margin: 0 !important;
    }

    .sidebar.collapsed .sidebar-nav {
        padding: 10px 6px !important;
    }

    .sidebar.collapsed .nav-item.sidebar-link {
        justify-content: center;
        padding: 6px;
        gap: 0;
        border-radius: 10px;
    }

    .sidebar.collapsed .nav-item.sidebar-link .icon {
        margin: 0;
        /* Icons only (no chip box) */
        background: transparent;
        border: 0;
        padding: 0;
        width: 20px;
        height: 20px;
    }

    .sidebar.collapsed .nav-item.sidebar-link.active {
        background-color: var(--ib-primary);
        color: #ffffff;
    }

    .sidebar.collapsed .nav-item.sidebar-link.active::before {
        display: none;
    }
}

.sidebar-header {
    height: 56px;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    background-color: var(--ib-primary);
    border: 1px solid var(--ib-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #ffffff;
}

.sidebar-nav {
    overflow-y: auto;
    padding: 10px 12px;
}

.nav-item.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: var(--ib-sidebar-link-py) var(--ib-sidebar-link-px);
    margin-bottom: 0.20rem;
    border-radius: var(--ib-sidebar-link-radius);
    color: var(--ib-sidebar-muted);
    text-decoration: none;
    font-size: 0.92rem;
    position: relative;
    border: 1px solid transparent;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.sidebar.collapsed .nav-item.sidebar-link::after {
    content: attr(data-title);
    position: fixed;
    left: 88px;
    top: var(--tooltip-y);
    transform: translateY(-50%);
    background: #111827;
    color: #ffffff;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 2000;
}

.sidebar.collapsed .nav-item.sidebar-link:hover::after {
    opacity: 1;
}

.nav-item.sidebar-link:hover,
.nav-item.sidebar-link.active {
    background-color: var(--ib-sidebar-faint);
    color: var(--ib-text);
}

.nav-item.sidebar-link.active {
    background-color: var(--ib-primary);
    border-color: var(--ib-primary);
    color: #ffffff;
    font-weight: 600;
}

.nav-item.sidebar-link .icon {
    flex: 0 0 auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    width: 20px;
    height: 20px;
}

.nav-item.sidebar-link:focus-visible {
    outline: 2px solid rgba(34, 197, 94, 0.55);
    outline-offset: 2px;
}

.nav-item .icon {
    width: 18px;
    height: 18px;
}

.sidebar-footer {
    position: sticky;
    bottom: 0;
    background-color: var(--ib-sidebar);
}

/* Main wrapper margin depending on sidebar */
.main-wrapper {
    margin-left: 0;
    padding-left: 0;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

.ib-container {
    max-width: 1180px;
    margin: 0 auto;
}

.ib-stat-card {
    border: 1px solid var(--ib-border);
    border-radius: var(--ib-radius);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.ib-stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--ib-shadow);
    border-color: rgba(17, 24, 39, 0.10);
}

.ib-icon-chip {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(17, 24, 39, 0.08);
}

.ib-icon-chip .icon {
    width: 20px;
    height: 20px;
}

.ib-icon-chip--admins {
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
}

.ib-icon-chip--clients {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
}

.ib-icon-chip--invoices {
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
}

.ib-icon-chip--revenue {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
}

.ib-icon-chip--month {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

/* Superadmin sidebar icon colors (non-active) */
.sa-nav-dashboard:not(.active) .icon {
    color: #0ea5e9;
}

.sa-nav-admins:not(.active) .icon {
    color: #1d4ed8;
}

.sa-nav-profile:not(.active) .icon {
    color: #8b5cf6;
}

@media (max-width: 575.98px) {
    .ib-container {
        max-width: 100%;
    }
}

@media (min-width: 768px) {
    .main-wrapper {
        margin-left: 240px;
        padding-left: 0 !important;
    }

    .sidebar.collapsed ~ .main-wrapper {
        margin-left: 72px;
        padding-left: 0 !important;
    }
}

/* Desktop collapse toggle button */
.sidebar-toggle {
    position: fixed;
    top: 24px;
    left: 240px;
    transform: translateX(-50%);
    z-index: 1061;
    padding: 6px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ib-border);
    background-color: var(--ib-surface);
}

@media (max-width: 767.98px) {
    .sidebar-toggle {
        display: none;
    }
}

.sidebar.collapsed ~ .sidebar-toggle {
    left: 72px;
    transform: translateX(-50%);
}

/* Alerts auto-dismiss */
.alert-auto-dismiss {
    transition: opacity 0.5s ease;
    border-radius: var(--ib-radius-sm);
    border: 1px solid var(--ib-border);
    box-shadow: var(--ib-shadow-sm);
}

.alert-auto-dismiss.fade-out {
    opacity: 0;
}

.alert-icon {
    width: 18px;
    height: 18px;
    margin-right: 6px;
}

.card {
    border: 1px solid var(--ib-border);
    border-radius: var(--ib-radius);
    box-shadow: var(--ib-shadow-sm);
}

.card .card-header {
    background-color: var(--ib-surface);
    border-bottom: 1px solid var(--ib-border);
}

.table {
    background-color: var(--ib-surface);
}

.table thead th {
    font-weight: 650;
    color: var(--ib-text);
}

.table-bordered > :not(caption) > * {
    border-color: var(--ib-border);
}

.table tbody tr:hover {
    background-color: #f9fafb;
}

#items-table .form-control,
#items-table .form-select {
    padding-top: 0.16rem;
    padding-bottom: 0.16rem;
    padding-left: 0.45rem;
    padding-right: 2rem;
    font-size: 0.82rem;
    min-height: 30px;
}

#items-table th,
#items-table td {
    padding: 0.45rem;
}

#items-table {
    table-layout: fixed;
}

#items-table th:nth-child(2),
#items-table td:nth-child(2) {
    width: 32%;
}

#items-table th:nth-child(3),
#items-table td:nth-child(3) {
    width: 10%;
}

#items-table th:nth-child(1),
#items-table td:nth-child(1),
#items-table th:nth-child(8),
#items-table td:nth-child(8) {
    width: 6%;
}

.btn {
    border-radius: 10px;
    font-weight: 600;
}

.btn:focus,
.btn:active:focus {
    box-shadow: none;
}

.btn:focus-visible {
    box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.18);
}

.btn-secondary {
    background-color: #2563eb;
    border-color: #2563eb;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
}

.btn-eye {
    background: transparent;
    border: 0;
    padding: 0.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ib-muted);
}

.btn-eye .icon {
    width: 18px;
    height: 18px;
}

.password-field {
    position: relative;
}

.password-field .form-control {
    padding-right: 2.25rem;
}

.password-field .btn-eye {
    position: absolute;
    right: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
}

.btn-eye:hover {
    color: var(--ib-text);
}

.stat-icon {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--stat-border, var(--ib-border));
    background: var(--stat-bg, rgba(15, 23, 42, 0.04));
}

.stat-icon .icon {
    width: 18px;
    height: 18px;
    color: var(--stat-color, var(--ib-text));
}

.stat-icon--indigo {
    --stat-color: #4f46e5;
    --stat-border: rgba(79, 70, 229, 0.35);
    --stat-bg: rgba(79, 70, 229, 0.10);
}

.stat-icon--sky {
    --stat-color: #0284c7;
    --stat-border: rgba(2, 132, 199, 0.35);
    --stat-bg: rgba(2, 132, 199, 0.10);
}

.stat-icon--emerald {
    --stat-color: #16a34a;
    --stat-border: rgba(22, 163, 74, 0.35);
    --stat-bg: rgba(22, 163, 74, 0.10);
}

.stat-icon--amber {
    --stat-color: #d97706;
    --stat-border: rgba(217, 119, 6, 0.35);
    --stat-bg: rgba(217, 119, 6, 0.10);
}

.btn-primary {
    background-color: var(--ib-primary);
    border-color: var(--ib-primary);
}

.btn-primary:focus,
.btn-primary:active,
.btn-primary:active:focus,
.btn-primary.active,
.show > .btn-primary.dropdown-toggle,
.btn-check:focus + .btn-primary,
.btn-check:active + .btn-primary,
.btn-check:checked + .btn-primary {
    box-shadow: none !important;
    outline: none !important;
    background-color: var(--ib-primary) !important;
    border-color: var(--ib-primary) !important;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--ib-primary-hover);
    border-color: var(--ib-primary-hover);
}

.btn-primary:active,
.btn-primary.active,
.show > .btn-primary.dropdown-toggle,
.btn-check:active + .btn-primary,
.btn-check:checked + .btn-primary {
    background-color: var(--ib-primary-hover) !important;
    border-color: var(--ib-primary-hover) !important;
}

.btn-danger {
    background-color: var(--ib-danger);
    border-color: var(--ib-danger);
}

.form-control,
.form-select {
    border-radius: 10px;
    border-color: var(--ib-border);
    box-shadow: none;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(34, 197, 94, 0.55);
    box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.18);
}

.password-field {
    position: relative;
}

.password-field .form-control {
    padding-right: 2.5rem;
}

.btn-eye {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    padding: 0.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ib-muted);
}

.btn-eye:hover {
    color: var(--ib-text);
}

.btn-eye .icon {
    width: 18px;
    height: 18px;
}

.modal-content {
    border-radius: var(--ib-radius);
    border: 1px solid var(--ib-border);
    box-shadow: var(--ib-shadow);
}

.modal-header {
    border-bottom: 1px solid var(--ib-border);
}

.modal-footer {
    border-top: 1px solid var(--ib-border);
}

/* Mobile hamburger */
.mobile-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1060;
    background-color: var(--ib-primary);
    color: #ffffff;
    border-radius: 0.5rem;
    padding: 6px 8px;
    border: none;
    box-shadow: var(--ib-shadow-sm);
}

@media (min-width: 768px) {
    .mobile-toggle {
        display: none;
    }
}

.mobile-toggle.hidden {
    opacity: 0;
    visibility: hidden;
}

@media (max-width: 767.98px) {
    #profileDropdown {
        position: fixed;
        top: 12px;
        right: 12px;
        left: auto;
        z-index: 1060;
        margin: 0 !important;
        max-width: calc(100vw - 72px);
    }

    #profileDropdown #profileMenuButton {
        padding: 4px !important;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #profileDropdown #profileMenuButton img {
        width: 28px !important;
        height: 28px !important;
    }

    .main-wrapper {
        padding-top: 45px !important;
    }

    .main-wrapper.p-3 {
        padding-top: 45px !important;
    }

    main.main-wrapper {
        padding-top: 45px !important;
    }

    .ib-container {
        padding-top: 4px;
    }

    #invoice-form .table-responsive {
        display: block;
        overflow-x: auto !important;
        overflow-y: hidden;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        touch-action: pan-x;
    }

    .main-wrapper,
    .ib-container {
        max-width: 100%;
        overflow-x: hidden;
    }

    #items-table {
        min-width: 820px;
        table-layout: auto;
    }

    #items-table th,
    #items-table td {
        white-space: nowrap;
        padding: 6px 8px;
        font-size: 0.9rem;
        vertical-align: middle;
    }

    #items-table td .form-control,
    #items-table td .form-select {
        width: 100%;
        min-width: 0;
        padding: 6px 8px;
        box-sizing: border-box;
    }

    #items-table td .form-select {
        padding-right: 2.25rem;
        background-position: right 0.75rem center;
        background-repeat: no-repeat;
        -webkit-appearance: none;
        appearance: none;
    }

    #items-table td .qty,
    #items-table td .price,
    #items-table td .discount-val {
        min-width: 90px;
    }

    #items-table td .discount-type {
        min-width: 110px;
    }

    #items-table td .line-total {
        min-width: 110px;
    }

    #items-table td .btn.btn-danger {
        min-width: 40px;
        padding: 6px 10px;
    }
}
