/* ==========================================================================
   Reusable Components
   ========================================================================== */

svg.icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px var(--space-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

/* Keyboard-only focus ring (mouse/touch clicks don't trigger :focus-visible),
   applied broadly so every interactive control gets a visible indicator
   consistent with .stat-card-link's existing treatment below. */
.btn:focus-visible,
.btn-icon:focus-visible,
.dropdown-item:focus-visible,
.tab-btn:focus-visible,
.pagination-btn:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(198, 154, 109, 0.4);
  outline-offset: 2px;
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.btn-sm {
  padding: 6px var(--space-3);
  font-size: var(--fs-xs);
}

.btn-lg {
  padding: 12px var(--space-5);
  font-size: var(--fs-md);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-light);
}

.btn-secondary {
  background: var(--color-secondary-dark);
  color: #fff;
}
.btn-secondary:hover {
  filter: brightness(0.92);
}

.btn-outline {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-text);
}
.btn-outline:hover {
  border-color: var(--color-secondary);
  color: var(--color-secondary-dark);
  background: var(--color-secondary-light);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 0.2px solid var(--color-primary);
  border-radius: var(--radius-sm);
}
.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(0.92);
}

.btn-danger-outline {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.btn-danger-outline:hover {
  background: var(--color-danger-bg);
}

.btn-success-outline {
  background: transparent;
  border-color: var(--color-success);
  color: var(--color-success);
}
.btn-success-outline:hover {
  background: var(--color-success-bg);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  vertical-align: middle;
}

.btn-icon .icon,
.modal-close .icon,
.topbar-icon-btn .icon,
.theme-toggle .icon {
  margin: auto;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-group {
  display: inline-flex;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
}
.btn-group .btn {
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--color-border-strong);
}
.btn-group .btn:last-child {
  border-right: none;
}

/* ---- Cards ---- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.card-body {
  padding: var(--space-4);
}

.card > .card-body.pb-0:has(.toolbar) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: var(--space-4);
}

.card > .card-body.pb-0:has(.toolbar.toolbar-left) {
  justify-content: flex-start;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-table-head);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.card-header h3 {
  font-size: var(--fs-sm);
}

.card-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* ---- Statistic / KPI Cards ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card-link {
  color: inherit;
  text-decoration: none;
}

.stat-card-link:focus-visible {
  outline: 3px solid rgba(198, 154, 109, 0.4);
  outline-offset: 2px;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-primary);
}

/* Top accent follows the same semantic tone as the card's icon, so alerts
   (warning/danger) read as visually distinct from routine metrics instead
   of every card sharing one accent color. */
.stat-card.tone-secondary::before { background: var(--color-secondary); }
.stat-card.tone-success::before { background: var(--color-success); }
.stat-card.tone-warning::before { background: var(--color-warning); }
.stat-card.tone-danger::before { background: var(--color-danger); }
.stat-card.tone-info::before { background: var(--color-info); }

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.stat-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card__icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card__icon.tone-primary { background: var(--color-primary-bg); color: var(--color-text); }
.stat-card__icon.tone-secondary { background: var(--color-secondary-bg); color: var(--color-secondary-dark); }
.stat-card__icon.tone-success { background: var(--color-success-bg); color: var(--color-success); }
.stat-card__icon.tone-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.stat-card__icon.tone-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.stat-card__icon.tone-info { background: var(--color-info-bg); color: var(--color-info); }

.stat-card__label {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: var(--fw-medium);
}

.stat-card__value {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
}

.stat-card__trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}

.stat-card__trend.up { color: var(--color-success); }
.stat-card__trend.down { color: var(--color-danger); }
.stat-card__trend.flat { color: var(--color-text-muted); }

.stat-card-link {
  color: inherit;
  text-decoration: none;
}

.stat-card-link:focus-visible {
  outline: 3px solid rgba(198, 154, 109, 0.4);
  outline-offset: 2px;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  line-height: 1.6;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-secondary { background: var(--color-secondary-bg); color: var(--color-secondary-dark); }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }
