/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
* { font-family: 'Inter', sans-serif; box-sizing: border-box; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #f3f4f6; }
::-webkit-scrollbar-thumb { background: #fb923c; border-radius: 9999px; }
html.dark ::-webkit-scrollbar-track { background: #1f2937; }

/* ── Sidebar ── */
#sidebar { transition: width 0.3s ease; width: 256px; overflow: hidden; }
#sidebar.collapsed { width: 64px; }
#sidebar.collapsed .menu-label { display: none !important; }
#sidebar.collapsed .submenu { display: none !important; }
#main-wrapper { transition: margin-left 0.3s ease; margin-left: 256px; }
#main-wrapper.collapsed { margin-left: 64px; }

/* ── Mobile sidebar overlay ── */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 29;
  background: rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
@media (max-width: 767px) {
  #sidebar { transform: translateX(-256px); transition: transform 0.3s ease; width: 256px !important; }
  #sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.18); }
  #main-wrapper, #main-wrapper.collapsed { margin-left: 0 !important; }
  .sidebar-backdrop { display: block; }
  .sidebar-backdrop.active { opacity: 1; pointer-events: auto; }
}

/* ── Submenu ── */
.submenu { overflow: hidden; max-height: 0; transition: max-height 0.35s ease; }
.submenu.open { max-height: 600px; }

/* ── Sidebar active link ── */
.sidebar-link.active {
  background-color: #f97316 !important;
  color: #ffffff !important;
}
.sidebar-link.active i { color: #ffffff !important; stroke: #ffffff !important; }

/* ── Menu parent active (when child is active) ── */
.menu-parent.parent-active {
  color: #ea580c;
  background-color: #fff7ed;
}
html.dark .menu-parent.parent-active {
  color: #fb923c;
  background-color: rgba(194,65,12,0.15);
}

/* ── Toggle switch ── */
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: #d1d5db; border-radius: 24px; transition: 0.3s;
}
.toggle-slider:before {
  position: absolute; content: "";
  height: 20px; width: 20px; left: 2px; bottom: 2px;
  background-color: white; border-radius: 50%; transition: 0.3s;
}
input:checked + .toggle-slider { background-color: #f97316; }
input:checked + .toggle-slider:before { transform: translateX(16px); }

/* ── Input base ── */
.inp {
  width: 100%; padding: 10px 16px; border-radius: 8px;
  border: 1px solid #d1d5db; background: white; color: #111827;
  font-size: 0.875rem; line-height: 1.25rem;
  transition: outline 0.15s, border-color 0.15s;
  outline: none;
}
.inp:focus { border-color: #f97316; box-shadow: 0 0 0 3px rgba(249,115,22,0.2); }
html.dark .inp {
  background: #1f2937; border-color: #4b5563; color: #f9fafb;
}
input.inp, select.inp { height: 42px; }
select.inp { cursor: pointer; }
textarea.inp { resize: vertical; height: auto; }

/* ── Flatpickr dark ── */
html.dark .flatpickr-calendar {
  background: #1f2937; border-color: #374151;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
html.dark .flatpickr-day { color: #e5e7eb; }
html.dark .flatpickr-day:hover,
html.dark .flatpickr-day:focus { background: #374151; border-color: #374151; }
html.dark .flatpickr-day.selected,
html.dark .flatpickr-day.selected:hover { background: #f97316; border-color: #f97316; color: #fff; }
html.dark .flatpickr-day.today { border-bottom-color: #f97316; }
html.dark .flatpickr-months { background: #111827; border-radius: 8px 8px 0 0; }
html.dark .flatpickr-month,
html.dark .flatpickr-current-month input.cur-year,
html.dark .flatpickr-current-month .flatpickr-monthDropdown-months { color: #f9fafb; background: transparent; fill: #f9fafb; }
html.dark .flatpickr-weekday { color: #9ca3af; background: #111827; }
html.dark .flatpickr-weekdays { background: #111827; }
html.dark .flatpickr-prev-month,
html.dark .flatpickr-next-month { color: #e5e7eb; fill: #e5e7eb; }
html.dark .flatpickr-time { background: #1f2937; border-color: #374151; }
html.dark .flatpickr-time input,
html.dark .flatpickr-time .flatpickr-am-pm { color: #f9fafb; background: #1f2937; }
html.dark .flatpickr-time .numInputWrapper:hover,
html.dark .flatpickr-time .numInputWrapper:focus { background: #374151; }

/* ── Select2 base ── */
.select2-container--default .select2-selection--single {
  height: 42px; border-radius: 8px; border: 1px solid #d1d5db;
  display: flex; align-items: center;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 1.25rem; padding-left: 16px; color: #111827; font-size: 0.875rem;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 42px; right: 8px;
}
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: #f97316;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.2);
}
.select2-dropdown { border-radius: 8px; border-color: #d1d5db; box-shadow: 0 10px 25px rgba(0,0,0,0.1); overflow: hidden; }
.select2-search--dropdown .select2-search__field {
  border-radius: 6px; border-color: #d1d5db; padding: 6px 12px; font-size: 0.875rem;
  outline: none;
}
.select2-search--dropdown .select2-search__field:focus { border-color: #f97316; }
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
  background-color: #f97316;
}
.select2-container--default .select2-results__option--selected {
  background-color: #fff7ed; color: #c2410c;
}
.select2-results__option { font-size: 0.875rem; padding: 8px 16px; }

/* Select2 dark */
html.dark .select2-container--default .select2-selection--single {
  background: #1f2937; border-color: #4b5563;
}
html.dark .select2-container--default .select2-selection--single .select2-selection__rendered { color: #f9fafb; }
html.dark .select2-container--default .select2-selection--single .select2-selection__arrow b { border-color: #9ca3af transparent transparent; }
html.dark .select2-dropdown { background: #1f2937; border-color: #4b5563; }
html.dark .select2-results__option { color: #e5e7eb; }
html.dark .select2-search--dropdown .select2-search__field {
  background: #374151; border-color: #4b5563; color: #f9fafb;
}
html.dark .select2-container--default .select2-results__option--selected { background: #374151; color: #fb923c; }

/* ── Card ── */
.card {
  background: white; border-radius: 16px;
  border: 1px solid #e5e7eb; padding: 20px;
}
html.dark .card { background: #111827; border-color: #374151; }

/* ── Table ── */
.data-table { width: 100%; font-size: 0.875rem; }
.data-table thead tr { border-bottom: 1px solid #e5e7eb; }
html.dark .data-table thead tr { border-bottom-color: #374151; }
.data-table th { padding: 12px 16px; font-weight: 500; color: #6b7280; text-align: left; }
html.dark .data-table th { color: #9ca3af; }
.data-table tbody tr { border-bottom: 1px solid #f3f4f6; transition: background 0.15s; }
html.dark .data-table tbody tr { border-bottom-color: #1f2937; }
.data-table tbody tr:hover { background: #fff7ed; }
html.dark .data-table tbody tr:hover { background: rgba(55,65,81,0.5); }
.data-table td { padding: 12px 16px; color: #374151; }
html.dark .data-table td { color: #d1d5db; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 8px; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: background 0.15s, color 0.15s; border: none; }
.btn-primary   { background: #f97316; color: #fff; }
.btn-primary:hover { background: #ea580c; }
.btn-secondary { background: #f3f4f6; color: #374151; }
.btn-secondary:hover { background: #e5e7eb; }
html.dark .btn-secondary { background: #1f2937; color: #d1d5db; }
html.dark .btn-secondary:hover { background: #374151; }
.btn-warning   { background: #fef3c7; color: #92400e; }
.btn-warning:hover { background: #fde68a; }
html.dark .btn-warning { background: rgba(120,53,15,0.3); color: #fbbf24; }
html.dark .btn-warning:hover { background: rgba(120,53,15,0.5); }
.btn-success   { background: #d1fae5; color: #065f46; }
.btn-success:hover { background: #a7f3d0; }
html.dark .btn-success { background: rgba(6,78,59,0.3); color: #34d399; }
html.dark .btn-success:hover { background: rgba(6,78,59,0.5); }
.btn-danger    { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }
html.dark .btn-danger { background: rgba(153,27,27,0.3); color: #f87171; }
html.dark .btn-danger:hover { background: rgba(153,27,27,0.5); }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; border-radius: 6px; gap: 4px; }
.btn-sm svg { width: 14px; height: 14px; }

/* ── DataTables overrides ── */
.dataTables_wrapper { font-size: 0.875rem; color: #374151; }
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter { margin-bottom: 10px; }
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label { color: #6b7280; }
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #d1d5db; border-radius: 6px;
    padding: 4px 8px; font-size: 0.8rem;
    color: #374151; background: #fff; outline: none;
    margin: 0 4px;
}
.dataTables_wrapper .dataTables_filter input:focus { border-color: #f97316; }
.dataTables_wrapper .dataTables_info { color: #6b7280; font-size: 0.8rem; padding-top: 8px; }
.dataTables_wrapper .dataTables_paginate { padding-top: 8px; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 4px 10px; margin: 0 2px; border-radius: 6px;
    border: 1px solid #d1d5db !important; color: #374151 !important;
    cursor: pointer; font-size: 0.8rem; background: none !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #fff7ed !important; border-color: #f97316 !important; color: #f97316 !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: #f97316 !important; border-color: #f97316 !important; color: #fff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    color: #d1d5db !important; border-color: #e5e7eb !important; cursor: default;
}
table.dataTable thead th { border-bottom: 1px solid #e5e7eb; }
table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_asc:after,
table.dataTable thead th.sorting_desc:after { opacity: 0.5; }
/* DataTables dark mode */
html.dark .dataTables_wrapper { color: #d1d5db; }
html.dark .dataTables_wrapper .dataTables_length label,
html.dark .dataTables_wrapper .dataTables_filter label,
html.dark .dataTables_wrapper .dataTables_info { color: #9ca3af; }
html.dark .dataTables_wrapper .dataTables_length select,
html.dark .dataTables_wrapper .dataTables_filter input {
    background: #1f2937; border-color: #374151; color: #d1d5db;
}
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button {
    border-color: #374151 !important; color: #d1d5db !important;
}
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #374151 !important; border-color: #4b5563 !important; color: #f9fafb !important;
}
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button.current,
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: #f97316 !important; border-color: #f97316 !important; color: #fff !important;
}
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
html.dark .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    color: #4b5563 !important; border-color: #374151 !important;
}
html.dark table.dataTable thead th { border-bottom-color: #374151; }

/* ── Flatpickr dark mode ── */
html.dark .flatpickr-calendar { background: #1f2937; border-color: #374151; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
html.dark .flatpickr-months .flatpickr-month,
html.dark .flatpickr-weekdays,
html.dark span.flatpickr-weekday { background: #1f2937; color: #f9fafb; fill: #f9fafb; }
html.dark .flatpickr-day { color: #d1d5db; }
html.dark .flatpickr-day:hover { background: #374151; border-color: #374151; }
html.dark .flatpickr-day.selected,
html.dark .flatpickr-day.selected:hover { background: #f97316; border-color: #f97316; color: #fff; }
html.dark .flatpickr-day.today { border-color: #f97316; }
html.dark .flatpickr-day.flatpickr-disabled,
html.dark .flatpickr-day.prevMonthDay,
html.dark .flatpickr-day.nextMonthDay { color: #4b5563; }
html.dark .flatpickr-current-month input.cur-year,
html.dark .flatpickr-current-month .flatpickr-monthDropdown-months { color: #f9fafb; background: #1f2937; }
html.dark .flatpickr-prev-month svg,
html.dark .flatpickr-next-month svg { fill: #d1d5db; }
html.dark .flatpickr-prev-month:hover svg,
html.dark .flatpickr-next-month:hover svg { fill: #f97316; }

/* ── Badge ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge-orange  { background: #ffedd5; color: #c2410c; }
.badge-green   { background: #d1fae5; color: #065f46; }
.badge-red     { background: #fee2e2; color: #991b1b; }
.badge-blue    { background: #dbeafe; color: #1e40af; }
.badge-purple  { background: #ede9fe; color: #6d28d9; }
.badge-gray    { background: #f3f4f6; color: #374151; }
html.dark .badge-orange  { background: rgba(194,65,12,0.2); color: #fb923c; }
html.dark .badge-green   { background: rgba(6,78,59,0.2);  color: #34d399; }
html.dark .badge-red     { background: rgba(153,27,27,0.2); color: #f87171; }
html.dark .badge-blue    { background: rgba(30,64,175,0.2); color: #60a5fa; }
html.dark .badge-purple  { background: rgba(109,40,217,0.2);color: #a78bfa; }
html.dark .badge-gray    { background: #1f2937; color: #9ca3af; }

/* ── User avatar circle ── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #ffedd5; color: #c2410c;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.75rem;
}
html.dark .avatar { background: rgba(194,65,12,0.3); color: #fb923c; }

/* ── Sidebar collapse button icon ── */
#sidebar.collapsed #sidebarCollapseIcon { transform: rotate(180deg); }

/* ── Notification dot ── */
.notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; background: #f97316;
  border-radius: 50%;
}

/* ── Toast notification ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-radius: 12px; min-width: 280px; max-width: 380px;
  background: white; border: 1px solid #e5e7eb;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  transform: translateY(16px); opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
html.dark .toast { background: #1f2937; border-color: #374151; box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
.toast-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; shrink: 0; }
.toast-success .toast-icon { background: #d1fae5; color: #059669; }
html.dark .toast-success .toast-icon { background: rgba(6,78,59,0.3); color: #34d399; }
.toast-info .toast-icon { background: #dbeafe; color: #2563eb; }
html.dark .toast-info .toast-icon { background: rgba(37,99,235,0.2); color: #60a5fa; }
.toast-error .toast-icon { background: #fee2e2; color: #dc2626; }
html.dark .toast-error .toast-icon { background: rgba(153,27,27,0.2); color: #f87171; }
.toast-title { font-size: 0.875rem; font-weight: 600; color: #111827; }
html.dark .toast-title { color: #f9fafb; }
.toast-msg { font-size: 0.75rem; color: #6b7280; margin-top: 1px; }
html.dark .toast-msg { color: #9ca3af; }
.toast-close { margin-left: auto; padding: 2px; color: #9ca3af; cursor: pointer; background: none; border: none; line-height: 1; }
.toast-close:hover { color: #374151; }
html.dark .toast-close:hover { color: #d1d5db; }

/* ── Confirmation Popover ── */
#confirm-popover {
  position: fixed;
  z-index: 99999;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
html.dark #confirm-popover {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}
#confirm-popover p {
  margin: 0 0 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
}
html.dark #confirm-popover p { color: #e5e7eb; }
#confirm-popover::before,
#confirm-popover::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  pointer-events: none;
}
#confirm-popover.pop-bottom::before { top: -14px; border-bottom-color: #e5e7eb; }
#confirm-popover.pop-bottom::after  { top: -12px; border-width: 6px; border-bottom-color: #fff; }
html.dark #confirm-popover.pop-bottom::after { border-bottom-color: #1f2937; }
#confirm-popover.pop-top::before { bottom: -14px; border-top-color: #e5e7eb; }
#confirm-popover.pop-top::after  { bottom: -12px; border-width: 6px; border-top-color: #fff; }
html.dark #confirm-popover.pop-top::after { border-top-color: #1f2937; }

/* ── Responsive inline-grid helpers ── */
.po-item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
  align-items: end;
}
@media (min-width: 640px) {
  .po-item-row { grid-template-columns: 3fr 1.4fr 1.4fr 1.4fr auto; }
}

.tax-form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (min-width: 640px) {
  .tax-form-row { grid-template-columns: 3fr 1.5fr 5.5fr; }
}

/* ── Dropdown menu ── */
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 180px; background: white;
  border: 1px solid #e5e7eb; border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  z-index: 100; display: none; overflow: hidden;
}
html.dark .dropdown-menu { background: #1f2937; border-color: #374151; }
.dropdown-menu a,
.dropdown-menu button {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; font-size: 0.875rem;
  color: #374151; text-decoration: none; cursor: pointer;
  width: 100%; border: none; background: none; text-align: left;
  transition: background 0.15s;
}
html.dark .dropdown-menu a,
html.dark .dropdown-menu button { color: #d1d5db; }
.dropdown-menu a:hover,
.dropdown-menu button:hover { background: #fff7ed; }
html.dark .dropdown-menu a:hover,
html.dark .dropdown-menu button:hover { background: #374151; }
.dropdown-menu .dropdown-divider { border-top: 1px solid #e5e7eb; margin: 4px 0; }
html.dark .dropdown-menu .dropdown-divider { border-color: #374151; }
.dropdown-menu .danger { color: #dc2626 !important; }
.dropdown-menu .danger:hover { background: #fee2e2 !important; }
html.dark .dropdown-menu .danger:hover { background: rgba(153,27,27,0.2) !important; }
