@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --primary-color: #6366f1; /* Modern Indigo */
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981; /* Emerald */
    --danger-color: #ef4444; /* Rose */
    --warning-color: #f59e0b; /* Amber */
    --info-color: #06b6d4; /* Cyan */
    
    /* Sleek Dark/Light Theme Colors */
    --bg-main: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.85);
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    --sidebar-bg: #0f172a; /* Deep Slate Dark */
    --sidebar-text: #94a3b8;
    --sidebar-active: #6366f1;
    
    --border-radius: 16px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --backdrop-blur: blur(12px);
}

[data-theme="dark"] {
    --bg-main: #090d16;
    --bg-card: rgba(20, 26, 40, 0.8);
    --border-color: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: 'Cairo', 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0; /* Align to right for Arabic-first layout */
    z-index: 100;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    overflow-y: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 32px;
    padding: 0 12px;
}

.sidebar-logo i {
    color: var(--primary-color);
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
}

.sidebar-item a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sidebar-item.active a {
    background-color: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.4);
}

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 16px;
    margin-top: 16px;
}

/* Main Content Area */
.main-wrapper {
    margin-right: 260px; /* Offset for sidebar */
    width: calc(100% - 260px);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0; /* Prevent children from stretching flex item */
}

.header {
    height: 70px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: var(--backdrop-blur);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 90;
}

.header-search {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 12px;
    gap: 8px;
    width: 300px;
}

.header-search input {
    border: none;
    background: transparent;
    outline: none;
    color: var(--text-main);
    width: 100%;
    font-family: inherit;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.theme-toggle {
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 20px;
    display: flex;
    align-items: center;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 700;
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.content-body {
    padding: 32px;
    flex-grow: 1;
}

/* Glassmorphism Cards */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: var(--backdrop-blur);
    margin-bottom: 24px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #fff;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: #fff;
}
.btn-secondary:hover {
    background-color: var(--secondary-hover, var(--secondary-color));
    opacity: 0.95;
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.25);
}

.btn-success {
    background-color: var(--success-color);
    color: #fff;
}
.btn-success:hover {
    background-color: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-danger {
    background-color: var(--danger-color);
    color: #fff;
}
.btn-danger:hover {
    background-color: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Grid & Layout System */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

/* KPI Card */
.kpi-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease, border-color 0.2s ease;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.kpi-details h4 {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
}

.kpi-details .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

/* Table Style */
.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

th {
    padding: 14px 16px;
    font-weight: 700;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.01);
}

td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
}

tr:hover td {
    background-color: rgba(0, 0, 0, 0.01);
}

/* Form inputs */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-main);
}

.form-control, select, textarea {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-main);
    font-family: inherit;
    outline: none;
    font-size: 14px;
}

.form-control:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Badge */
.badge {
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
}

.badge-success {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.badge-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

/* Alert system */
.alert {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.15);
    color: #065f46;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: #991b1b;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-warning {
    background-color: rgba(245, 158, 11, 0.15);
    color: #92400e;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 30px;
    width: 500px;
    max-width: 90%;
    box-shadow: var(--shadow-lg);
}

/* Tabs */
.tab-header {
    display: flex;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 700;
    color: var(--text-muted);
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* POS specific styles */
.pos-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 24px;
    height: calc(100vh - 150px);
}

.pos-products {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    overflow-y: auto;
    padding-left: 6px;
}

.pos-cart-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.pos-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.pos-product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    text-align: center;
    position: relative;
    box-shadow: var(--shadow);
}

.pos-product-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.pos-cart-items {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

.pos-cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

/* COA Tree Styles */
.coa-tree {
    list-style: none;
    margin-right: 15px;
}

.coa-tree-item {
    margin-top: 10px;
}

.coa-node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.01);
    border: 1px solid var(--border-color);
}

/* RTL override for main content */
body.rtl {
    direction: rtl;
}

body.rtl .sidebar {
    right: 0;
    left: auto;
}

body.rtl .main-wrapper {
    margin-right: 260px;
    margin-left: 0;
}

body.rtl th, body.rtl td {
    text-align: right;
}

/* Sidebar Menu Category Grouping & Collapsible List */
.sidebar-category-wrapper {
    margin-bottom: 8px;
}

.sidebar-category-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b; /* Sleek muted color */
    text-transform: uppercase;
    transition: background-color 0.2s, color 0.2s;
    margin: 10px 0 4px 0;
}

.sidebar-category-header:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: #fff;
}

.sidebar-category-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-category-header-title i {
    font-size: 14px;
    color: var(--primary-color);
    opacity: 0.8;
}

