/* 
   MyBillBook Inspired Theme Overrides 
   Modern, Clean, SaaS Aesthetic
*/

:root {
    --primary-color: #462A75;
    /* Deep Amethyst */
    --primary-hover: #3a2261;
    /* Darker shade */
    --primary-soft: #f4effc;
    /* Soft Purple 50 */
    --accent-color: #10b981;
    /* Emerald for Success */
    --text-dark: #1e1b4b;
    /* Deep Slate */
    --text-muted: #64748b;
    --bg-body: #f8fafc;
    --card-shadow: 0 4px 6px -1px rgba(70, 42, 117, 0.05), 0 2px 4px -1px rgba(70, 42, 117, 0.03);
    --border-radius: 12px;
    --input-border: #e2e8f0;
    --input-focus: #462A75;
}

body {
    background-color: var(--bg-body);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-dark);
    font-size: 13.5px;
    line-height: 1.6;
}

/* --- Typography Scaling --- */
h1,
.h1 {
    font-size: 1.5rem;
}

h2,
.h2 {
    font-size: 1.25rem;
}

h3,
.h3 {
    font-size: 1.1rem;
}

h4,
.h4 {
    font-size: 1rem;
}

h5,
.h5 {
    font-size: 0.875rem;
}

h6,
.h6 {
    font-size: 0.75rem;
}

/* --- Typography --- */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.025em;
}

/* --- Cards --- */
.card,
.tile,
.invoice-card {
    background: #ffffff;
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    margin-bottom: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-header,
.tile-title {
    background: transparent;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.75rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body,
.tile-body {
    padding: 1.5rem;
}

/* --- Buttons --- */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.4rem 0.85rem;
    font-size: 13px;
    transition: all 0.2s;
    text-transform: none;
    letter-spacing: 0.01em;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #fff;
    border-color: #d1d5db;
    color: var(--text-dark);
}

.btn-secondary:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
}

.btn-success {
    background-color: #10b981;
    border-color: #10b981;
}

.btn-danger {
    background-color: #ef4444;
    border-color: #ef4444;
}

/* --- Forms --- */
.form-control,
.form-select {
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 13.5px;
    color: #374151;
    background-color: #fff;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(70, 42, 117, 0.15);
    /* Brand color mist */
}

label,
.control-label,
.form-label {
    font-weight: 500;
    font-size: 13px;
    color: #4b5563;
    margin-bottom: 0.3rem;
}

/* Adjustments for validation errors */
.is-invalid {
    border-color: #ef4444 !important;
}

/* --- Tables --- */
.table {
    width: 100%;
    margin-bottom: 1rem;
    color: #374151;
    vertical-align: middle;
}

.table thead th {
    background-color: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 16px;
}

.table tbody td {
    border-bottom: 1px solid #f3f4f6;
    padding: 10px 16px;
    font-size: 13.5px;
}

.table-hover tbody tr:hover {
    background-color: var(--primary-soft);
}

/* --- Sidebar & Header (Vali Theme Overrides) --- */
.app-header {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    height: 75px !important;
    /* Explicitly forced */
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    margin: 0 !important;
    z-index: 1050;
}

.app-header__logo {
    background-color: #fff !important;
    color: var(--primary-color) !important;
    font-family: 'Inter', sans-serif;
    font-size: 20px;
    font-weight: 700;
    width: 230px;
    height: 75px;
    margin-left: -1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid #f1f5f9;
}

.logo-icon {
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.15);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.app-header__logo:hover .logo-icon {
    transform: rotate(15deg) scale(1.1);
}

