/**
 * Micro SaaS Tickets - Global Design System
 * Focus: Indigo Professional B2B Aesthetic — Mobile-First Responsive
 */

:root {
    /* Colors - Indigo Palette */
    --primary: #4f46e5;
    --primary-soft: #f5f7ff;
    --primary-hover: #4338ca;
    --primary-glow: rgba(79, 70, 229, 0.08);
    /* Reduced glow intensity */

    /* Neutrals - Slate Palette */
    --white: #ffffff;
    --bg-body: #eff1f4;
    /* Slightly darker for better contrast with cards */
    --bg-surface: #ffffff;
    --bg-sidebar: #ffffff;
    /* Refined White Sidebar */
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border-color: #e2e8f0;
    --input-border: #cbd5e1;

    /* System Tokens */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-pill: 9999px;

    /* Multi-layered Premium Shadows */
    --shadow-sm: 0 2px 4px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-premium: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --sidebar-width: 270px;
    --sidebar-collapsed: 85px;
    --header-height: 70px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =====================================================
   BASE STYLES
   ===================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body,
.bg-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body) !important;
    color: var(--text-main);
    font-size: 0.9375rem;
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-main);
    font-weight: 700;
    letter-spacing: -0.025em;
}

.text-muted {
    color: var(--text-muted) !important;
}

.small-tight {
    font-size: 0.8rem;
    line-height: 1.2;
}

/* =====================================================
   COMPONENTS — CARDS
   ===================================================== */
.card {
    background-color: var(--bg-surface);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    /* Removed height: 100% to prevent vertical stretching layout bugs in flex containers */
    display: flex;
    flex-direction: column;
    min-width: 0;
    word-wrap: break-word;
    background-clip: border-box;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

/* =====================================================
   COMPONENTS — BUTTONS
   ===================================================== */
.btn {
    font-weight: 600;
    border-radius: var(--radius-md);
    padding: 0.625rem 1.25rem;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
    background-color: #64748b;
    border-color: #64748b;
    color: var(--white);
}

.btn-secondary:hover {
    background-color: #475569;
    border-color: #475569;
    color: var(--white);
    transform: translateY(-1px);
}

.btn-light {
    background-color: var(--white);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}

.btn-light:hover {
    background-color: var(--bg-body);
    border-color: var(--input-border);
    box-shadow: var(--shadow);
}

/* =====================================================
   COMPONENTS — FORMS
   ===================================================== */
.form-label {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control,
.form-select {
    padding: 0.625rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--input-border);
    background-color: var(--white);
    transition: var(--transition);
    /* Prevent iOS zoom on focus (font-size >= 16px) */
    font-size: 16px;
}

@media (min-width: 768px) {

    .form-control,
    .form-select {
        font-size: 0.9375rem;
    }
}

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

/* =====================================================
   COMPONENTS — TABLES
   ===================================================== */
.table-responsive {
    border-radius: var(--radius-lg);
    background: var(--white);
    border: 1px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
}

.table thead th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

/* =====================================================
   LAYOUT — APP SHELL
   ===================================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.02);
}

/* Custom Scrollbar for Sidebar */
.app-sidebar::-webkit-scrollbar {
    width: 4px;
}

.app-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.1);
}

.app-sidebar .sidebar-logo-text h6 {
    color: var(--text-main) !important;
}

.app-sidebar .sidebar-toggle-btn {
    background: var(--white);
    border: 1px solid var(--border-color) !important;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}

.app-sidebar .sidebar-toggle-btn:hover {
    background: var(--bg-body);
    color: var(--primary);
}

.app-sidebar .sidebar-section-title {
    color: var(--text-light) !important;
    font-weight: 700;
}

/* ---- Main Content ---- */
.app-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar Collapsed State (Desktop) */
@media (min-width: 992px) {
    .sidebar-collapsed .app-sidebar {
        width: var(--sidebar-collapsed);
        background: var(--bg-sidebar);
    }

    .sidebar-collapsed .app-content {
        margin-left: var(--sidebar-collapsed);
    }

    .sidebar-collapsed .app-sidebar .sidebar-logo-text,
    .sidebar-collapsed .app-sidebar .sidebar-nav-link span,
    .sidebar-collapsed .app-sidebar .sidebar-section-title,
    .sidebar-collapsed .app-sidebar .badge-pill-nav,
    .sidebar-collapsed .app-sidebar .sidebar-footer-text {
        display: none !important;
    }

    .sidebar-collapsed .app-sidebar .sidebar-nav-link {
        justify-content: center;
        padding: 0.85rem 0 !important;
        width: 100%;
        margin: 0.2rem 0 !important;
    }

    .sidebar-collapsed .app-sidebar .sidebar-nav-link.active::before {
        left: 0;
        top: 15%;
        bottom: 15%;
        width: 3px;
    }

    .sidebar-collapsed .app-sidebar .sidebar-nav-link i {
        margin: 0 !important;
        font-size: 1.5rem;
        width: auto !important;
    }

    /* Fixed Toggle and Header centering */
    .sidebar-collapsed .app-sidebar .sidebar-header {
        justify-content: center !important;
        padding: 0 !important;
        height: 64px;
    }

    /* Hide logo container in collapsed mode to center toggle */
    .sidebar-collapsed .app-sidebar .sidebar-header>div:first-child {
        display: none !important;
    }

    .sidebar-collapsed .app-sidebar .sidebar-toggle-btn {
        margin: 0 !important;
    }

    .sidebar-collapsed .app-sidebar .sidebar-nav-container {
        padding: 1rem 0 !important;
    }

    .sidebar-collapsed .app-sidebar .sidebar-footer {
        padding: 1rem 0;
        text-align: center;
    }
}

