/* ===== Typography & base ===== */
body { font-family: 'Inter', system-ui, sans-serif; font-feature-settings: 'cv11','ss01'; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.55rem 1rem; border-radius: 0.5rem; font-weight: 500; font-size: 0.875rem; transition: all 0.15s; white-space: nowrap; }
.btn-primary { background: #f97316; color: white; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.btn-primary:hover { background: #ea580c; }
.btn-accent  { background: #f97316; color: white; }
.btn-accent:hover { background: #ea580c; }
.btn-ghost   { color: #475569; background: white; border: 1px solid #e2e8f0; }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger  { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: #059669; color: white; }
.btn-success:hover { background: #047857; }

/* ===== Form inputs ===== */
.input, .select, .textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.5rem;
  border: 1.5px solid #e2e8f0;
  background: white;
  font-size: 0.95rem;
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #f97316;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}
.label { display: block; font-size: 0.8125rem; font-weight: 600; color: #334155; margin-bottom: 0.4rem; letter-spacing: 0.01em; }

/* ===== Cards ===== */
.card { background: white; border-radius: 0.75rem; border: 1px solid #e2e8f0; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }

/* ===== Tables — all cells centered, both axes ===== */
.table { width: 100%; font-size: 0.95rem; border-collapse: collapse; }
.table thead th {
  text-align: center;
  padding: 0.875rem 1.25rem;
  font-weight: 600;
  font-size: 0.75rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  vertical-align: middle;
}
.table tbody td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  color: #0f172a;
  vertical-align: middle;
  text-align: center;
}
.table tbody tr { transition: background-color 0.1s; }
.table tbody tr:hover { background-color: #f8fafc; }
.table tbody tr:nth-child(even) { background-color: #fdfdfe; }
.table tbody tr:nth-child(even):hover { background-color: #f8fafc; }
.table tfoot td {
  padding: 1rem 1.25rem;
  background: #f8fafc;
  font-weight: 600;
  border-top: 2px solid #e2e8f0;
  text-align: center;
  vertical-align: middle;
}

/* Number cells: centered (overrides any old right-align) with tabular digits so decimals line up neatly */
.num { text-align: center; font-variant-numeric: tabular-nums; font-weight: 500; }
.num-big { font-size: 1.05rem; font-weight: 600; }
.money { font-variant-numeric: tabular-nums; }

/* Explicit override for any util cell using Tailwind text-right inside .table */
.table .text-right { text-align: center !important; }
.table .text-left { text-align: center !important; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-paid    { background: #d1fae5; color: #065f46; }
.badge-unpaid  { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }

/* ===== Stat cards ===== */
.stat-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1.5rem;
  transition: all 0.15s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.06); border-color: #cbd5e1; }
.stat-label { font-size: 0.8125rem; color: #64748b; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 2.25rem; font-weight: 700; color: #0f172a; margin-top: 0.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.8125rem; color: #94a3b8; margin-top: 0.25rem; }

/* ===== Section headers ===== */
.section-title { font-size: 1.125rem; font-weight: 700; color: #0f172a; }
.section-subtitle { font-size: 0.875rem; color: #64748b; }

/* ===== Sidebar ===== */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-radius: 0.5rem;
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: white; }
.sidebar-link.active { background: rgba(255,255,255,0.12); color: white; font-weight: 600; box-shadow: inset 3px 0 0 #f97316; }

/* ===== Select2 — exact match to .input style ===== */
.select2-container { width: 100% !important; }

/* The "input-looking" pill */
.select2-container--default .select2-selection--single {
  height: 42px !important;          /* matches .input total height */
  padding: 0 0.875rem !important;   /* matches .input horizontal padding */
  border: 1.5px solid #e2e8f0 !important;
  border-radius: 0.5rem !important;
  background: #fff !important;
  display: flex !important;
  align-items: center !important;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* The rendered text inside */
.select2-container--default .select2-selection--single .select2-selection__rendered {
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  font-size: 0.95rem !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  color: #0f172a !important;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 1.75rem !important;  /* space for arrow */
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: #94a3b8 !important;
  font-weight: 400;
}

/* Custom chevron arrow — replace default browser-ish triangle */
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 100% !important;
  width: 32px !important;
  top: 0 !important;
  right: 4px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
  display: none !important;  /* hide ugly default arrow */
}
.select2-container--default .select2-selection--single .select2-selection__arrow::after {
  content: '';
  width: 10px;
  height: 10px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.2s;
}
.select2-container--open .select2-selection--single .select2-selection__arrow::after {
  transform: rotate(225deg) translate(-2px, -2px);
}

/* Focus + open state */
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: #f97316 !important;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12) !important;
  outline: none !important;
}

/* Error state */
.select2-container.select2-error .select2-selection--single {
  border-color: #fb7185 !important;
}

/* Clear (x) button */
.select2-container--default .select2-selection--single .select2-selection__clear {
  position: absolute;
  right: 32px;
  top: 50%;
  transform: translateY(-50%);
  margin: 0 !important;
  padding: 0 6px;
  font-size: 1.1rem;
  font-weight: 400;
  color: #94a3b8;
  cursor: pointer;
  line-height: 1;
}
.select2-container--default .select2-selection--single .select2-selection__clear:hover {
  color: #ef4444;
}

/* Disabled state */
.select2-container--default.select2-container--disabled .select2-selection--single {
  background: #f8fafc !important;
  cursor: not-allowed !important;
  color: #64748b !important;
}

/* ----- Dropdown panel ----- */
.select2-dropdown {
  border: 1.5px solid #e2e8f0 !important;
  border-radius: 0.625rem !important;
  box-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.15), 0 4px 6px -2px rgba(15, 23, 42, 0.05) !important;
  overflow: hidden;
  margin-top: 6px;
  font-family: 'Inter', system-ui, sans-serif;
  background: #fff;
  /* never wider than the trigger element */
  min-width: 200px;
  box-sizing: border-box;
}
/* Long option text wraps to next line rather than expanding panel */
.select2-results__option {
  white-space: normal !important;
  word-break: break-word;
}
.select2-dropdown--above { margin-top: -6px; }

/* Search field inside dropdown */
.select2-search--dropdown {
  padding: 0.625rem !important;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.select2-search--dropdown .select2-search__field {
  padding: 0.5rem 0.75rem 0.5rem 2.25rem !important;
  border: 1.5px solid #e2e8f0 !important;
  border-radius: 0.375rem !important;
  font-size: 0.9rem !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  outline: none !important;
  background-color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 0.625rem center;
  background-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.select2-search--dropdown .select2-search__field:focus {
  border-color: #f97316 !important;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12) !important;
}

/* Result options */
.select2-results__options {
  padding: 0.25rem !important;
}
.select2-container--default .select2-results > .select2-results__options {
  max-height: 280px !important;
}
.select2-results__option {
  padding: 0.6rem 0.75rem !important;
  font-size: 0.9rem !important;
  color: #1e293b !important;
  border-radius: 0.375rem !important;
  margin-bottom: 1px;
  transition: background-color 0.1s, color 0.1s;
}
.select2-container--default .select2-results__option--highlighted,
.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted[data-selected],
.select2-container--default .select2-results__option--selected {
  background-color: #eff6ff !important;
  color: #ea580c !important;
  font-weight: 500;
}
.select2-container--default .select2-results__option[aria-selected=true],
.select2-container--default .select2-results__option[data-selected=true] {
  background-color: #f97316 !important;
  color: #fff !important;
  font-weight: 600;
}
.select2-container--default .select2-results__option[aria-selected=true].select2-results__option--highlighted {
  background-color: #ea580c !important;
}
.select2-container--default .select2-results__option--disabled {
  color: #cbd5e1 !important;
  cursor: not-allowed;
}
.select2-results__message {
  color: #64748b !important;
  font-size: 0.9rem !important;
  padding: 0.75rem 1rem !important;
}

/* Scrollbar — slim & light */
.select2-results__options::-webkit-scrollbar { width: 6px; }
.select2-results__options::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.select2-results__options::-webkit-scrollbar-track { background: transparent; }

/* ===== Flatpickr — match Tailwind .input style ===== */
.flatpickr-input.input { cursor: pointer; }
.flatpickr-calendar {
  font-family: 'Inter', system-ui, sans-serif !important;
  border-radius: 0.75rem !important;
  border: 1.5px solid #e2e8f0 !important;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12) !important;
  padding: 6px;
}
.flatpickr-months {
  background: #f8fafc;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
}
.flatpickr-month {
  color: #0f172a !important;
  fill: #0f172a !important;
}
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  font-weight: 600 !important;
  font-size: 0.95rem !important;
  color: #0f172a !important;
}
.flatpickr-prev-month, .flatpickr-next-month {
  fill: #475569 !important;
  padding: 8px !important;
}
.flatpickr-prev-month:hover, .flatpickr-next-month:hover {
  background: #e2e8f0;
  border-radius: 0.375rem;
}
.flatpickr-weekday {
  color: #64748b !important;
  font-weight: 600 !important;
  font-size: 0.75rem !important;
  text-transform: uppercase;
}
.flatpickr-day {
  color: #0f172a;
  border-radius: 0.375rem !important;
  border: none !important;
  font-weight: 500;
}
.flatpickr-day:hover {
  background: #e2e8f0 !important;
}
.flatpickr-day.today {
  border: 1.5px solid #f97316 !important;
  color: #f97316;
  font-weight: 700;
}
.flatpickr-day.selected, .flatpickr-day.selected:hover {
  background: #f97316 !important;
  color: white !important;
  border-color: #f97316 !important;
}
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay {
  color: #cbd5e1 !important;
}

/* ===== Collapsible sidebar ===== */
/* Smooth transition for sidebar width + content margin */
@media (min-width: 1024px) {
  aside { transition: width 0.22s ease; }
  .lg\:ml-64 { transition: margin-left 0.22s ease; }

  body.sidebar-collapsed aside { width: 64px !important; }
  body.sidebar-collapsed .lg\:ml-64 { margin-left: 64px !important; }
}

/* Hide label text + section headings + brand text when collapsed */
body.sidebar-collapsed .sidebar-link > span,
body.sidebar-collapsed .sidebar-section-label,
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-user-meta {
  display: none !important;
}

/* Center icons + logo + avatar when collapsed */
body.sidebar-collapsed .sidebar-link { justify-content: center; padding-left: 0.5rem; padding-right: 0.5rem; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; }
body.sidebar-collapsed .sidebar-user { justify-content: center; padding-left: 0; padding-right: 0; }

/* Hide section heading padding so dividers don't look weird */
body.sidebar-collapsed .sidebar-section-label { padding: 0; margin: 0; height: 8px; }

/* Toggle button chevron — rotate when collapsed */
body.sidebar-collapsed .sidebar-toggle-icon { transform: rotate(180deg); }
.sidebar-toggle-icon { transition: transform 0.22s ease; }

/* CSS tooltip: only when collapsed + hovering a sidebar link */
body.sidebar-collapsed .sidebar-link {
  position: relative;
}
body.sidebar-collapsed .sidebar-link[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: white;
  padding: 0.4rem 0.7rem;
  border-radius: 0.375rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  pointer-events: none;
}
/* Small caret pointing left from tooltip */
body.sidebar-collapsed .sidebar-link[data-tip]:hover::before {
  content: '';
  position: absolute;
  left: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: #0f172a;
  z-index: 100;
  pointer-events: none;
}

/* Same tooltip pattern for the toggle button itself */
body.sidebar-collapsed .sidebar-toggle-btn { position: relative; }
body.sidebar-collapsed .sidebar-toggle-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: white;
  padding: 0.4rem 0.7rem;
  border-radius: 0.375rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 100;
}

/* Sidebar brand button — also clickable to toggle collapse; same tooltip when collapsed */
.sidebar-brand-btn { background: transparent; border: 0; color: inherit; font: inherit; }
.sidebar-brand-btn:focus-visible { outline: 2px solid #f97316; outline-offset: -2px; }
body.sidebar-collapsed .sidebar-brand-btn { position: relative; padding-left: 0.5rem; padding-right: 0.5rem; }
body.sidebar-collapsed .sidebar-brand-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: white;
  padding: 0.4rem 0.7rem;
  border-radius: 0.375rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  pointer-events: none;
}

@media print {
  aside, header, .no-print { display: none !important; }
  main { padding: 0 !important; }
  .lg\:ml-64 { margin-left: 0 !important; }
  body { background: white !important; }
}

/* ===== Mobile responsive tables — opt in by adding .table-card to a .table ===== */
@media (max-width: 767px) {
  .table-card,
  .table-card thead,
  .table-card tbody,
  .table-card tfoot,
  .table-card tr,
  .table-card td,
  .table-card th { display: block; width: 100%; box-sizing: border-box; }
  .table-card thead { display: none; }
  .table-card tr {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.625rem;
    margin: 0 0 0.75rem 0;
    padding: 0.85rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  .table-card tbody tr:nth-child(even) { background: white; }
  .table-card td {
    border: none !important;
    padding: 0.4rem 0;
    text-align: left !important;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .table-card td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    padding-top: 2px;
  }
  /* Cells flagged as primary (e.g. customer name) take full width, no label */
  .table-card td.cell-primary { display: block; text-align: left !important; padding-bottom: 0.6rem; border-bottom: 1px dashed #e2e8f0 !important; margin-bottom: 0.4rem; }
  .table-card td.cell-primary::before { content: none; }
  /* Action cells: full width, label hidden, wrap buttons */
  .table-card td.cell-actions { display: block; text-align: left !important; padding-top: 0.6rem; border-top: 1px dashed #e2e8f0 !important; margin-top: 0.4rem; }
  .table-card td.cell-actions::before { content: none; }
  .table-card td.cell-actions > div { justify-content: flex-start !important; flex-wrap: wrap; gap: 0.4rem; }
  /* Number cells right-align value, label on left */
  .table-card td.num { text-align: right !important; }
  /* Hide cell entirely on mobile */
  .table-card td.mobile-hide { display: none !important; }
  /* When a cell contains a form input/select, stack label above instead of inline */
  .table-card td:has(> .input, > .select, > .textarea, > select, > input, > .select2-container) {
    display: block;
    text-align: left !important;
  }
  .table-card td:has(> .input, > .select, > .textarea, > select, > input, > .select2-container)::before {
    display: block;
    margin-bottom: 0.3rem;
    padding-top: 0;
  }
  /* Form-row tables (used in issue/return/quotation/purchase forms): treat each tr as a card */
  .table-card tbody tr.form-row,
  .table-card tbody tr { background: white; }
  /* Empty-state row keeps centered look */
  .table-card tr.empty-row { padding: 2rem 1rem; text-align: center; }
  .table-card tr.empty-row td { display: block; text-align: center !important; }
  .table-card tr.empty-row td::before { content: none; }
}

/* ===== Mobile-friendly native dialogs ===== */
@media (max-width: 640px) {
  dialog.responsive-dialog {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    max-height: calc(100vh - 1rem) !important;
    margin: 0.5rem auto !important;
    padding: 0 !important;
    border-radius: 0.75rem !important;
  }
  dialog.responsive-dialog > * { max-height: calc(100vh - 2rem); overflow-y: auto; }
}

/* ===== Mobile multi-item form rows → stacked cards ===== */
@media (max-width: 767px) {
  .item-rows-mobile .item-row {
    display: block !important;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.85rem;
    margin-bottom: 0.75rem;
  }
  .item-rows-mobile .item-row > div,
  .item-rows-mobile .item-row > td {
    display: block !important;
    width: 100% !important;
    padding: 0.35rem 0;
  }
  .item-rows-mobile .item-row .field-label-mobile {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 0.25rem;
    letter-spacing: 0.04em;
  }
}
@media (min-width: 768px) {
  .item-rows-mobile .field-label-mobile { display: none; }
}
