/* CSS Reset & Variables */
:root {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    --primary: #10b981;
    --primary-hover: #059669;
    --secondary: #3b82f6;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --border: #e2e8f0;
    --border-glow: rgba(16, 185, 129, 0.3);
    
    --glass-blur: blur(8px);
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body { 
    font-family: var(--font-body); 
    margin: 0; 
    background-color: var(--bg-main); 
    color: var(--text-main); 
    line-height: 1.6;
    min-height: 100vh;
}

/* Typography & Layout */
.container { 
    max-width: 100%; 
    margin: 0 auto; 
    padding: 20px; 
}

/* Dashboard New Layout Grids */
.dash-layout-top {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.dash-layout-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.dash-charts-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1.5fr;
    gap: 24px;
}

@media (max-width: 992px) {
    .hide-mobile { display: none !important; }
    .dash-layout-top, .dash-layout-bottom, .dash-charts-row {
        grid-template-columns: 1fr;
    }
}

h1, h2, h3, h4 { 
    font-family: var(--font-heading);
    margin-top: 0; 
    color: var(--text-main); 
    font-weight: 700;
    letter-spacing: -0.03em;
}

h1 { font-size: 3rem; text-align: center; margin-bottom: 2.5rem; }
h2 { font-size: 2rem; margin-bottom: 1.5rem; }

.text-center { text-align: center; }

/* Animations */
@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Glassmorphism Cards */
.glass-panel {
    background: var(--bg-card); 
    border-radius: 16px;
    padding: 35px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.card { 
    background: var(--bg-card); 
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 24px; 
    box-shadow: var(--shadow-soft); 
    padding: 40px; 
    margin-bottom: 32px;
    border: 1px solid var(--border);
    transition: transform 0.3s ease, border-color 0.3s ease;
    max-width: 100%;
    min-width: 0;
}

.card:hover {
    border-color: rgba(0, 0, 0, 0.1);
}

/* Forms & Inputs */
.form-group { margin-bottom: 24px; position: relative; }
label { 
    display: block; 
    margin-bottom: 10px; 
    font-weight: 600; 
    font-size: 0.85em; 
    color: var(--text-muted); 
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-control, input:not([type="checkbox"]):not([type="radio"]), select, textarea { 
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 14px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    background-color: var(--bg-input);
    color: var(--text-main); 
    font-size: 1rem; 
    transition: all 0.3s; 
    box-sizing: border-box !important;
    font-family: var(--font-body);
    -webkit-appearance: none;
    appearance: none;
    text-align: left;
}

input:focus, select:focus, textarea:focus { 
    outline: none; 
    border-color: var(--primary); 
    background-color: var(--bg-card);
    box-shadow: 0 0 0 4px var(--border-glow); 
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

/* Premium Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 16px 32px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    box-shadow: 0 4px 20px 0 rgba(16, 185, 129, 0.2);
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 50%; height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 100%);
    transform: skewX(-20deg);
    transition: all 0.5s ease;
}

.btn:hover { 
    transform: translateY(-2px) scale(1.02); 
    box-shadow: 0 8px 25px 0 rgba(16, 185, 129, 0.3); 
}

.btn:hover::after {
    left: 150%;
}

.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; box-shadow: none; transform: none; }

.btn-outline { 
    background: transparent; 
    color: var(--text-main); 
    border: 1px solid var(--border); 
    box-shadow: none;
}
.btn-outline:hover { 
    background: var(--bg-input); 
    border-color: var(--text-muted); 
    box-shadow: none; 
}
.btn-danger { background: var(--danger); box-shadow: 0 4px 20px 0 rgba(239, 68, 68, 0.2); }
.btn-danger:hover { box-shadow: 0 8px 25px 0 rgba(239, 68, 68, 0.3); }

.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: 8px; }

/* Authentication Container */
.auth-container {
    max-width: 460px;
    margin: 40px auto;
}

/* Navigation Tabs */
.auth-tabs {
    display: flex;
    margin-bottom: 40px;
    background: var(--bg-input);
    padding: 8px;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.auth-tabs button {
    flex: 1;
    background: transparent;
    color: var(--text-muted);
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-tabs button.active {
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: var(--shadow-soft);
}

/* Top Navigation (Dashboard) */
.nav { 
    display: flex; 
    gap: 16px; 
    margin-bottom: 40px; 
    overflow-x: auto; 
    padding: 8px; 
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
}
.nav .btn { flex: 1; margin: 0; white-space: nowrap; }

/* Alerts */
.alert { 
    padding: 16px 20px; 
    border-radius: 12px; 
    margin-bottom: 24px; 
    display: none; 
    font-weight: 500;
    animation: slideUpFade 0.3s ease;
}
.alert.error { 
    display: block;
    background-color: #fee2e2; 
    color: #991b1b; 
    border: 1px solid #fecaca; 
    border-left: 4px solid var(--danger);
}
.alert.success { 
    display: block;
    background-color: #d1fae5; 
    color: #065f46; 
    border: 1px solid #a7f3d0; 
    border-left: 4px solid var(--success);
}

/* Utilities */
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }
.grid-charts { display: grid; grid-template-columns: 1fr 2fr; gap: 24px; }
.header-flex { display: flex; justify-content: space-between; align-items: flex-start; }

/* Data Tables */
.table-responsive { overflow-x: auto; margin-bottom: 24px; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--bg-card); }
th, td { padding: 15px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg-input); font-weight: 600; color: var(--text-main); text-transform: uppercase; font-size: 0.85em; letter-spacing: 0.05em; }
td { color: var(--text-main); }
tr:hover td { background: var(--bg-input); }

/* Status Badges */
.badge { padding: 4px 10px; border-radius: 99px; font-size: 0.85em; font-weight: 600; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-error { background: #fee2e2; color: #991b1b; }

/* Account & Deal Cards */
.account-card, .deal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 25px;
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.account-card:hover, .deal-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.deal-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 16px;
}

@media (max-width: 768px) {
    .modal-content { width: 95%; margin: 5% auto; }
}

/* Secondary Buttons */
.btn-secondary {
    background: transparent !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border) !important;
    box-shadow: none !important;
}
.btn-secondary:hover {
    background: var(--bg-input) !important;
    color: var(--text-main) !important;
    box-shadow: none !important;
}
.btn-secondary::after {
    display: none;
}

/* Mobile Responsiveness Improvements */
@media (max-width: 768px) {
    .container { padding: 10px; }
    .card { padding: 15px; margin-bottom: 20px; }
    .glass-panel { padding: 15px; }
    
    .btn { padding: 10px 15px; font-size: 13px; }
    
    /* Force table cells to not wrap on mobile so it triggers horizontal scroll cleanly */
    .table-responsive table { white-space: nowrap; }
    th, td { padding: 10px; font-size: 13px; }
    
    /* Make the action buttons on inventory fill better */
    #inv-header-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        width: 100%;
    }
    #inv-header-actions .btn {
        width: 100%;
        margin: 0;
    }
    .nav { flex-wrap: wrap; }
    .nav .btn { flex: 1 1 calc(50% - 16px); }
    .grid-2, .grid-3, .grid-4, .grid-charts { grid-template-columns: 1fr; }
    .header-flex { flex-direction: column; gap: 16px; }
    .card { padding: 24px; }
    
    /* Prevent charts from overflowing the screen width */
    canvas {
        max-width: 100%;
        height: auto !important;
    }
}

/* Floating Action Button (FAB) */
.fab-container {
    position: fixed;
    bottom: calc(var(--bottom-nav-height, 70px) + 20px); /* Clear mobile bottom nav */
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 10px;
}
.fab-main {
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    font-size: 24px;
    border: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.fab-main:active {
    transform: scale(0.95);
}
.fab-actions {
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}
.fab-container.active .fab-actions {
    display: flex;
}
.fab-action-btn {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 10px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    cursor: pointer;
    white-space: nowrap;
}

/* Sidebar Layout & Navigation */
:root {
    --sidebar-width: 250px;
    --header-height: 60px;
    --bottom-nav-height: 70px;
}

.app-container {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    top: 0;
    left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    transition: left 0.3s ease;
    z-index: 1001;
    overflow-y: auto;
    box-shadow: var(--shadow-soft);
}
.sidebar.open { left: 0; }
.sidebar-profile { padding: 20px; border-bottom: 1px solid var(--border); }
.accordion-menu .menu-section { margin-bottom: 15px; }
.accordion-menu .menu-header { font-size: 11px; font-weight: 700; color: var(--text-muted); margin: 15px 20px 5px; }
.accordion-menu .nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--text-main); text-decoration: none; font-weight: 500; font-size: 14px; transition: background 0.2s, color 0.2s; }
.accordion-menu .nav-item i { font-size: 18px; color: var(--text-muted); }
.accordion-menu .nav-item:hover, .accordion-menu .nav-item.active { background: rgba(16, 185, 129, 0.1); color: var(--primary); }
.accordion-menu .nav-item:hover i, .accordion-menu .nav-item.active i { color: var(--primary); }

