:root {
    --erp-sidebar-width: 250px;
    --erp-sidebar-bg: #1e293b;
    --erp-sidebar-hover: #334155;
    --erp-primary: #0f766e;
    --erp-primary-dark: #0d9488;
    --erp-accent: #0ea5e9;
    --erp-body-bg: #f1f5f9;
    --erp-card-border: #e2e8f0;
    --erp-text: #1e293b;
    --erp-muted: #64748b;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--erp-body-bg);
    color: var(--erp-text);
    min-height: 100vh;
}

/* ---------- Auth ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(14, 165, 233, 0.85)),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
    overflow: hidden;
}

.auth-card .auth-header {
    background: #0f172a;
    color: #fff;
    padding: 1.75rem 1.5rem 1.25rem;
    text-align: center;
}

.auth-card .auth-header .brand-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: var(--erp-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

.auth-card .auth-body {
    padding: 1.75rem 1.5rem;
}

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

.sidebar {
    width: var(--erp-sidebar-width);
    background: var(--erp-sidebar-bg);
    color: #cbd5e1;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    overflow-x: hidden;
    overflow-y: auto;
}

.sidebar-brand-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-right: 0.5rem;
    min-height: 64px;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    text-decoration: none;
    min-width: 0;
    flex: 1;
}

.sidebar-brand:hover { color: #fff; }

.sidebar-brand .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--erp-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-text {
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.2;
    white-space: nowrap;
}

.sidebar-brand .brand-text small {
    display: block;
    font-weight: 400;
    font-size: 0.7rem;
    color: #94a3b8;
}

.sidebar-close-btn {
    border: 0;
    background: transparent;
    color: #94a3b8;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: none;
    align-items: center;
    justify-content: center;
}

.sidebar-close-btn:hover {
    background: var(--erp-sidebar-hover);
    color: #fff;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.85rem 0.75rem;
    display: flex;
    flex-direction: column;
}

.sidebar-nav .nav-link {
    color: #94a3b8;
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.925rem;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    white-space: nowrap;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    background: var(--erp-sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link i {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0.5rem 0.35rem;
}

.sidebar-logout-form {
    margin: 0;
    width: 100%;
}

.sidebar-logout-form .logout-link {
    cursor: pointer;
}

.main-content {
    margin-left: var(--erp-sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    position: relative;
    z-index: 1;
}

.top-navbar {
    background: #fff;
    border-bottom: 1px solid var(--erp-card-border);
    padding: 0.65rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 1050; /* above sidebar so toggle never hides */
}

/* Always visible hamburger */
.btn-sidebar-toggle {
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #0f172a;
    border-radius: 8px;
    flex-shrink: 0;
    position: relative;
    z-index: 1060;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.btn-sidebar-toggle:hover,
.btn-sidebar-toggle:focus {
    background: #f1f5f9;
    color: var(--erp-primary);
    border-color: #94a3b8;
}

.btn-sidebar-toggle i {
    font-size: 1.35rem;
    line-height: 1;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #0f766e;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.page-content {
    padding: 1.25rem;
    flex: 1;
}

.app-footer {
    padding: 0.85rem 1.25rem;
    background: #fff;
    border-top: 1px solid var(--erp-card-border);
    color: var(--erp-muted);
    font-size: 0.85rem;
}

.app-footer a {
    color: var(--erp-primary);
    text-decoration: none;
    font-weight: 600;
}

.app-footer a:hover {
    text-decoration: underline;
}

.page-header {
    margin-bottom: 1.25rem;
}

.page-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.breadcrumb {
    margin-bottom: 0;
    background: transparent;
    padding: 0;
    font-size: 0.85rem;
}

.erp-card {
    background: #fff;
    border: 1px solid var(--erp-card-border);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.erp-card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--erp-card-border);
    padding: 0.9rem 1.15rem;
    font-weight: 600;
}

.erp-card .card-body {
    padding: 1.15rem;
}

