/* ==========================================================================
   Nava — component kit
   Shared primitives from the contract: buttons, forms, surfaces, tables,
   tabs, badges, overlays, menus, empty states, skeletons, kanban.
   Everything is logical-property based so RTL/LTR both hold.
   ========================================================================== */

/* ---------- keyframes --------------------------------------------------- */

@keyframes nv-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes nv-pop-in {
  from { opacity: 0; transform: translateY(6px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes nv-slide-in-end {
  from { opacity: .4; transform: translateX(var(--slide-from, 100%)); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes nv-slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes nv-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
@keyframes nv-spin {
  to { transform: rotate(360deg); }
}
@keyframes nv-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------- buttons ----------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 32px;
  padding-inline: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease),
              color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease),
              transform var(--motion-fast) var(--ease);
}
.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.btn:active {
  background: var(--surface-active);
  transform: translateY(.5px);
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .5;
  pointer-events: none;
}
.btn svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--brand-contrast);
}
.btn-primary:active {
  background: var(--brand-active);
  border-color: var(--brand-active);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: transparent;
  color: var(--text);
}
.btn-ghost:active {
  background: var(--surface-active);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
}
.btn-danger:hover {
  background: #C41F1F;
  border-color: #C41F1F;
  color: #FFFFFF;
}
.btn-danger:active {
  background: #AC1919;
  border-color: #AC1919;
}

.btn-soft {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand);
}
.btn-soft:hover {
  background: var(--brand-soft);
  border-color: var(--brand-ring);
  color: var(--brand-hover);
}

.btn-sm {
  height: 26px;
  padding-inline: var(--sp-2);
  font-size: var(--text-xs);
  gap: 6px;
}
.btn-sm svg {
  width: 13px;
  height: 13px;
}

.btn-lg {
  height: 40px;
  padding-inline: var(--sp-4);
  font-size: var(--text-base);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  gap: 0;
  color: var(--text-2);
  background: transparent;
  border-color: transparent;
}
.btn-icon:hover {
  background: var(--surface-hover);
  border-color: transparent;
  color: var(--text);
}
.btn-icon.btn-sm {
  width: 26px;
  height: 26px;
}
.btn-icon.btn-lg {
  width: 40px;
  height: 40px;
}
.btn-icon svg {
  width: 17px;
  height: 17px;
}

.btn-block {
  width: 100%;
}

.btn .spinner {
  width: 14px;
  height: 14px;
}

/* ---------- spinner ----------------------------------------------------- */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-block-start-color: transparent;
  border-radius: 50%;
  animation: nv-spin .7s linear infinite;
  opacity: .8;
}