.sidebar-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

.main-content {
    flex: 1;
    padding: 20px;
    padding-bottom: calc(var(--bottom-nav-height) + 20px); /* Room for mobile nav */
    transition: margin-left 0.3s ease;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.mobile-header {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    z-index: 900;
}
.mobile-page-title { font-size: 18px; font-weight: 600; margin: 0; color: var(--text-main); }
.btn-icon { background: none; border: none; font-size: 24px; color: var(--text-main); cursor: pointer; padding: 5px; display: flex; align-items: center; justify-content: center;}

.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    min-height: var(--bottom-nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 999;
    padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    flex: 1;
    padding: 10px 0;
}
.mobile-nav .nav-item i { font-size: 24px; }
.mobile-nav .nav-item.active { color: var(--primary); }
.mobile-nav .nav-item.active i { color: var(--primary); }

@media (min-width: 992px) {
    .hide-desktop { display: none !important; }
    .sidebar { left: 0; }
    .main-content { margin-left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); padding-bottom: 20px; }
    
    /* Increase desktop font sizes */
    body { font-size: 16px; }
    .accordion-menu .nav-item { font-size: 16px; padding: 12px 24px; }
    .accordion-menu .nav-item i { font-size: 20px; }
    .accordion-menu .menu-header { font-size: 12px; margin-top: 20px; }
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }
    
    .fab-container { bottom: 20px; } /* Reset FAB on desktop */
    
    .dash-layout-top {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: 24px;
        align-items: start;
    }
}

