/**
 * ATRICARD — UNIFIED ENTERPRISE DESIGN SYSTEM
 * Modern, Premium SaaS UI Architecture
 * Consistent Typography, Spacing Scale, Restrained Radius, and Polished Palette
 */

/* ==========================================================================
   1. DESIGN TOKENS & CSS VARIABLES
   ========================================================================== */
:root,
[data-theme="light"] {
    --theme-mode: 'light';

    /* Brand Primary Palette: Deep Premium Indigo */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-active: #3730a3;
    --primary-light: rgba(79, 70, 229, 0.08);
    --primary-subtle: rgba(79, 70, 229, 0.14);

    /* Accents */
    --secondary: #6366f1;
    --accent: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0284c7;

    /* Neutrals: Crisp White, Off-White, Slate, Charcoal */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-muted: #e2e8f0;
    --bg-input: #ffffff;
    --bg-input-addon: #f8fafc;

    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --border-focus: #4f46e5;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Subtle Premium Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.09), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
    --card-shadow: var(--shadow-sm);
    --card-shadow-hover: var(--shadow-md);

    /* Dimensions & Restrained Radius Scale */
    --sidebar-width: 260px;
    --header-height: 68px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-card: 20px;
    --radius-modal: 24px;
    --radius-pill: 9999px;

    --header-bg: rgba(255, 255, 255, 0.92);
    --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
    --theme-mode: 'dark';

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-active: #4338ca;
    --primary-light: rgba(99, 102, 241, 0.12);
    --primary-subtle: rgba(99, 102, 241, 0.2);

    --secondary: #818cf8;
    --accent: #38bdf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #38bdf8;

    --bg-main: #0a0e17;
    --bg-surface: #111726;
    --bg-card: #131b2e;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-muted: #1e293b;
    --bg-input: #0f1626;
    --bg-input-addon: #182238;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.18);
    --border-focus: #6366f1;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.7);
    --shadow-xl: 0 24px 40px -8px rgba(0, 0, 0, 0.85);
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --card-shadow-hover: 0 10px 30px rgba(0, 0, 0, 0.5);

    --header-bg: rgba(17, 23, 38, 0.9);
}

/* ==========================================================================
   2. BASE RESET & TYPOGRAPHY SYSTEM
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 0.925rem;
    line-height: 1.55;
    color: var(--text-primary);
    background-color: var(--bg-main);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
    margin-top: 0;
}

h1, .h1 { font-size: 1.85rem; }
h2, .h2 { font-size: 1.5rem; }
h3, .h3 { font-size: 1.25rem; }
h4, .h4 { font-size: 1.1rem; }
h5, .h5 { font-size: 0.98rem; }
h6, .h6 { font-size: 0.88rem; }

p {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    color: var(--primary-hover);
}

/* Focus visibility for accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   3. APP SHELL LAYOUT (Sidebar & Main Workspace)
   ========================================================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    transition: transform 0.25s ease-in-out, background-color 0.2s ease, border-color 0.2s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 22px;
    border-bottom: 1px solid var(--border-color);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 1.2rem;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff !important;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 10px 14px 6px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 3px;
    transition: var(--transition);
}

.sidebar-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    color: var(--text-muted);
    transition: var(--transition);
}

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

.sidebar-link:hover i {
    color: var(--primary);
}

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

.sidebar-link.active i {
    color: var(--primary);
}

[data-theme="dark"] .sidebar-link.active {
    color: #ffffff;
    background: var(--primary-subtle);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

/* Main Workspace */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.25s ease-in-out;
}

.app-navbar {
    height: var(--header-height);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
}

.app-navbar h5 {
    color: var(--text-primary);
    font-size: 1.15rem;
}

.content-body {
    flex: 1;
    padding: 28px;
}

/* ==========================================================================
   4. CARDS & SURFACES
   ========================================================================== */
.atri-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-card);
    box-shadow: var(--card-shadow);
    transition: var(--transition);
    position: relative;
}

.atri-card:hover {
    border-color: var(--border-hover);
}

.card-header-custom {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
}

.card-header-custom h6 {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 700;
}

.card-body-custom {
    padding: 24px;
}

/* Stat & KPI Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--card-shadow);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

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

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-val {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    line-height: 1.15;
    margin: 8px 0 4px;
}

/* Hero Overview Banner */
.client-hero-card {
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-hover) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-card);
}

/* ==========================================================================
   5. BUTTONS & CONTROLS
   ========================================================================== */
.btn-primary-custom {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: #ffffff !important;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
    cursor: pointer;
}

.btn-primary-custom:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.btn-primary-custom:active {
    transform: translateY(0);
}

.btn-secondary-custom {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
}

.btn-secondary-custom:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.theme-toggle-btn {
    padding: 7px 12px !important;
}

/* ==========================================================================
   6. TABLES & DATA LISTS
   ========================================================================== */
.table-responsive-custom {
    overflow-x: auto;
    border-radius: var(--radius-card);
}