/* ---------- form fields ------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field + .field {
  margin-block-start: var(--sp-3);
}
.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}
.field-req {
  color: var(--danger);
  font-size: var(--text-xs);
}
.field-hint {
  font-size: var(--text-xs);
  color: var(--text-2);
  line-height: 1.5;
}
.field-error {
  font-size: var(--text-xs);
  color: var(--danger);
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-error svg {
  width: 13px;
  height: 13px;
}
.field-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
}

.input,
.select,
.textarea {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding-inline: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.4;
  transition: border-color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease),
              background-color var(--motion-fast) var(--ease);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-3);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--surface-3);
  color: var(--text-3);
  cursor: not-allowed;
}

.input-sm {
  height: 28px;
  font-size: var(--text-xs);
}

.textarea {
  height: auto;
  min-height: 88px;
  padding-block: 8px;
  resize: vertical;
  line-height: var(--leading-ui);
}

.select {
  appearance: none;
  padding-inline-end: 28px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center right 8px;
  background-size: 14px;
  cursor: pointer;
}
[dir="rtl"] .select {
  background-position: center left 8px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.input-affix {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.input-affix .input {
  padding-inline-start: 32px;
}
.input-affix > svg {
  position: absolute;
  inset-inline-start: 10px;
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}
.input-affix .input-toggle {
  position: absolute;
  inset-inline-end: 4px;
}

.checkbox,
.radio {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition: background-color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.radio {
  border-radius: 50%;
}
.checkbox::after {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform var(--motion-fast) var(--ease);
  background-color: var(--brand-contrast);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.checkbox:checked,
.checkbox:indeterminate {
  background: var(--brand);
  border-color: var(--brand);
}
.checkbox:checked::after {
  transform: scale(1);
}
.radio::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transform: scale(0);
  transition: transform var(--motion-fast) var(--ease);
  background: var(--brand-contrast);
}
.radio:checked {
  background: var(--brand);
  border-color: var(--brand);
}
.radio:checked::after {
  transform: scale(1);
}
.checkbox:focus-visible,
.radio:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  cursor: pointer;
  padding-block: 2px;
}
.checkbox-row .checkbox,
.checkbox-row .radio {
  margin-block-start: 2px;
}

.switch {
  appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color var(--motion) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: var(--shadow-1);
  transition: transform var(--motion) var(--ease);
}
.switch:checked {
  background: var(--brand);
}
.switch:checked::after {
  transform: translateX(14px);
}
[dir="rtl"] .switch:checked::after {
  transform: translateX(-14px);
}
.switch:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-grid .field + .field {
  margin-block-start: 0;
}
.span-2 {
  grid-column: span 2;
}
@media (max-width: 640px) {
  .span-2 { grid-column: span 1; }
}

/* ---------- surfaces ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  min-width: 0;
}
.card--raised {
  box-shadow: var(--shadow-1);
}
.card--flush {
  padding: 0;
}
.card--interactive {
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease),
              transform var(--motion-fast) var(--ease);
}
.card--interactive:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-1);
}
.card--interactive:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-block-end: var(--sp-3);
  min-width: 0;
}
.card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  margin: 0;
}
.card-sub {
  font-size: var(--text-xs);
  color: var(--text-2);
  margin: 0;
}
.card-body {
  min-width: 0;
}
.card-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-block-start: var(--sp-3);
}
.card-grid {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card-stat {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.panel {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--sp-3);
}

.divider {
  height: 1px;
  border: 0;
  background: var(--border);
  margin-block: var(--sp-3);
}
.divider-v {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin-inline: var(--sp-1);
}

/* ---------- chips, avatars, badges, kbd -------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding-inline: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  max-width: 100%;
}
.chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip--brand {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand);
}
.chip--button {
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.chip--button:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.chip--button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.chip--active {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand);
}
.chip--sm {
  height: 19px;
  font-size: 11px;
  padding-inline: 7px;
}

.chip-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.avatar {
  --avatar-size: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: calc(var(--avatar-size) * 0.4);
  font-weight: var(--weight-semibold);
  line-height: 1;
  overflow: hidden;
  user-select: none;
  letter-spacing: 0;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar--square {
  border-radius: var(--radius-sm);
}
.avatar--ring {
  box-shadow: 0 0 0 2px var(--surface);
}
.avatar-stack {
  display: inline-flex;
  align-items: center;
  flex-direction: row;
}
.avatar-stack .avatar + .avatar {
  margin-inline-start: -7px;
}
.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--surface);
}
.avatar-stack .avatar-more {
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding-inline: 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  line-height: 1;
}
.badge svg {
  width: 11px;
  height: 11px;
}
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge--dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border: 1px solid var(--border);
  border-block-end-color: var(--border-strong);
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1;
  white-space: nowrap;
}

.counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 10.5px;
  font-weight: var(--weight-semibold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.counter--muted {
  background: var(--surface-active);
  color: var(--text-2);
}
.counter--dot {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  background: var(--brand);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
}
.dot--online {
  background: var(--success);
}
.dot--pulse {
  animation: nv-pulse-dot 2.4s var(--ease) infinite;
}

/* ---------- tabs -------------------------------------------------------- */

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-block-end: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding-inline: 10px;
  margin-block-end: -1px;
  border-block-end: 2px solid transparent;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition: color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--text);
  border-block-end-color: var(--brand);
}
.tab:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
.tab .counter {
  height: 16px;
  min-width: 16px;
  font-size: 10px;
}

.tab-panel {
  padding-block-start: var(--sp-4);
}
.tab-panel[hidden] {
  display: none;
}

/* ---------- toolbar ----------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  min-height: 44px;
  padding-block: var(--sp-2);
}
.toolbar-end {
  margin-inline-start: auto;
}
.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin-inline: 4px;
}

/* ---------- tables ------------------------------------------------------ */

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  max-height: 100%;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}
.table th {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  padding: 9px 12px;
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-align: start;
  white-space: nowrap;
}
.table th[data-align="end"],
.table td[data-align="end"] {
  text-align: end;
}
.table th[data-align="center"],
.table td[data-align="center"] {
  text-align: center;
}
.table td {
  padding: 10px 12px;
  border-block-end: 1px solid var(--border-soft);
  vertical-align: middle;
  color: var(--text);
}
.table tbody tr:last-child td {
  border-block-end: 0;
}
.table tbody tr {
  transition: background-color var(--motion-fast) var(--ease);
}
.table tbody tr:hover {
  background: var(--surface-hover);
}
.table tbody tr[aria-selected="true"] {
  background: var(--brand-soft);
}
.table .cell-strong {
  font-weight: var(--weight-medium);
}
.table .cell-muted {
  color: var(--text-2);
}
.table .cell-actions {
  width: 1%;
  white-space: nowrap;
  text-align: end;
}
.table-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  font: inherit;
  padding: 0;
  border-radius: var(--radius-sm);
}
.table-sort:hover {
  color: var(--text);
}
.table-sort:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.table-sort svg {
  width: 12px;
  height: 12px;
  opacity: .6;
}
.table-empty {
  padding: 0;
}