.app-sidebar__toggle {
    color: var(--text-dark);
    width: 45px;
    height: 45px;
    margin: 0 0.5rem;
    padding: 0;
    line-height: normal;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex !important;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.app-sidebar__toggle::before {
    display: none !important;
    /* Hide Vali theme default */
}

.app-sidebar__toggle:hover {
    background-color: var(--primary-soft);
    color: var(--primary-color);
}

.app-sidebar__toggle i {
    transition: transform 0.3s ease;
}

.app-sidebar__toggle:active i {
    transform: scale(0.9);
}

.sidenav-toggled .app-sidebar__toggle i {
    transform: rotate(180deg);
}

.avatar-circle {
    width: 35px;
    height: 35px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.app-nav__item {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 10px;
    position: relative;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    color: var(--text-muted);
}

.app-nav__item:hover {
    background-color: var(--primary-soft);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.header-search input {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent !important;
}

.header-search input:focus {
    width: 380px !important;
    background-color: #fff !important;
    border-color: var(--primary-color) !important;
    box-shadow: 0 4px 12px rgba(70, 42, 117, 0.08) !important;
}

.dropdown-menu {
    border-radius: 15px !important;
    padding: 0.8rem !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1) !important;
    border: 1px solid #eee !important;
    animation: dropdownFade 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dropdownFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-menu.show {
    display: block !important;
}

/* --- Toggled State Adjustments (Desktop Only) --- */
@media (min-width: 768px) {
    .sidenav-toggled .app-header__logo {
        width: 50px;
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 0;
    }

    .sidenav-toggled .app-header__logo img {
        height: 32px !important;
        width: auto;
    }

    .sidenav-toggled .logo-icon {
        margin: 0 !important;
        transform: scale(0.9);
    }

    .sidenav-toggled .app-sidebar__user {
        display: none;
    }

    .sidenav-toggled .app-menu__label {
        display: none;
    }

    .sidenav-toggled .app-menu__item {
        justify-content: center;
        padding: 12px 0;
        margin: 8px auto;
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }

    .sidenav-toggled .app-menu__icon {
        margin: 0 !important;
        font-size: 1.2rem;
    }

    .sidenav-toggled .app-menu__separator {
        display: none;
    }

    .sidenav-toggled .mt-auto {
        display: none !important;
    }
}

/* Glassmorphism for Sidebar too */
.app-sidebar {
    position: fixed !important;
    background-color: rgba(252, 252, 253, 0.9);
    backdrop-filter: blur(15px);
    border-right: 1px solid rgba(238, 240, 242, 0.5);
    box-shadow: none;
    top: 75px !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
    height: calc(100vh - 75px) !important;
    z-index: 1040;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    left: 0;
}

.sidenav-toggled .app-sidebar {
    left: -230px;
}

@media (max-width: 767px) {
    .app-sidebar {
        left: -300px !important;
        visibility: hidden;
        opacity: 0;
        box-shadow: none !important;
        border: none !important;
        top: 0 !important;
        height: 100vh !important;
        z-index: 1060;
    }

    .sidenav-toggled .app-sidebar {
        left: 0 !important;
        visibility: visible;
        opacity: 1;
    }

    .app-sidebar__overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1050;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
    }

    .sidenav-toggled .app-sidebar__overlay {
        display: block;
    }
}

.app-sidebar__user {
    padding-top: 0px !important;
    padding-bottom: 12px !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    margin-top: 0 !important;
    transition: all 0.3s;
}

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

.app-menu__item {
    color: #4b5563;
    font-weight: 500;
    font-size: 13px;
    border-radius: 10px;
    margin: 4px 12px;
    padding: 8px 15px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
}

.app-menu__icon {
    font-size: 1.1rem;
    transition: transform 0.3s ease;
}

.app-menu__item:hover .app-menu__icon {
    transform: scale(1.2);
}

.app-menu__item:hover {
    background-color: var(--primary-soft);
    color: var(--primary-color);
    padding-left: 20px;
    /* Indent on hover */
}

.app-menu__item.active {
    background-color: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 12px rgba(70, 42, 117, 0.25);
}

.app-menu__item.active .app-menu__icon {
    color: #fff;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 991px) {
    .header-search {
        display: none !important;
    }

    .app-header__logo {
        width: 180px;
    }

    .logo-text {
        font-size: 18px;
    }

    .app-header {
        padding: 0 0.5rem;
    }
}

@media (max-width: 767px) {
    .app-nav__item span {
        display: none;
    }

    .app-nav {
        margin-right: 0 !important;
    }

    .app-sidebar {
        width: 250px;
    }

    /* Center create button label fix */
    .btn-primary span {
        display: none;
    }

    .btn-primary {
        padding: 8px 10px;
    }
}

/* --- Interactive Animations --- */
.pulse-on-hover:hover {
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.05);
    }
}

/* --- Dashboard Widgets Upgrade --- */
.widget-small {
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.widget-small:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    border-color: rgba(70, 42, 117, 0.1);
}

.widget-small .info p {
    color: #111827;
    font-size: 1.5rem;
    font-weight: 700;
}