.badge-neutral::before { display: none; }

.badge-branch {
  background: var(--color-secondary-dark);
  color: #fff;
}
.badge-branch::before { display: none; }

.badge-role {
  background: var(--color-primary-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.badge-role::before { display: none; }

/* ---- Forms ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-3);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

.form-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text);
}

.form-label .required {
  color: var(--color-danger);
}

.form-hint {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.form-hint.inline {
  display: inline;
}

.form-control[readonly] {
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* Compact spreadsheet-style variant for inputs embedded directly inside a
   data-table cell (e.g. the Float Expenses editable line table) — same
   tokens as .form-control, just lower-profile so a dense row of inputs
   doesn't read as a stack of separate form fields. Borderless until
   hover/focus keeps the row visually calm; a matched/locked field (e.g. Unit
   auto-filled from a product) still gets the shared [readonly] treatment. */
.table-inline-input {
  min-height: 34px;
  padding: 6px var(--space-2);
  border-color: transparent;
  background: transparent;
  font-size: var(--fs-sm);
}

.table-inline-input:hover {
  background: var(--color-control-bg);
}

.table-inline-input:focus {
  background: var(--color-control-bg);
  border-color: var(--color-primary);
}

.table-inline-input[readonly] {
  border-color: transparent;
}

.form-control {
  width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 10px var(--space-3);
  background: var(--color-control-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  line-height: 1.35;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-focus);
  background: var(--color-card);
}

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

select.form-control {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b6a58' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-secondary);
}

.input-icon {
  position: relative;
}
.input-icon .icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-faint);
}
.input-icon .form-control {
  padding-left: 38px;
}

.file-drop {
  position: relative;
  display: block;
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.file-drop:hover {
  border-color: var(--color-secondary);
  background: var(--color-secondary-light);
}

.file-drop__text {
  margin-top: 8px;
  margin-bottom: 4px;
}

.file-drop__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop.dragover {
  border-color: var(--color-secondary);
  background: var(--color-secondary-light);
}

.file-drop__preview {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  margin: 0 auto var(--space-2);
}

/* ---- Branch Selector ---- */
.branch-selector {
  position: relative;
}

.branch-selector__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: var(--color-control-bg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--color-text);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.branch-selector__trigger:hover {
  border-color: var(--color-secondary);
}

.branch-selector__trigger .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
}

.branch-selector__menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: var(--z-dropdown);
  display: none;
}

.branch-selector__menu.open {
  display: block;
}

.branch-selector__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  transition: background var(--transition-fast);
}

.branch-selector__item:hover {
  background: var(--color-bg);
}

.branch-selector__item.active {
  background: var(--color-secondary-light);
  color: var(--color-primary-dark);
  font-weight: var(--fw-semibold);
}

.branch-selector__item .check {
  color: var(--color-secondary-dark);
  opacity: 0;
}
.branch-selector__item.active .check {
  opacity: 1;
}

/* ---- Generic Dropdown ---- */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: var(--z-dropdown);
  display: none;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-menu.align-left {
  right: auto;
  left: 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--color-text);
  text-align: left;
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--color-bg);
}

.dropdown-item.danger {
  color: var(--color-danger);
}

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-2) 0;
}