/* ---------- kanban ------------------------------------------------------ */

.kanban {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  overflow-x: auto;
  padding-block-end: var(--sp-3);
  min-height: 200px;
  scroll-snap-type: x proximity;
}
.kanban-column {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: 280px;
  flex: 0 0 280px;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-3);
  scroll-snap-align: start;
  max-height: 100%;
}
.kanban-column-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 2px 4px 6px;
  min-height: 28px;
}
.kanban-column-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
  min-width: 0;
}
.kanban-column-count {
  margin-inline-start: 2px;
  font-size: var(--text-xs);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.kanban-column-actions {
  margin-inline-start: auto;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--motion-fast) var(--ease);
}
.kanban-column:hover .kanban-column-actions,
.kanban-column:focus-within .kanban-column-actions {
  opacity: 1;
}
.kanban-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
  overflow-y: auto;
}
.kanban-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  cursor: grab;
  transition: border-color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease),
              transform var(--motion-fast) var(--ease),
              opacity var(--motion-fast) var(--ease);
}
.kanban-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}
.kanban-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.kanban-card[aria-grabbed="true"] {
  opacity: .45;
}
.kanban-card--dragging {
  opacity: .4;
  cursor: grabbing;
}
.kanban-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  color: var(--text);
}
.kanban-placeholder {
  border: 1px dashed var(--brand-ring);
  background: var(--brand-softer);
  border-radius: var(--radius-sm);
  min-height: 44px;
  pointer-events: none;
}
.kanban-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: var(--text-xs);
  text-align: center;
}

/* ---------- list rows --------------------------------------------------- */

.list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.list-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-sm);
  transition: background-color var(--motion-fast) var(--ease);
  text-align: start;
}
.list-row--interactive {
  cursor: pointer;
}
.list-row--interactive:hover {
  background: var(--surface-hover);
}
.list-row--interactive:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.list-row[aria-selected="true"],
.list-row--active {
  background: var(--brand-soft);
  color: var(--brand);
}
.list-row-meta {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-3);
  font-size: var(--text-xs);
  flex-shrink: 0;
}
.list-group-label {
  padding: 10px 10px 4px;
  font-size: 10.5px;
  font-weight: var(--weight-semibold);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}
html[lang="fa"] .list-group-label {
  letter-spacing: 0;
  text-transform: none;
}

/* ---------- overlays: scrim, modal, drawer, toast, popover, menu -------- */

.ovl {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal);
  animation: nv-fade-in var(--motion-fast) var(--ease);
}
.ovl--drawer {
  z-index: calc(var(--z-drawer) - 1);
}

/* modal is rendered inside .ovl; this block keeps standalone use safe */
.modal {
  position: fixed;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100vw - 32px));
  max-height: min(calc(100vh - 64px), 760px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-3);
  animation: nv-pop-in var(--motion) var(--ease-out);
  overflow: hidden;
}
[dir="rtl"] .modal {
  transform: translate(50%, -50%);
}
.modal--sm { width: min(420px, calc(100vw - 32px)); }
.modal--lg { width: min(760px, calc(100vw - 32px)); }
.modal--full { width: min(960px, calc(100vw - 32px)); }

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-block-end: 1px solid var(--border);
}
.modal-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: 1.4;
  margin: 0;
  min-width: 0;
}
.modal-desc {
  margin-block-start: 2px;
  font-size: var(--text-sm);
  color: var(--text-2);
  line-height: var(--leading-ui);
}
.modal-close {
  margin-inline-start: auto;
  flex-shrink: 0;
}
.modal-body {
  padding: var(--sp-4);
  overflow-y: auto;
  min-height: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-block-start: 1px solid var(--border);
  background: var(--surface);
}
.modal-foot--split {
  justify-content: space-between;
}

