/**
 * CRM Gospodarul - Custom Styles
 */

body {
    font-family: 'Nunito', sans-serif;
}

:root {
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 60px;
    --primary-color: #387698;
    --accent-color: #f3b544;
    --sidebar-bg: #0d1b2a;
    --sidebar-text: #a0b8c8;
    --sidebar-active: #ffffff;

    /* Muted Bootstrap color overrides */
    --bs-primary: #3a7fa6;
    --bs-primary-rgb: 58, 127, 166;
    --bs-success: #4a9e72;
    --bs-success-rgb: 74, 158, 114;
    --bs-warning: #d4a33a;
    --bs-warning-rgb: 212, 163, 58;
    --bs-danger: #c75454;
    --bs-danger-rgb: 199, 84, 84;
    --bs-info: #5a9fc2;
    --bs-info-rgb: 90, 159, 194;
    --bs-secondary: #6d7a88;
    --bs-secondary-rgb: 109, 122, 136;
}

/* Muted button styles */
.btn-primary {
    --bs-btn-bg: #3a7fa6;
    --bs-btn-border-color: #3a7fa6;
    --bs-btn-hover-bg: #30698a;
    --bs-btn-hover-border-color: #30698a;
    --bs-btn-active-bg: #295b78;
    --bs-btn-active-border-color: #295b78;
}
.btn-success {
    --bs-btn-bg: #4a9e72;
    --bs-btn-border-color: #4a9e72;
    --bs-btn-hover-bg: #3e8861;
    --bs-btn-hover-border-color: #3e8861;
    --bs-btn-active-bg: #367755;
    --bs-btn-active-border-color: #367755;
}
.btn-warning {
    --bs-btn-bg: #d4a33a;
    --bs-btn-border-color: #d4a33a;
    --bs-btn-hover-bg: #be9132;
    --bs-btn-hover-border-color: #be9132;
    --bs-btn-active-bg: #a9812c;
    --bs-btn-active-border-color: #a9812c;
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-color: #fff;
}
.btn-danger {
    --bs-btn-bg: #c75454;
    --bs-btn-border-color: #c75454;
    --bs-btn-hover-bg: #b04848;
    --bs-btn-hover-border-color: #b04848;
    --bs-btn-active-bg: #9c3f3f;
    --bs-btn-active-border-color: #9c3f3f;
}
.btn-info {
    --bs-btn-bg: #5a9fc2;
    --bs-btn-border-color: #5a9fc2;
    --bs-btn-hover-bg: #4d8aaa;
    --bs-btn-hover-border-color: #4d8aaa;
    --bs-btn-active-bg: #437996;
    --bs-btn-active-border-color: #437996;
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-color: #fff;
}
.btn-outline-primary {
    --bs-btn-color: #3a7fa6;
    --bs-btn-border-color: #3a7fa6;
    --bs-btn-hover-bg: #3a7fa6;
    --bs-btn-hover-border-color: #3a7fa6;
    --bs-btn-active-bg: #30698a;
    --bs-btn-active-border-color: #30698a;
}
.btn-outline-success {
    --bs-btn-color: #4a9e72;
    --bs-btn-border-color: #4a9e72;
    --bs-btn-hover-bg: #4a9e72;
    --bs-btn-hover-border-color: #4a9e72;
    --bs-btn-active-bg: #3e8861;
    --bs-btn-active-border-color: #3e8861;
}
.btn-outline-warning {
    --bs-btn-color: #d4a33a;
    --bs-btn-border-color: #d4a33a;
    --bs-btn-hover-bg: #d4a33a;
    --bs-btn-hover-border-color: #d4a33a;
    --bs-btn-active-bg: #be9132;
    --bs-btn-active-border-color: #be9132;
}
.btn-outline-danger {
    --bs-btn-color: #c75454;
    --bs-btn-border-color: #c75454;
    --bs-btn-hover-bg: #c75454;
    --bs-btn-hover-border-color: #c75454;
    --bs-btn-active-bg: #b04848;
    --bs-btn-active-border-color: #b04848;
}
.btn-outline-info {
    --bs-btn-color: #5a9fc2;
    --bs-btn-border-color: #5a9fc2;
    --bs-btn-hover-bg: #5a9fc2;
    --bs-btn-hover-border-color: #5a9fc2;
    --bs-btn-active-bg: #4d8aaa;
    --bs-btn-active-border-color: #4d8aaa;
}