.dropdown-header {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

/* ---- Notification / Message panels ---- */
.notif-panel {
  width: 340px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
}

.notif-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.notif-panel__list {
  overflow-y: auto;
}

.notif-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.notif-item:hover {
  background: var(--color-bg);
}

.notif-item__icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notif-item__body {
  flex: 1;
  min-width: 0;
}

.notif-item__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.notif-item__meta {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.notif-item.unread {
  background: rgba(198, 154, 109, 0.08);
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
}

.card > .table-wrap {
  border-top: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.data-table {
  width: 100%;
  font-size: var(--fs-sm);
  border: 1px solid var(--color-border);
}

.data-table thead th {
  text-align: left;
  padding: var(--space-3) var(--space-3);
  background: var(--color-table-head);
  color: var(--color-text-muted);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

.data-table thead th:last-child {
  border-right: none;
}

.data-table thead th.sortable {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.data-table thead th.sortable:hover {
  color: var(--color-text);
}

.data-table tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody td:last-child {
  border-right: none;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--color-bg);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .cell-media {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.data-table .thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.data-table .cell-primary {
  font-weight: var(--fw-semibold);
}

.data-table .cell-muted {
  color: var(--color-text-muted);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}

.data-table thead th.text-right,
.data-table tbody td.text-right,
.data-table thead th.text-center,
.data-table tbody td.text-center {
  text-align: center;
}

.data-table tbody td.text-right .row-actions,
.data-table tbody td.text-center .row-actions {
  justify-content: center;
}

.data-table tbody td:has(> .btn-icon:only-child) {
  text-align: center;
}

.row-actions .btn-icon {
  width: 32px;
  height: 32px;
}

/* ---- Toolbar / Filters ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  width: 100%;
  margin-bottom: 0;
}

.toolbar-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 240px;
  min-width: 200px;
  max-width: 400px;
  height: 56px;
}

.toolbar-search .form-control {
  height: 100%;
  padding-left: 38px;
}

.toolbar-search .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-faint);
}

.toolbar-filter {
  /* .form-control sets width:100%, which (unlike .toolbar-search's input,
     constrained by its own wrapper) resolves against the whole toolbar row
     here since these selects are direct flex children — forcing each onto
     its own line. Override so they size like normal inline filter controls. */
  width: auto;
  height: 56px;
  flex: 0 1 240px;
  min-width: 190px;
}

.toolbar > .form-control:not(.toolbar-filter),
.toolbar .date-range-group .form-control {
  height: 56px;
}

.toolbar > .btn,
.toolbar .date-range-group .btn {
  min-height: 56px;
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 56px;
  flex: 0 0 auto;
  padding: 0 var(--space-3);
  background: var(--color-control-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}

.toolbar-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.filter-chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.filter-chip button {
  color: var(--color-text-faint);
  display: inline-flex;
}

/* ---- Pagination ---- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  flex-wrap: wrap;
  border-top: 1px solid var(--color-border);
}

.pagination-info {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pagination-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.pagination-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.pagination-btn.active {
  background: var(--color-primary);
  color: #fff;
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}

.tab-btn {
  padding: var(--space-3) var(--space-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-secondary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---- Accordion ---- */
.accordion-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-weight: var(--fw-medium);
  font-size: var(--fs-sm);
}

.accordion-header .icon {
  transition: transform var(--transition-fast);
}

.accordion-item.open .accordion-header .icon {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition);
}

.accordion-body__inner {
  padding: 0 var(--space-4) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}

/* ---- Modals ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 22, 10, 0.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal-backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  z-index: var(--z-modal);
  animation: modal-in 0.25s ease;
}

/* A <form> wrapping modal-body + modal-footer would otherwise be an
   unconstrained grid item that grows to fit all its content; making it
   a transparent layout box lets its children join the modal's own grid
   rows directly (header / scrollable body / pinned footer). */
.modal > form {
  display: contents;
}

.modal.modal-lg { max-width: 760px; }
.modal.modal-sm { max-width: 420px; }
.modal.modal-xl { max-width: 960px; }

/* Goods Received Note workspace — wider than the standard .modal-xl so its
   dense receiving table (13 columns) needs less internal horizontal scroll;
   the table itself still sits in the usual .table-wrap (overflow-x: auto)
   for narrower viewports. */
.modal.grn-workspace { max-width: 1280px; }
.modal.grn-workspace .modal-footer { flex-wrap: wrap; }

/* Requisition -> PO -> GRN -> Invoice -> Posted progress strip, shown at the
   top of the Purchase Order detail workspace. */
.po-progress-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.po-progress-strip__step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.po-progress-strip__dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  font-size: var(--fs-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.po-progress-strip__step.is-done .po-progress-strip__dot {
  background: var(--color-success);
  border-color: var(--color-success);
  color: var(--color-text-on-primary);
}

.po-progress-strip__step.is-done { color: var(--color-text); }

.po-progress-strip__step.is-active .po-progress-strip__dot {
  border-color: var(--color-secondary);
  color: var(--color-secondary);
}

.po-progress-strip__step.is-active { color: var(--color-text); font-weight: 600; }

.po-progress-strip__connector {
  flex: 1 1 16px;
  min-width: 12px;
  height: 1px;
  background: var(--color-border);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  font-size: var(--fs-md);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
}

.modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* Purchase Order / Invoice detail modal — brand-colored header, matching the
   command banner used on the Purchases/Supplier Ledger pages. Shared markup
   across every page that includes #purchase-detail-modal. */
#purchase-detail-modal .modal-header {
  background: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

#purchase-detail-modal .modal-header h3 {
  color: #fff;
}

#purchase-detail-modal .modal-close {
  color: rgba(255, 255, 255, .72);
}

#purchase-detail-modal .modal-close:hover {
  background: rgba(255, 255, 255, .12);
  color: #fff;
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.modal-footer.space-between {
  justify-content: space-between;
}

/* ---- Alerts ---- */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  border: 1px solid transparent;
}

.alert .icon {
  flex-shrink: 0;
}

.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: rgba(21,128,61,0.25); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: rgba(217,119,6,0.25); }
.alert-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: rgba(220,38,38,0.25); }
.alert-info { background: var(--color-info-bg); color: var(--color-info); border-color: rgba(37,99,235,0.25); }