/* drawer */
.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  width: var(--drawer-w);
  max-width: 100vw;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  animation: nv-slide-in-end var(--motion-slow) var(--ease-out);
  --slide-from: 100%;
}
[dir="rtl"] .drawer {
  --slide-from: -100%;
}
.drawer-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-block-end: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.drawer-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  margin: 0;
  min-width: 0;
}
.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--sp-4);
  min-height: 0;
}
.drawer-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-block-start: 1px solid var(--border);
  background: var(--surface);
}
@media (max-width: 640px) {
  .drawer {
    inset-inline: 0;
    width: 100vw;
    border-inline-start: 0;
  }
  .modal {
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    max-height: 100%;
    inset: 0;
    transform: none;
    border-radius: 0;
    border: 0;
  }
  [dir="rtl"] .modal {
    transform: none;
  }
  .modal-body {
    flex: 1 1 auto;
  }
}

/* toast */
.toast-stack {
  position: fixed;
  inset-block-end: var(--sp-4);
  inset-inline-end: var(--sp-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px 10px 10px 12px;
  padding-inline-start: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
  color: var(--text);
  pointer-events: auto;
  animation: nv-slide-up var(--motion-slow) var(--ease-out);
  overflow: hidden;
}
.toast::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 3px;
  background: var(--info);
}
.toast-icon {
  margin-block-start: 1px;
  color: var(--info);
  flex-shrink: 0;
}
.toast-icon svg {
  width: 16px;
  height: 16px;
}
.toast-msg {
  flex: 1 1 auto;
  min-width: 0;
  padding-block-start: 1px;
  word-break: break-word;
}
.toast-close {
  flex-shrink: 0;
  margin-block-start: -2px;
}
.toast--success::before { background: var(--success); }
.toast--success .toast-icon { color: var(--success); }
.toast--warning::before { background: var(--warning); }
.toast--warning .toast-icon { color: var(--warning); }
.toast--danger::before { background: var(--danger); }
.toast--danger .toast-icon { color: var(--danger); }

/* popover & menu */
.popover {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 200px;
  max-width: min(380px, calc(100vw - 16px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  animation: nv-pop-in var(--motion-fast) var(--ease-out);
  overflow: hidden;
}
.popover-body {
  padding: var(--sp-3);
}

.menu {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 208px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(420px, calc(100vh - 24px));
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  animation: nv-pop-in var(--motion-fast) var(--ease-out);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-sm);
  text-align: start;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease),
              color var(--motion-fast) var(--ease);
}
.menu-item:hover,
.menu-item:hover:not([aria-disabled="true"]) {
  background: var(--surface-hover);
}
.menu-item:focus-visible {
  outline: none;
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 1px var(--brand-ring);
}
.menu-item[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
}
.menu-item svg {
  width: 15px;
  height: 15px;
  color: var(--text-2);
  flex-shrink: 0;
}
.menu-item-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-item[data-danger="true"] {
  color: var(--danger);
}
.menu-item[data-danger="true"] svg {
  color: var(--danger);
}
.menu-item[data-danger="true"]:hover {
  background: var(--danger-soft);
}
.menu-item kbd,
.menu-item .kbd {
  margin-inline-start: auto;
  flex-shrink: 0;
}
.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border-soft);
}
.menu-label {
  padding: 8px 8px 4px;
  font-size: 10.5px;
  font-weight: var(--weight-semibold);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}
html[lang="fa"] .menu-label {
  letter-spacing: 0;
  text-transform: none;
}

/* tooltip */
.tooltip {
  position: fixed;
  z-index: var(--z-popover);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--ink-1);
  color: #FFFFFF;
  font-size: var(--text-xs);
  line-height: 1.45;
  pointer-events: none;
  max-width: 240px;
  box-shadow: var(--shadow-2);
  animation: nv-fade-in var(--motion-fast) var(--ease);
}
html[data-theme="dark"] .tooltip {
  background: var(--surface-3);
  color: var(--text);
}

/* ---------- empty, skeleton, loading ----------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-5);
  min-height: 200px;
  color: var(--text-2);
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-block-end: var(--sp-1);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-2);
}
.empty-icon svg {
  width: 20px;
  height: 20px;
}
.empty-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text);
  line-height: 1.4;
}
.empty-text {
  font-size: var(--text-sm);
  color: var(--text-2);
  max-width: 46ch;
  line-height: var(--leading-ui);
}
.empty-action {
  margin-block-start: var(--sp-2);
}
.empty--compact {
  padding: var(--sp-5) var(--sp-4);
  min-height: 120px;
}

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    var(--surface-3) 25%,
    var(--surface-hover) 37%,
    var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: nv-shimmer 1.4s ease infinite;
}
.skeleton--text {
  height: 11px;
}
.skeleton--title {
  height: 15px;
}
.skeleton--block {
  height: 64px;
}
.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: var(--sp-3);
}
.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.skeleton-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- progress --------------------------------------------------- */