.sidebar-category-header-arrow {
    font-size: 16px;
    transition: transform 0.3s ease;
    color: #475569;
}

.sidebar-subcategory-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Collapsed States */
.sidebar-category-wrapper.collapsed .sidebar-category-header-arrow {
    transform: rotate(90deg); /* Point left in RTL */
}

/* Indent sub-items slightly for a clean hierarchy */
.sidebar-subcategory-list .sidebar-item a {
    padding-right: 28px; /* Indent sub items in RTL */
}

/* POS Selling Mode Full-screen layout controls */
body.pos-active {
    overflow: hidden;
}

body.pos-active .header {
    display: none;
}

body.pos-active .pos-page-header {
    display: none;
}

body.pos-active .tab-header {
    display: none;
}

body.pos-active .main-wrapper {
    min-height: 100vh;
    height: 100vh;
}

body.pos-active .content-body {
    padding: 12px !important;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.pos-active .content-body > .alert {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1100;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    margin-bottom: 0;
    animation: posAlertSlideIn 0.3s ease forwards;
}

@keyframes posAlertSlideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

body.pos-active .pos-container {
    height: 100% !important;
    margin: 0 !important;
    flex-grow: 1;
}

/* Custom interactive chart bars styling */
.chart-bar {
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), fill-opacity 0.2s ease, fill 0.2s ease;
    cursor: pointer;
}
.chart-bar:hover {
    fill-opacity: 1 !important;
    transform: scaleY(1.03);
    transform-origin: bottom;
}

/* Fix date input format direction for RTL */
input[type="date"] {
    direction: ltr !important;
    text-align: right !important;
    font-family: inherit;
}

/* ─── Select / Dropdown Fix ─── */
/* 1. تطبيق ألوان الثيم على جميع عناصر select */
select {
    background-color: var(--bg-main) !important;
    color: var(--text-main) !important;
}

/* 2. لضمان ظهور الخيارات بشكل صحيح في الوضع الداكن */
select option {
    background-color: var(--bg-main);
    color: var(--text-main);
}

[data-theme="dark"] select,
[data-theme="dark"] select option {
    background-color: #141a28 !important;
    color: #f8fafc !important;
}

/* 3. Choices.js RTL & Theming Fixes */
.choices__inner {
    background: var(--bg-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 10px !important;
    padding-right: 14px !important;
    padding-left: 30px !important;
    color: var(--text-main) !important;
    min-height: 42px !important;
}

.choices[data-type*='select-one']::after {
    left: 11.5px !important;
    right: auto !important;
    border-color: var(--text-muted) transparent transparent !important;
}

.choices[data-theme*='dark'] .choices__inner,
[data-theme="dark"] .choices__inner {
    background: #141a28 !important;
    border-color: #1e293b !important;
    color: #f8fafc !important;
}

.choices__list--dropdown {
    background: var(--bg-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 10px !important;
    color: var(--text-main) !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
    z-index: 1050 !important;
}

[data-theme="dark"] .choices__list--dropdown {
    background: #141a28 !important;
    border-color: #1e293b !important;
    color: #f8fafc !important;
}

.choices__list--dropdown .choices__item {
    text-align: right !important;
    color: var(--text-main) !important;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted {
    background: rgba(99,102,241,0.15) !important;
    color: var(--primary-color) !important;
}

.choices__input {
    background: var(--bg-main) !important;
    color: var(--text-main) !important;
}

[data-theme="dark"] .choices__input {
    background: #141a28 !important;
    color: #f8fafc !important;
}

/* 4. Standard select arrow override (لا نستخدم appearance:none لأنه يخفي السهم) */
select.form-control {
    padding-left: 28px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236366f1' d='M1 1l5 5 5-5'/></svg>");
    background-repeat: no-repeat;
    background-position: left 10px center;
    background-size: 12px;
}

/* ─── Sidebar Toggle & Layout Expansion ─── */
.sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease, border-color 0.3s ease;
}

.main-wrapper {
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar {
    transform: translateX(260px);
}

body.sidebar-collapsed .main-wrapper {
    margin-right: 0 !important;
    width: 100% !important;
}

body.ltr.sidebar-collapsed .sidebar {
    transform: translateX(-260px);
}

body.ltr.sidebar-collapsed .main-wrapper {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
}

/* Breadcrumbs Bar Styling */
.breadcrumbs-bar {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    width: fit-content;
}

.breadcrumbs-bar a {
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s ease;
}

.breadcrumbs-bar a:hover {
    color: var(--primary-hover);
    text-decoration: none;
}

.breadcrumbs-bar span {
    color: var(--text-main);
    font-weight: 600;
}