/* ---- Toast Notifications ---- */
.toast-stack {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  max-width: 340px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast .icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.toast.success .icon { color: var(--color-success); }
.toast.warning .icon { color: var(--color-warning); }
.toast.danger .icon { color: var(--color-danger); }
.toast.info .icon { color: var(--color-info); }

.toast-close {
  margin-left: auto;
  color: var(--color-text-faint);
}

/* ---- Tooltip ---- */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary-dark);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: var(--z-tooltip);
}

[data-tooltip]:hover::after {
  opacity: 1;
}

/* ---- Loading Spinner ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--color-border);
  border-top-color: var(--color-secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3.5px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-7);
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
}

/* ---- Empty State ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
  color: var(--color-text-faint);
}

.empty-state h3 {
  color: var(--color-text);
  margin-bottom: 4px;
  font-size: var(--fs-base);
}

.empty-state p {
  font-size: var(--fs-sm);
  max-width: 320px;
  margin-bottom: var(--space-3);
}

/* ---- Chart Containers ---- */
.chart-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.chart-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--space-4);
  margin-bottom: 0;
  background: var(--color-table-head);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-2);
  flex-wrap: wrap;
}

.chart-card__header h3 {
  font-size: var(--fs-sm);
}

.chart-card__header p {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
  width: calc(100% - var(--space-8));
  margin: var(--space-4);
}

.chart-legend {
  padding: 0 var(--space-4) var(--space-4);
}

.chart-canvas-wrap.sm { height: 180px; }
.chart-canvas-wrap.lg { height: 340px; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-legend__dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-sm);
}

/* ---- Progress bar ---- */
.progress {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-secondary);
  transition: width var(--transition-slow);
}

.progress__bar.success { background: var(--color-success); }
.progress__bar.warning { background: var(--color-warning); }
.progress__bar.danger { background: var(--color-danger); }

/* ---- Timeline ---- */
.timeline {
  position: relative;
  padding-left: var(--space-5);
}

.timeline::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--color-border);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--space-4);
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-5) + 4px);
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-secondary);
  border: 2px solid var(--color-card);
  box-shadow: 0 0 0 2px var(--color-secondary);
}

