/**
 * Awada Marina ERP - Main Stylesheet
 * Light & Dark Mode Support
 */

:root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #818cf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --radius: 12px;
    --transition: all 0.3s ease;
}

/* Light Theme (Default) */
[data-theme="light"], :root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-topbar: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --input-bg: #ffffff;
    --table-stripe: #f8fafc;
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-active: rgba(79, 70, 229, 0.3);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0f172a;
    --bg-topbar: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #ffffff;
    --border-color: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
    --input-bg: #0f172a;
    --table-stripe: #1a2332;
    --sidebar-hover: rgba(255,255,255,0.05);
    --sidebar-active: rgba(79, 70, 229, 0.4);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    transition: var(--transition);
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
}

.sidebar-brand .brand-text {
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.2;
}

.sidebar-brand .brand-sub {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    scrollbar-width: thin;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.sidebar .nav-section {
    padding: 0.5rem 1.25rem 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(203, 213, 225, 0.55);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 0.875rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
    margin: 1px 0;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-link.active {
    background: var(--sidebar-active);
    color: var(--text-sidebar-active);
    border-left-color: var(--primary-light);
    font-weight: 500;
}

.nav-link i { font-size: 1.1rem; width: 20px; text-align: center; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow);
}

.page-content {
    flex: 1;
    padding: 1.5rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-body { padding: 1.25rem; }

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.net-profit-hero {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.06), rgba(16, 185, 129, 0.05));
}

.net-profit-value {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.net-profit-chart-wrap {
    background: rgba(255, 255, 255, 0.45);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 1rem 0.5rem;
    min-height: 180px;
}

[data-theme="dark"] .net-profit-chart-wrap {
    background: rgba(0, 0, 0, 0.15);
}

.dashboard-details-collapsed {
    display: none !important;
}

.bg-primary-soft { background: rgba(79, 70, 229, 0.12); color: var(--primary); }
.bg-success-soft { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.bg-warning-soft { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.bg-danger-soft { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.bg-info-soft { background: rgba(6, 182, 212, 0.12); color: var(--info); }

/* Forms */
.form-control, .form-select {
    background: var(--input-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    background: var(--input-bg);
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.input-group-text {
    background: var(--bg-body);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

/* Tables */
.table {
    color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-striped-bg: var(--table-stripe);
    --bs-table-hover-bg: var(--table-stripe);
    --bs-table-border-color: var(--border-color);
}

.table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    white-space: nowrap;
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* Theme Toggle */
.theme-toggle {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 4px;
    display: flex;
    cursor: pointer;
    position: relative;
    width: 56px;
    height: 30px;
}

.theme-toggle .toggle-option {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    z-index: 1;
    transition: var(--transition);
    color: var(--text-muted);
}

.theme-toggle .toggle-slider {
    position: absolute;
    width: 22px;
    height: 22px;
    background: var(--primary);
    border-radius: 50%;
    top: 4px;
    left: 4px;
    transition: var(--transition);
}

[data-theme="dark"] .theme-toggle .toggle-slider {
    left: 30px;
}

.currency-toggle .currency-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Notifications */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #4f46e5 50%, #7c3aed 100%);
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    color: white;
    font-size: 1.75rem;
}

/* POS Styles */
.pos-container { display: grid; grid-template-columns: 1fr 400px; gap: 1rem; height: calc(100vh - var(--topbar-height) - 3rem); }
.pos-products { overflow-y: auto; }
.pos-cart { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); display: flex; flex-direction: column; }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 1rem; }
.pos-cart-footer { border-top: 1px solid var(--border-color); padding: 1rem; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}
.product-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.product-card .product-name { font-size: 0.8rem; font-weight: 500; margin-top: 0.25rem; }
.product-card .product-thumb {
    width: 100%;
    height: 88px;
    border-radius: 8px;
    background: var(--table-stripe);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 0.35rem;
}
.product-card .product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.product-card .product-thumb i {
    font-size: 1.75rem;
    color: var(--text-muted);
}
.cart-line .cart-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--table-stripe);
}
.product-list-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--table-stripe);
}
.product-view-image {
    max-height: 180px;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
}
.product-card .product-price { font-size: 0.85rem; color: var(--primary); font-weight: 600; }

/* Barcode Scanner */
.scanner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.scanner-box {
    width: 90%;
    max-width: 500px;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}
#qr-reader { width: 100%; }

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
}

/* Breadcrumb override */
.breadcrumb { margin: 0; font-size: 0.85rem; }
.breadcrumb-item a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb-item.active { color: var(--text-muted); }

/* Modal dark mode */
.modal-content {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.modal-header, .modal-footer { border-color: var(--border-color); }
.btn-close { filter: var(--bs-btn-close-filter, none); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* Dropdown */
.dropdown-menu {
    background: var(--bg-card);
    border-color: var(--border-color);
    box-shadow: var(--shadow-lg);
}
.dropdown-item { color: var(--text-primary); }
.dropdown-item:hover { background: var(--table-stripe); color: var(--text-primary); }
.dropdown-divider { border-color: var(--border-color); }

/* Alert */
.alert { border-radius: 10px; border: none; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; }
    .pos-container { grid-template-columns: 1fr; height: auto; }
}

@media (max-width: 575.98px) {
    .page-content { padding: 1rem; }
    .stat-card .stat-value { font-size: 1.25rem; }
    .page-title { font-size: 1.25rem; }
}

/* Print */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.3s ease; }

/* DataTables dark mode */
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* DataTables empty placeholder rows (colspan expanded before init) */
table.datatable tbody tr.datatable-empty-row td:first-child {
    text-align: center;
}
table.datatable tbody tr.datatable-empty-row td.datatable-empty-pad {
    display: none;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }

/* BI Dashboard */
.bi-insight { border: 1px solid var(--border-color); transition: var(--transition); }
.bi-insight:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.bi-insight-success { border-left: 3px solid var(--success); }
.bi-insight-warning { border-left: 3px solid var(--warning); }
.bi-insight-danger { border-left: 3px solid var(--danger); }
.bi-insight-info { border-left: 3px solid var(--info); }
.bi-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.hover-shadow { transition: var(--transition); }
.hover-shadow:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

/* Help Chatbot */
.erp-help-chat {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1080;
}
.erp-help-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 1.4rem;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: var(--transition);
}
.erp-help-chat-toggle:hover {
    transform: scale(1.05);
    color: #fff;
}
.erp-help-chat-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: min(380px, calc(100vw - 2rem));
    height: 520px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.erp-help-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
}
.erp-help-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.erp-chat-msg-user { align-self: flex-end; max-width: 88%; }
.erp-chat-msg-bot { align-self: flex-start; max-width: 95%; }
.erp-chat-bubble {
    padding: 0.65rem 0.85rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.5;
}
.erp-chat-msg-user .erp-chat-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.erp-chat-msg-bot .erp-chat-bubble {
    background: var(--table-stripe);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}
.erp-chat-meta {
    margin-top: 0.35rem;
    font-size: 0.75rem;
}
.erp-chat-link {
    display: inline-block;
    margin-right: 0.5rem;
    margin-top: 0.25rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.erp-chat-link:hover { text-decoration: underline; }
.erp-help-chat-suggestions {
    padding: 0 0.75rem 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    max-height: 90px;
    overflow-y: auto;
}
.erp-chat-chip {
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    cursor: pointer;
}
.erp-chat-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.erp-help-chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
}
.erp-help-chat-form .form-control { flex: 1; }

@media print {
    .erp-help-chat { display: none !important; }
}