/* ---- Header ---- */
.app-header {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    position: sticky;
    top: 0;
    z-index: 999;
    padding: 0 2rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

/* =====================================================
   BADGES
   ===================================================== */
.badge-soft-primary {
    background: var(--primary-soft);
    color: var(--primary);
}

.badge-soft-success {
    background: var(--success-soft);
    color: var(--success);
}

.badge-soft-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge-soft-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

/* =====================================================
   ANIMATION
   ===================================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.fade-in-up {
    animation: fadeIn 0.4s ease-out forwards;
}

/* =====================================================
   UTILITIES
   ===================================================== */
.glass {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(12px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: var(--shadow-premium);
}

.letter-spacing-1 {
    letter-spacing: 1px;
}

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =====================================================
   MOBILE OFFCANVAS SIDEBAR STYLES
   ===================================================== */
.offcanvas-sidebar-link {
    color: var(--text-muted);
    font-weight: 500;
    border-radius: var(--radius-md);
    padding: 0.65rem 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    text-decoration: none;
    margin-bottom: 0.15rem;
    font-size: 0.95rem;
}

.offcanvas-sidebar-link i {
    margin-right: 0.75rem;
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.offcanvas-sidebar-link:hover {
    background: var(--bg-body);
    color: var(--primary);
}

.offcanvas-sidebar-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

/* =====================================================
   RESPONSIVE — TABLET (< 992px)
   ===================================================== */
@media (max-width: 991.98px) {

    /* Hide desktop sidebar, content fills full width */
    .app-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Prevent any element from leaking outside viewport */
    html,
    body {
        max-width: 100vw;
        overflow-x: hidden;
    }

    .container,
    .container-fluid,
    .row {
        max-width: 100% !important;
    }

    /* Reduce page padding */
    .p-4.p-lg-5 {
        padding: 1.25rem !important;
    }

    .p-lg-5 {
        padding: 1.25rem !important;
    }

    /* Cards stack cleanly */
    .row.g-4>[class*="col-"] {
        padding: 0.5rem;
    }
}

/* =====================================================
   RESPONSIVE — MOBILE (< 768px)
   ===================================================== */
@media (max-width: 767.98px) {

    /* Header adjustments */
    .app-header {
        padding: 0 1rem;
    }

    .app-wrapper {
        overflow-x: hidden;
    }

    /* Page inner padding */
    .app-content>main .p-4,
    .app-content .p-4 {
        padding: 1rem !important;
    }

    /* Card body padding */
    .card-body.p-4 {
        padding: 1rem !important;
    }

    .card-header {
        padding: 1rem;
    }

    /* Table: allow horizontal scroll, compact cells */
    .table thead th,
    .table tbody td {
        padding: 0.625rem 0.75rem;
        font-size: 0.85rem;
    }

    /* Reduce display-6 headings */
    .display-6 {
        font-size: 1.5rem !important;
    }

    /* KPI cards: 2-column grid on mobile */
    .kpi-card-grid>[class*="col-xl-3"] {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Btn full-width on mobile when in stacked container */
    .btn-mobile-full {
        width: 100%;
        justify-content: center;
    }

    /* Dashboard header top section — stack vertically */
    .dashboard-header-actions {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    /* Offcanvas full width on small phones */
    .offcanvas-start {
        width: min(300px, 85vw) !important;
    }

    /* Forms inside modal/offcanvas use full width */
    .modal-body .row.g-3>[class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* =====================================================
   RESPONSIVE — SMALL PHONES (< 480px)
   ===================================================== */
@media (max-width: 479.98px) {
    body {
        font-size: 0.875rem;
    }

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

    /* Single column KPI on very small screens */
    .kpi-card-grid>[class*="col-xl-3"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Stack header buttons */
    .btn-group-mobile {
        flex-direction: column;
        width: 100%;
    }

    .btn-group-mobile .btn {
        width: 100%;
        justify-content: center;
    }

    /* Table: allow compact mode */
    .table-sm-auto {
        table-layout: auto;
    }
}

/* =====================================================
   PRINT (optional)
   ===================================================== */
@media print {

    .app-sidebar,
    .app-header,
    .offcanvas {
        display: none !important;
    }

    .app-content {
        margin-left: 0 !important;
    }
}