.timeline-item__meta {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.timeline-item__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

/* ---- List items (activity, low-stock, etc.) ---- */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item__icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.list-item__body {
  flex: 1;
  min-width: 0;
}

.list-item__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.list-item__meta {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.list-item__value {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-align: right;
  flex-shrink: 0;
}

/* ---- Avatar ---- */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: #fff;
  background: var(--color-secondary-dark);
  flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 0.625rem; }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-base); }

.profile-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.avatar-group {
  display: flex;
}
.avatar-group .avatar {
  margin-left: -10px;
  border: 2px solid var(--color-card);
}
.avatar-group .avatar:first-child {
  margin-left: 0;
}

/* ---- Theme toggle switch ---- */
.theme-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.theme-toggle:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { display: none; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--color-border-strong);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .track {
  background: var(--color-secondary);
}
.switch input:checked + .track::before {
  transform: translateX(18px);
}

/* ---- Inline-form / mini-table utility classes ---- */
.section-title.compact h2 { font-size: var(--fs-base); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }

/* "Payment" section header inside the Purchase Order / Invoice detail modal —
   brand-colored band matching the modal's own header, instead of a plain
   heading butted up against the product table. */
.payment-section-title {
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary);
  border-radius: var(--radius-sm);
}

.payment-section-title h2 {
  color: #fff;
}

/* Read-only "here's the line you're acting on" summary card at the top of
   the Float Expenses Convert/Keep-as-Expense modals — a tinted, bordered box
   instead of plain floating label/value text, so the line being converted or
   classified reads as a distinct, anchored reference point. */
.float-line-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.float-line-summary__amount {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--color-primary);
}

/* Small non-colored section labels breaking a long form into scannable
   groups (Purchase Details / Product / Quantity & Pricing / Attachment) —
   lighter-weight than .payment-section-title's brand band, which would be
   too heavy repeated four times in one modal. */
.form-section-label {
  margin: var(--space-4) 0 var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.form-section-label:first-child {
  margin-top: 0;
}

.col-qty { width: 90px; min-width: 70px; }
.col-cost { width: 120px; min-width: 90px; }
.col-total { width: 110px; min-width: 90px; }
.col-action { width: 40px; min-width: 40px; }
.col-share { width: 160px; }

/* Item-row table inside the New Purchase Order modal: force a real minimum
   table width so table-layout:auto can't crush the Qty/Cost inputs down to
   a width narrower than their own padding (which makes typed values invisible
   even though the value is there) — the .table-wrap already scrolls this. */
.purchase-items-table {
  min-width: 520px;
}

.purchase-items-table .js-item-qty,
.purchase-items-table .js-item-cost,
.purchase-items-table .js-req-item-qty,
.purchase-items-table .js-req-item-price,
.js-convert-qty,
.js-convert-price {
  padding-left: var(--space-2);
  padding-right: var(--space-2);
  text-align: center;
}

/* Requisition item rows have more columns than the plain Purchase Order item
   table (unit, remarks, estimate/variance), so they need more horizontal
   room before .table-wrap's scroll kicks in. */
.requisition-items-table {
  min-width: 760px;
}
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}
.total-row .value { font-size: var(--fs-lg); }

.purchase-action-panel {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.purchase-action-panel .form-group {
  margin-bottom: 0;
  margin-top: 0;
}

.purchase-action-panel .form-group + .purchase-action-panel__buttons {
  margin-top: var(--space-3);
}

.purchase-action-panel__buttons {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---- Utility ---- */
.text-muted { color: var(--color-text-muted); }
.text-faint { color: var(--color-text-faint); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-info { color: var(--color-info); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-semibold { font-weight: var(--fw-semibold); }
.fs-xs { font-size: var(--fs-xs); }
.fs-sm { font-size: var(--fs-sm); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-0 { margin-bottom: 0; }
.pb-0 { padding-bottom: 0; }
.w-full { width: 100%; }
.hidden { display: none !important; }