/* --- New Add Transaction Layout --- */
.tx-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 992px) {
    .tx-layout {
        grid-template-columns: 1fr;
    }
}

.tx-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.tx-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.tx-section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.tx-step-number {
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

/* Marketplace Grid */
.tx-marketplace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.tx-marketplace-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--bg-card);
}

.tx-marketplace-card:hover {
    border-color: var(--primary);
}

.tx-marketplace-card.active {
    border: 2px solid var(--primary);
    background: rgba(16, 185, 129, 0.05);
}

.tx-marketplace-card .check-icon {
    display: none;
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.tx-marketplace-card.active .check-icon {
    display: flex;
}

.tx-marketplace-logo {
    height: 30px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.tx-marketplace-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}

/* Form Inputs with Dollar Sign */
.input-with-prefix {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-prefix .prefix {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.input-with-prefix input {
    padding-left: 32px !important;
}

.required-asterisk {
    color: var(--danger);
}

.field-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Profit Summary Sidebar */
.tx-profit-sidebar {
    position: sticky;
    top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.profit-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-weight: 600;
    color: var(--text-main);
}

.profit-giant-text {
    text-align: center;
    margin-bottom: 30px;
}

.profit-giant-text .label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

.profit-giant-text .amount {
    font-size: 36px;
    font-weight: 700;
    color: var(--success);
    line-height: 1;
    margin-bottom: 8px;
    font-family: var(--font-heading);
}

.profit-giant-text .badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.profit-line-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.profit-line-item .val {
    font-weight: 600;
    color: var(--text-main);
}

.profit-divider {
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.profit-total-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

.profit-net-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 700;
    color: var(--success);
    background: rgba(16, 185, 129, 0.05);
    padding: 12px;
    border-radius: 8px;
    margin-top: 16px;
}

.tx-info-box {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    padding: 16px;
    margin-top: 24px;
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: #1e3a8a;
}

/* Ensure notes textarea is styled */
.tx-notes {
    width: 100%;
    min-height: 80px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-family: var(--font-body);
    font-size: 13px;
}

/* Color Selector Custom UI */
input[type="radio"][name="template_color"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
input[type="radio"][name="template_color"] + span {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}
input[type="radio"][name="template_color"]:checked + span {
    border: 2px solid var(--text-main);
    transform: scale(1.15);
    color: white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;
}
input[type="radio"][name="template_color"]:checked + span::after {
    content: "✓";
    font-size: 14px;
    font-weight: bold;
}
input[type="radio"][name="template_color"]:focus-visible + span {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