.progress {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-active);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width var(--motion-slow) var(--ease);
}
.progress--success .progress-fill { background: var(--success); }
.progress--warning .progress-fill { background: var(--warning); }
.progress--danger .progress-fill { background: var(--danger); }
.progress--sm { height: 4px; }

/* ---------- upload ----------------------------------------------------- */

.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--sp-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-input);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-sm);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease),
              background-color var(--motion-fast) var(--ease),
              color var(--motion-fast) var(--ease);
}
.upload:hover,
.upload:focus-visible {
  border-color: var(--brand-ring);
  background: var(--brand-softer);
  color: var(--text);
  outline: none;
}
.upload--over {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}
.upload-hint {
  font-size: var(--text-xs);
  color: var(--text-3);
}
.upload-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-block-start: var(--sp-2);
  width: 100%;
}
.upload-file {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-xs);
  text-align: start;
}
.upload-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-file-size {
  margin-inline-start: auto;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- charts ----------------------------------------------------- */

.chart {
  width: 100%;
  min-width: 0;
}
.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
/* Chart geometry is laid out left-to-right even inside an RTL document;
   bidi still shapes Persian labels correctly. */
.chart svg text {
  direction: ltr;
  unicode-bidi: isolate;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-block-start: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-2);
}
.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chart-legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ---------- misc ------------------------------------------------------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface-3);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
  color: var(--text-2);
}
.banner--info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.banner--warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.banner--danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.banner--success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.banner svg { width: 15px; height: 15px; flex-shrink: 0; margin-block-start: 1px; }

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface-3);
}
.segmented-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding-inline: 9px;
  border-radius: 6px;
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.segmented-item:hover { color: var(--text); }
.segmented-item[aria-pressed="true"],
.segmented-item[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.segmented-item:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.segmented-item svg { width: 14px; height: 14px; }

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.help-text {
  font-size: var(--text-xs);
  color: var(--text-2);
  line-height: 1.55;
}

.key-value {
  display: grid;
  grid-template-columns: minmax(90px, max-content) 1fr;
  gap: 6px var(--sp-4);
  font-size: var(--text-sm);
}
.key-value dt {
  color: var(--text-2);
}
.key-value dd {
  margin: 0;
  min-width: 0;
}

.scroll-y {
  overflow-y: auto;
  min-height: 0;
}
.scroll-x {
  overflow-x: auto;
  min-height: 0;
}

/* ---------- date picker (ndp) ------------------------------------------- */
.ndp {
  position: relative;
}

.ndp-trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  text-align: start;
  cursor: pointer;
}
.ndp-trigger[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}
.ndp-trigger svg {
  flex: 0 0 auto;
  color: var(--text-3);
}
.ndp-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ndp-label--empty {
  color: var(--text-3);
}

.ndp-pop {
  position: fixed;
  z-index: var(--z-popover);
  width: 292px;
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  animation: nv-pop-in var(--motion-fast) var(--ease-out);
}

.ndp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
}
.ndp-title {
  flex: 1 1 auto;
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
}
.ndp-nav {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease),
    color var(--motion-fast) var(--ease);
}
.ndp-nav:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.ndp-nav:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--brand-ring);
}

.ndp-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 2px;
}
.ndp-week span {
  padding: 4px 0;
  text-align: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-3);
}

.ndp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.ndp-day {
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease),
    color var(--motion-fast) var(--ease);
}
.ndp-day:hover {
  background: var(--surface-hover);
}
.ndp-day:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--brand-ring);
}
.ndp-day--out {
  color: var(--text-3);
  opacity: 0.65;
}
.ndp-day--today {
  box-shadow: inset 0 0 0 1px var(--border-strong);
  font-weight: var(--weight-semibold);
}
.ndp-day--sel,
.ndp-day--sel:hover {
  background: var(--brand);
  color: var(--brand-contrast);
  font-weight: var(--weight-semibold);
}

.ndp-foot {
  display: flex;
  gap: var(--sp-2);
  justify-content: space-between;
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: var(--hairline);
}
.ndp-foot-btn {
  flex: 1 1 auto;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease),
    color var(--motion-fast) var(--ease);
}
.ndp-foot-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.ndp-foot-btn--muted {
  color: var(--text-3);
}