/* Ensure white text on warning/info badges */
.badge.bg-warning { color: #fff !important; }
.badge.bg-info { color: #fff !important; }

/* Link color */
a { color: #3a7fa6; }
a:hover { color: #30698a; }

/* Layout */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.content-page {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

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

.content {
    flex: 1;
    padding: 1.5rem;
    background-color: #f5f7fb;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.3s ease;
    overflow-y: auto;
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-logo {
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo .logo {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.sidebar-logo .logo img {
    width: 100%;
    max-height: 90px;
    object-fit: contain;
}

.sidebar-logo .logo-sm {
    display: none;
}

.sidebar-collapsed .sidebar-logo .logo-lg {
    display: none;
}

.sidebar-collapsed .sidebar-logo .logo-sm {
    display: block;
}

.sidebar-menu {
    padding: 1rem 0;
}

.side-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-title {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1.5rem 0.5rem;
    margin-top: 0.5rem;
}

.sidebar-collapsed .menu-title {
    display: none;
}

.menu-item {
    margin: 2px 0;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 0.625rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.menu-link:hover {
    color: var(--sidebar-active);
    background: rgba(255, 255, 255, 0.05);
}

.menu-item.active .menu-link {
    color: var(--sidebar-active);
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--accent-color);
}

.menu-link i {
    font-size: 1.25rem;
    width: 24px;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.sidebar-collapsed .menu-link span {
    display: none;
}

.sidebar-collapsed .menu-link {
    justify-content: center;
    padding: 0.75rem;
}

.sidebar-collapsed .menu-link i {
    margin-right: 0;
}

/* Topbar */
.navbar-custom {
    background: #fff;
    border-bottom: 1px solid #e5e9f2;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.button-toggle-menu {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6c757d;
    cursor: pointer;
    padding: 0.25rem;
}

.topbar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
}

.topbar-menu .nav-link {
    color: #6c757d;
    padding: 0.5rem;
}

.topbar-menu .nav-link:hover {
    color: var(--primary-color);
}

/* Avatar */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 500;
}

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.875rem;
}

.avatar-md {
    width: 40px;
    height: 40px;
    font-size: 1rem;
}

.avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 1.25rem;
}

/* Footer */
.footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e5e9f2;
    background: #fff;
    font-size: 0.875rem;
    color: #6c757d;
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 0 35px 0 rgba(154, 161, 171, 0.15);
    margin-bottom: 1.5rem;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid #e5e9f2;
    padding: 1rem 1.25rem;
}

.card-title {
    margin-bottom: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* Stats Cards */
.stats-card {
    position: relative;
    overflow: hidden;
}

.stats-card .stats-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    opacity: 0.15;
}

/* Tables */
.table {
    margin-bottom: 0;
}

.table thead th {
    border-top: none;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
    background: #f8f9fa;
}

.table tbody td {
    vertical-align: middle;
}

/* DataTables customization */
.dataTables_wrapper {
    padding: 0;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 1rem;
}

/* Buttons */
.btn {
    font-weight: 500;
    padding: 0.5rem 1rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Forms */
.form-label {
    font-weight: 500;
    margin-bottom: 0.375rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(56, 118, 152, 0.25);
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

/* Breadcrumb */
.breadcrumb {
    margin-bottom: 0;
    background: transparent;
    padding: 0;
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.375em 0.65em;
}

/* Dropdowns */
.dropdown-menu {
    border: none;
    box-shadow: 0 0 35px 0 rgba(154, 161, 171, 0.15);
}

.dropdown-header {
    font-weight: 600;
    color: #495057;
}

.dropdown-item {
    padding: 0.5rem 1rem;
}

.dropdown-item:hover {
    background-color: #f8f9fa;
}

/* Kanban Board */
.kanban-board {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
}

.kanban-column {
    min-width: 280px;
    max-width: 280px;
    background: #f8f9fa;
    border-radius: 0.5rem;
    padding: 1rem;
}

.kanban-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid;
}

.kanban-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.kanban-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
}

.kanban-cards {
    min-height: 200px;
}

.kanban-card {
    background: #fff;
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.kanban-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.kanban-card-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.kanban-card-meta {
    font-size: 0.75rem;
    color: #6c757d;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #387698 0%, #0d1b2a 100%);
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo img {
    max-height: 80px;
}

/* Alerts */
.alert {
    border: none;
    border-radius: 0.375rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state i,
.empty-state .empty-state-icon {
    font-size: 4rem;
    opacity: 0.2;
    margin-bottom: 1rem;
    display: block;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #495057;
}

.empty-state-description {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 1.5rem;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

/* Toast Notifications */
.toast-container .toast {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: #fff;
    min-width: 280px;
    margin-bottom: 0.5rem;
}

.toast-container .toast-body {
    padding: 0.75rem 1rem;
}

/* Loading Skeletons */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 0.25rem;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text { height: 1em; margin-bottom: 0.5rem; }
.skeleton-row { display: flex; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid #f0f0f0; }
.skeleton-cell { height: 1rem; flex: 1; }
.skeleton-badge { width: 60px; height: 1.5rem; border-radius: 0.25rem; }

/* Order Timeline */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; left: 0.6875rem; top: 0; bottom: 0; width: 2px; background: #e5e9f2; }
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot { position: absolute; left: -2rem; width: 1.5rem; height: 1.5rem; border-radius: 50%; display: flex; align-items: center; justify-content: center; z-index: 1; }
.timeline-dot i { font-size: 0.7rem; color: #fff; }
.timeline-content { padding-left: 0.5rem; }

/* Global Search */
#globalSearchWrap .input-group { border-radius: 0.5rem; overflow: hidden; }
#globalSearchWrap .input-group-text { background: #f5f7fb; border-color: #e5e9f2; }
#globalSearchWrap .form-control { background: #f5f7fb; border-color: #e5e9f2; }
#globalSearchWrap .form-control:focus { background: #fff; }
#globalSearchWrap .dropdown-menu { display: none; border: none; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); border-radius: 0.5rem; margin-top: 0.25rem; }
#globalSearchWrap .dropdown-menu.show { display: block; }
.search-group-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6c757d; padding: 0.5rem 1rem 0.25rem; font-weight: 600; background: #f8f9fa; }
.search-result-item { padding: 0.5rem 1rem; display: flex; align-items: center; gap: 0.75rem; cursor: pointer; border-bottom: 1px solid #f0f0f0; color: #333; }
.search-result-item:hover { background: #f8f9fa; }
.search-result-item .search-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.875rem; }
.search-result-item .search-meta { font-size: 0.75rem; color: #6c757d; }

/* Notifications */
.notif-item { padding: 0.75rem 1rem; display: flex; gap: 0.75rem; cursor: pointer; border-bottom: 1px solid #f0f0f0; transition: background 0.2s; color: #333; }
.notif-item:hover { background: #f8f9fa; }
.notif-item .notif-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.875rem; }
.notif-item .notif-title { font-weight: 500; font-size: 0.875rem; }
.notif-item .notif-desc { font-size: 0.75rem; color: #6c757d; }

/* Bulk Action Bar */
.bulk-action-bar { border-radius: 0.75rem; border: 1px solid #e5e9f2; }

/* Recent Items in Sidebar */
.sidebar-recent { border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: 0.5rem; margin-top: 0.5rem; }
.sidebar-recent .menu-title { font-size: 0.7rem; }
.sidebar-recent .menu-link { font-size: 0.8125rem; padding: 0.4rem 1.5rem; }
.sidebar-collapsed .sidebar-recent .menu-link span { display: none; }

/* Inline Editing */
.inline-edit-stock { cursor: pointer; border-bottom: 1px dashed #adb5bd; }
.inline-edit-stock:hover { color: var(--primary-color); }

/* Profit Color Coding */
.profit-good { color: #4a9e72; }
.profit-low { color: #d4a33a; }
.profit-negative { color: #c75454; }
.profit-unknown { color: #adb5bd; }

/* Responsive — Tablet & below */
@media (max-width: 991.98px) {
    .sidebar {
        height: auto;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-logo {
        flex-shrink: 0;
    }

    .sidebar-menu {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .content-page {
        margin-left: 0;
        overflow-x: hidden;
    }

    .sidebar-collapsed .content-page {
        margin-left: 0;
    }

    /* Tighter topbar on tablet */
    .topbar {
        padding: 0 1rem;
    }
}

/* Sidebar mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
}

.sidebar-open .sidebar-overlay {
    display: block;
}

/* Responsive — Phone */
@media (max-width: 767.98px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .content {
        padding: 0.75rem;
    }

    .topbar {
        padding: 0 0.75rem;
    }

    /* Prevent card body overflow */
    .card-body {
        overflow-x: auto;
    }

    /* Smaller sidebar logo on phone */
    .sidebar-logo {
        height: 80px;
    }

    .sidebar-logo .logo img {
        max-height: 60px;
    }

    /* Tighter card spacing */
    .card {
        margin-bottom: 1rem;
    }
}

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

.cursor-pointer {
    cursor: pointer;
}

.hover-shadow:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ===== Orders Page Responsive ===== */

/* DataTables Responsive child-row styling */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control::before {
    background-color: var(--primary-color, #387698);
}

table.dataTable > tbody > tr.child ul.dtr-details {
    width: 100%;
}

table.dataTable > tbody > tr.child ul.dtr-details > li {
    border-bottom: 1px solid #eee;
    padding: 0.5em 0;
}

table.dataTable > tbody > tr.child .dtr-title {
    font-weight: 600;
    min-width: 100px;
}

/* Phone breakpoint — orders & tables */
@media (max-width: 575.98px) {
    /* Smaller table font */
    .dataTables_wrapper {
        font-size: 0.8125rem;
    }

    .table {
        font-size: 0.8125rem;
    }

    /* Compact action buttons */
    .table .btn-group-sm .btn {
        padding: 0.15rem 0.35rem;
        font-size: 0.75rem;
    }

    /* Stack DT length + filter controls */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        float: none !important;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Centered pagination */
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        float: none !important;
        margin-top: 0.75rem;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .dataTables_wrapper .dataTables_info {
        text-align: center !important;
        float: none !important;
        font-size: 0.75rem;
    }

    /* Full-width header buttons on mobile */
    .page-header .d-flex.gap-2 {
        width: 100%;
    }

    .page-header .d-flex.gap-2 .btn {
        flex: 1;
    }

    /* Compact filter labels */
    #filtersCard .form-label {
        font-size: 0.75rem;
        margin-bottom: 0.2rem;
    }

    /* Nav tabs scroll horizontally if needed */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Tablet breakpoint — tables */
@media (min-width: 576px) and (max-width: 991.98px) {
    .table {
        font-size: 0.8125rem;
    }

    .dataTables_wrapper {
        font-size: 0.875rem;
    }
}