.stat-card {
    border: 1px solid var(--erp-card-border);
    border-radius: 10px;
    background: #fff;
    padding: 1.15rem;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    color: #fff;
    flex-shrink: 0;
}

.stat-card .stat-label {
    color: var(--erp-muted);
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.bg-stat-teal { background: #0f766e; }
.bg-stat-blue { background: #0284c7; }
.bg-stat-indigo { background: #4f46e5; }
.bg-stat-green { background: #16a34a; }
.bg-stat-slate { background: #475569; }
.bg-stat-amber { background: #d97706; }

.btn-primary {
    --bs-btn-bg: var(--erp-primary);
    --bs-btn-border-color: var(--erp-primary);
    --bs-btn-hover-bg: var(--erp-primary-dark);
    --bs-btn-hover-border-color: var(--erp-primary-dark);
    --bs-btn-active-bg: var(--erp-primary-dark);
    --bs-btn-active-border-color: var(--erp-primary-dark);
}

.table-actions .btn {
    padding: 0.2rem 0.45rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
}

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

/*
 * Desktop: open by default.
 * body.sidebar-hidden => fully hide sidebar (toggle never overlaps).
 */
@media (min-width: 992px) {
    body.sidebar-hidden .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-hidden .main-content {
        margin-left: 0;
    }

    body.sidebar-hidden .sidebar-overlay {
        display: none !important;
    }
}

/* Mobile / tablet: off-canvas */
@media (max-width: 991.98px) {
    .sidebar {
        width: min(var(--erp-sidebar-width), 86vw);
        transform: translateX(-100%);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-close-btn {
        display: inline-flex;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .page-content {
        padding: 1rem;
    }

    .stat-card {
        padding: 0.9rem;
    }

    .stat-card .stat-value {
        font-size: 1.25rem;
    }

    .top-navbar {
        padding: 0.55rem 0.75rem;
    }
}

@media (max-width: 575.98px) {
    .page-content {
        padding: 0.75rem;
    }

    .erp-card .card-body {
        padding: 0.9rem;
    }
}

/* DataTables — only table area scrolls; length/filter/info/paginate stay fixed */
div.dataTables_wrapper {
    width: 100%;
    overflow: visible;
}

div.dataTables_wrapper div.dataTables_length,
div.dataTables_wrapper div.dataTables_filter,
div.dataTables_wrapper div.dataTables_info,
div.dataTables_wrapper div.dataTables_paginate {
    float: none;
    padding: 0.5rem 0;
}

div.dataTables_wrapper .row {
    margin-left: 0;
    margin-right: 0;
}

/* Scroll container sits between header controls and pagination */
div.dataTables_wrapper div.dataTables_scroll {
    clear: both;
    margin: 0.25rem 0 0.5rem;
}

div.dataTables_wrapper div.dataTables_scrollBody {
    border-bottom: 1px solid #e2e8f0;
}

div.dataTables_wrapper div.dataTables_filter input,
div.dataTables_wrapper div.dataTables_length select {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background-color: #fff;
    color: #1e293b;
    height: 36px;
    line-height: 1.2;
    vertical-align: middle;
}

/* Length dropdown: enough width + right padding so arrow never overlaps value */
div.dataTables_wrapper div.dataTables_length select {
    min-width: 72px;
    width: auto;
    padding: 0.35rem 2rem 0.35rem 0.65rem;
    margin: 0 0.35rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23475569' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
    background-size: 12px 10px;
}

div.dataTables_wrapper div.dataTables_filter input {
    min-width: 180px;
    padding: 0.35rem 0.75rem;
    margin-left: 0.35rem;
}

/* App-wide select fix (forms, filters, reports) */
select.form-select {
    min-height: 38px;
    padding-right: 2.25rem;
    background-position: right 0.75rem center;
}

/* Select2 searchable dropdowns — match ERP form controls */
select.form-select.select2-hidden-accessible,
select.form-control.select2-hidden-accessible {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-height: 0 !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    clip: rect(0 0 0 0) !important;
    overflow: hidden !important;
}

.select2-container--bootstrap-5 {
    width: 100% !important;
}

.select2-container--bootstrap-5 .select2-selection--single {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    min-height: 38px;
    padding: 0.25rem 2.25rem 0.25rem 0.75rem !important;
    border-color: #ced4da;
    text-align: left !important;
    background-position: right 0.75rem center !important;
    background-repeat: no-repeat !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    display: block !important;
    float: none !important;
    width: 100% !important;
    max-width: 100%;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1.5 !important;
    text-align: left !important;
    color: var(--erp-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
    display: none !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
    float: none !important;
    margin: 0 0.35rem 0 0 !important;
    order: -1;
}

.select2-container--bootstrap-5.select2--small .select2-selection--single,
.select2-container--bootstrap-5 .select2-selection--single.select2--small {
    min-height: 31px;
    font-size: 0.875rem;
    padding-top: 0.15rem !important;
    padding-bottom: 0.15rem !important;
}

.select2-container--bootstrap-5 .select2-dropdown {
    border-color: #ced4da;
    z-index: 2000;
    text-align: left;
}

.select2-container--bootstrap-5 .select2-results__option {
    text-align: left;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    border-color: #ced4da;
    padding: 0.4rem 0.65rem;
    text-align: left;
}

.order-side-field .select2-container {
    width: 100% !important;
    max-width: 100%;
}

table.dataTable {
    width: 100% !important;
    margin: 0 !important;
}

table.dataTable thead th {
    white-space: nowrap;
    vertical-align: middle;
}

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

/* Bottom bar: info left, pagination right — never inside horizontal scroll */
div.dataTables_wrapper .dataTables_info {
    padding-top: 0.75rem !important;
}

div.dataTables_wrapper .dataTables_paginate {
    padding-top: 0.5rem !important;
}

@media (max-width: 767.98px) {
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        text-align: left !important;
    }
}

/* Sales Order — left items / right fields */
.order-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 0.85rem;
    align-items: start;
    max-width: 100%;
}

.order-layout-left,
.order-layout-right {
    min-width: 0;
    max-width: 100%;
}

.order-form-card .form-label,
.order-side-field .form-label {
    margin-bottom: 0.15rem;
    font-size: 0.78rem;
}

.order-side-fields {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.order-side-field .form-control,
.order-side-field .form-select {
    width: 100%;
    max-width: 100%;
}

.order-items-card .card-header,
.order-form-card .card-header {
    font-size: 0.9rem;
}

.order-items-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

#itemsGrid {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
    margin: 0;
}

#itemsGrid th,
#itemsGrid td {
    padding: 0.3rem 0.3rem;
    font-size: 0.78rem;
    vertical-align: middle;
}

/* Keep Item Name compact — no huge empty gap */
#itemsGrid .col-no { width: 36px; }
#itemsGrid .col-name { width: 30%; }
#itemsGrid .col-unit { width: 12%; }
#itemsGrid .col-rate { width: 18%; }
#itemsGrid .col-qty { width: 18%; }
#itemsGrid .col-amt { width: 18%; }

/* Daywise Stock items grid */
#daywiseItemsGrid {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
    margin: 0;
}

#daywiseItemsGrid th,
#daywiseItemsGrid td {
    padding: 0.3rem 0.3rem;
    font-size: 0.78rem;
    vertical-align: middle;
}

#daywiseItemsGrid .col-no { width: 36px; }
#daywiseItemsGrid .col-name { width: 34%; }
#daywiseItemsGrid .col-unit { width: 14%; }
#daywiseItemsGrid .col-stock { width: 22%; }
#daywiseItemsGrid .col-qty { width: 22%; }

#daywiseItemsGrid .form-control {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    font-size: 0.78rem;
}

#itemsGrid td:nth-child(2) {
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
}

#itemsGrid .form-control {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    font-size: 0.78rem;
}

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