.atri-table {
    width: 100%;
    margin-bottom: 0;
    color: var(--text-primary);
    border-collapse: separate;
    border-spacing: 0;
}

.atri-table th {
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.atri-table td {
    padding: 15px 18px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.atri-table tr:hover td {
    background: var(--bg-hover);
}

.atri-table tr:last-child td {
    border-bottom: none;
}

/* ==========================================================================
   7. BADGES & CHIPS
   ========================================================================== */
.badge-soft {
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.badge-soft-success {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.25);
}
[data-theme="dark"] .badge-soft-success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.badge-soft-primary {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.2);
}
[data-theme="dark"] .badge-soft-primary {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}

.badge-soft-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.25);
}
[data-theme="dark"] .badge-soft-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.badge-soft-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.25);
}
[data-theme="dark"] .badge-soft-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.badge-soft-info {
    background: rgba(14, 165, 233, 0.1);
    color: #0284c7;
    border: 1px solid rgba(14, 165, 233, 0.25);
}
[data-theme="dark"] .badge-soft-info {
    background: rgba(14, 165, 233, 0.15);
    color: #38bdf8;
}

/* ==========================================================================
   8. FORM INPUTS & CONTROLS
   ========================================================================== */
.form-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

.form-control-custom,
.form-select-custom {
    background: var(--bg-input) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    padding: 10px 14px !important;
    font-size: 0.9rem !important;
    transition: border-color 0.18s, box-shadow 0.18s !important;
}

.form-control-custom:focus,
.form-select-custom:focus {
    border-color: var(--border-focus) !important;
    box-shadow: 0 0 0 3px var(--primary-light) !important;
    outline: none !important;
}

.form-control-custom::placeholder {
    color: var(--text-muted) !important;
}

.input-group-text {
    background: var(--bg-input-addon) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
    font-size: 0.88rem !important;
}

/* ==========================================================================
   9. DESIGN CATALOG PRODUCT CARDS (3 cols desktop, 2 cols tablet, 1 col mobile)
   ========================================================================== */
.design-catalog-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

@media (max-width: 1024px) {
    .design-catalog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .design-catalog-grid {
        grid-template-columns: 1fr;
    }
}

.design-product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--card-shadow);
    transition: var(--transition);
}

.design-product-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

.design-product-card.active-design {
    border: 2px solid var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light), var(--card-shadow-hover);
}

/* Scaled Iframe Preview Container inside Design Cards */
.catalog-preview-box {
    position: relative;
    width: 100%;
    height: 340px;
    background: #090d16;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
}

.catalog-viewport-scaled {
    width: 410px;
    height: 680px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scale(0.5);
    transform-origin: top center;
    pointer-events: none;
}

.catalog-viewport-scaled iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 20px;
    background: #ffffff;
}

.catalog-preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    cursor: pointer;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.catalog-preview-box:hover .catalog-preview-overlay {
    opacity: 1;
}

/* ==========================================================================
   10. LIVE PREVIEW FRAMES (Mobile & Desktop Toggles)
   ========================================================================== */
.preview-chassis-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px;
    background: var(--bg-hover);
    border-radius: var(--radius-lg);
    min-height: 720px;
}

/* Mobile Chassis (iPhone Pro style) */
.mobile-frame-chassis {
    width: 390px;
    height: 780px;
    background: #0b0f19;
    border: 11px solid #1e293b;
    border-radius: 46px;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease;
}

.mobile-notch {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 96px;
    height: 20px;
    background: #1e293b;
    border-radius: 12px;
    z-index: 50;
    pointer-events: none;
}

.mobile-frame-chassis iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #ffffff;
}

/* Desktop Preview Frame */
.desktop-frame-chassis {
    width: 100%;
    max-width: 1100px;
    height: 780px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    transition: width 0.3s ease;
}

.desktop-frame-chassis iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ==========================================================================
   11. EMPTY STATES, MODALS & TOASTS
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
}

.empty-icon {
    font-size: 42px;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: inline-block;
}

/* Modals */
.modal-content {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-modal) !important;
    box-shadow: var(--shadow-xl) !important;
    overflow: hidden;
}

.modal-header {
    border-bottom: 1px solid var(--border-color) !important;
    padding: 20px 24px !important;
}

.modal-footer {
    border-top: 1px solid var(--border-color) !important;
    padding: 16px 24px !important;
}

/* Toast Alerts */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.atri-toast {
    pointer-events: auto;
    min-width: 320px;
    max-width: 420px;
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    animation: toastSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.atri-toast.toast-success { border-left-color: var(--success); }
.atri-toast.toast-error { border-left-color: var(--danger); }
.atri-toast.toast-warning { border-left-color: var(--warning); }

@keyframes toastSlide {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Breakpoints */
@media (max-width: 992px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }
    .app-main {
        margin-left: 0;
    }
    .content-body {
        padding: 18px;
    }
}