/* --- Utilities --- */
.text-primary {
    color: var(--primary-color) !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

/* Custom Badge Pill */
.badge {
    padding: 0.35em 0.65em;
    font-weight: 600;
    border-radius: 9999px;
}

/* Breadcrumbs */
.breadcrumb {
    background-color: transparent;
    padding: 0;
    margin-bottom: 1.5rem;
}

.breadcrumb-item a {
    color: var(--primary-color);
    text-decoration: none;
}

.breadcrumb-item.active {
    color: #9ca3af;
}

/* Dashboard Widgets */
.widget-small {
    background: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.widget-small .icon {
    background-color: rgba(70, 42, 117, 0.1);
    color: var(--primary-color);
}

.widget-small.primary .icon {
    background-color: rgba(70, 42, 117, 0.1);
    color: var(--primary-color);
}

.widget-small.info .icon {
    background-color: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.widget-small.warning .icon {
    background-color: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.widget-small.danger .icon {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.widget-small .info h4 {
    color: #6b7280;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.widget-small .info p {
    color: #111827;
    font-size: 1.5rem;
    font-weight: 700;
}

/* --- Header Banners & Page Titles --- */
.invoice-header-banner {
    background: linear-gradient(135deg, var(--primary-color), #6a4fa3);
    color: #fff !important;
    border-radius: 12px;
    padding: 0.85rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 12px rgba(70, 42, 117, 0.15);
}

.invoice-header-banner h5,
.invoice-header-banner h1,
.invoice-header-banner .h5 {
    color: #fff !important;
    font-weight: 700;
    margin: 0;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

/* Make legacy .app-title headers match invoice-header-banner design */
main.app-content .app-title {
    background: linear-gradient(135deg, var(--primary-color), #6a4fa3);
    color: #fff !important;
    border-radius: 12px;
    padding: 0.85rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 12px rgba(70, 42, 117, 0.15);
    border: 0;
}

main.app-content .app-title h1,
main.app-content .app-title h2,
main.app-content .app-title h3,
main.app-content .app-title h4,
main.app-content .app-title h5,
main.app-content .app-title p {
    color: #fff !important;
    margin: 0;
}

main.app-content .app-title h1 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

main.app-content .app-title .app-breadcrumb,
main.app-content .app-title .app-breadcrumb .breadcrumb-item,
main.app-content .app-title .app-breadcrumb .breadcrumb-item a,
main.app-content .app-title .app-breadcrumb .breadcrumb-item.active,
main.app-content .app-title .app-breadcrumb .breadcrumb-item i {
    color: #fff !important;
    opacity: 0.9;
}

@media (max-width: 768px) {
    main.app-content .app-title {
        padding: 0.75rem 1rem;
    }

    main.app-content .app-title .app-breadcrumb {
        margin-top: 0.35rem;
    }
}

.breadcrumb-item i {
    color: var(--text-muted);
}

/* --- Internet Failure Overlay --- */
#offline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
    text-align: center;
    animation: fadeInOverlay 0.5s ease-out;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.offline-card {
    background: #fff;
    padding: 3rem;
    border-radius: 24px;
    width: 90%;
    max-width: 450px;
    color: #1e293b;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    animation: slideUpCard 0.4s ease-out forwards;
}

@keyframes slideUpCard {
    to {
        transform: translateY(0);
    }
}

.offline-icon-container {
    width: 80px;
    height: 80px;
    background: #fee2e2;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 2.5rem;
    color: #ef4444;
    position: relative;
}

.offline-icon-container i {
    z-index: 1;
}

.offline-icon-container::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #ef4444;
    opacity: 0.3;
    animation: pulseIcon 2s infinite;
}

@keyframes pulseIcon {
    0% {
        transform: scale(1);
        opacity: 0.3;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

.offline-card h2 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: #0f172a;
}

.offline-card p {
    color: #64748b;
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 2rem;
}

.connection-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 0.9rem;
}

.dot-flashing {
    position: relative;
    width: 6px;
    height: 6px;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: var(--primary-color);
    animation: dotFlashing 1s infinite linear alternate;
    animation-delay: .5s;
}

.dot-flashing::before,
.dot-flashing::after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 0;
}

.dot-flashing::before {
    left: -12px;
    width: 6px;
    height: 6px;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: var(--primary-color);
    animation: dotFlashing 1s infinite linear alternate;
    animation-delay: 0s;
}

.dot-flashing::after {
    left: 12px;
    width: 6px;
    height: 6px;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: var(--primary-color);
    animation: dotFlashing 1s infinite linear alternate;
    animation-delay: 1s;
}

@keyframes dotFlashing {
    0% {
        background-color: var(--primary-color);
    }

    50%,
    100% {
        background-color: #e2e8f0;
    }
}

/* --- Global Main Spacing Fix --- */
main.app-content {
    margin-top: calc(75px + 0.5rem) !important;
    margin-left: 230px;
}

.sidenav-toggled main.app-content {
    margin-left: 50px;
}

@media (max-width: 767px) {
    main.app-content {
        margin-top: calc(75px + 0.5rem) !important;
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .sidenav-toggled main.app-content {
        margin-left: 0 !important;
    }
}
