/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-h);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur), border-color var(--dur), color var(--dur), box-shadow var(--dur);
}

.btn svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-danger-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-bg);
}

.btn-sm {
  height: var(--btn-h-sm);
  padding: 0 10px;
  font-size: var(--fs-xs);
}

.btn-block {
  width: 100%;
}

.btn.is-loading svg {
  animation: spin 0.8s linear infinite;
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--color-text-2);
  transition: background-color var(--dur), color var(--dur);
}

.icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.link {
  color: var(--color-primary);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.link:hover {
  text-decoration: underline;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-text-2);
}

.field .optional {
  color: var(--color-faint);
  font-weight: 400;
}

.input,
.select {
  height: var(--input-h);
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: var(--fs-base);
  color: var(--color-text);
  transition: border-color var(--dur), box-shadow var(--dur);
}

.input::placeholder {
  color: var(--color-faint);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.input[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--color-danger);
}

.input[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.18);
}

.input:disabled,
.select:disabled {
  background: var(--color-surface-2);
  color: var(--color-muted);
  cursor: not-allowed;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  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='%236b7484' 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: right 10px center;
  padding-right: 32px;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-right: 44px;
}

.input-group .input-prefix {
  position: absolute;
  left: 10px;
  color: var(--color-muted);
  font-size: var(--fs-sm);
  pointer-events: none;
}

.input-group.has-prefix .input {
  padding-left: 28px;
}

.input-group .input-icon {
  position: absolute;
  left: 10px;
  color: var(--color-faint);
  pointer-events: none;
  display: flex;
}

.input-group .input-icon svg {
  width: 15px;
  height: 15px;
}

.input-group.has-icon .input {
  padding-left: 32px;
}

.input-group .input-action {
  position: absolute;
  right: 4px;
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  color: var(--color-text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.input-group .input-action:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.input-group .input-action svg {
  width: 16px;
  height: 16px;
}

.field-error {
  font-size: var(--fs-xs);
  color: var(--color-danger);
}

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

.form-alert,
.alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  border: 1px solid;
}

.form-alert svg,
.alert svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 1px;
}

.alert-error {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
  color: var(--color-danger);
}

.alert-warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
  color: var(--color-warning);
}

.alert-info {
  background: var(--color-info-bg);
  border-color: var(--color-info-border);
  color: var(--color-info);
}

.alert-success {
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
  color: var(--color-success);
}

.alert-title {
  font-weight: 600;
  display: block;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--card-pad);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.card-title {
  font-size: var(--fs-md);
  font-weight: 600;
}

.card-desc {
  font-size: var(--fs-sm);
  color: var(--color-muted);
  margin-top: 2px;
}

.card-flush {
  padding: 0;
}

.card-flush .card-header {
  padding: var(--card-pad) var(--card-pad) 0;
}

/* Stats */
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat-value {
  font-size: var(--fs-stat);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

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

.stat-primary .stat-value {
  color: var(--color-primary);
}

/* Key / value list */
.kv {
  display: flex;
  flex-direction: column;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding: 9px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-sm);
}

.kv-row:first-child {
  padding-top: 0;
}

.kv-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.kv-row dt {
  color: var(--color-muted);
  flex: none;
}

.kv-row dd {
  font-weight: 500;
  text-align: right;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card .table-wrap {
  margin: 0 calc(var(--card-pad) * -1) calc(var(--card-pad) * -1);
}

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

.card .table-wrap .table tbody tr:last-child td {
  border-bottom: 0;
}

.table {
  width: 100%;
  font-size: var(--fs-sm);
}

.table th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--color-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  background: var(--color-surface-2);
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.table tbody tr:hover td {
  background: var(--color-surface-2);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table .cell-strong {
  font-weight: 500;
  color: var(--color-text);
}

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

.table .cell-sub {
  font-size: var(--fs-xs);
  color: var(--color-muted);
  margin-top: 1px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table td:first-child,
.table th:first-child {
  padding-left: var(--card-pad);
}

.table td:last-child,
.table th:last-child {
  padding-right: var(--card-pad);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 500;
  border: 1px solid;
  white-space: nowrap;
}

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

.badge-success {
  color: var(--color-success);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}

.badge-neutral {
  color: var(--color-text-2);
  background: var(--color-surface-2);
  border-color: var(--color-border);
}

.badge-warning {
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

/* Grant cards (mobile) */
.grant-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.grant-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-surface);
}

.grant-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.grant-card-title {
  font-weight: 500;
  font-size: var(--fs-base);
}

.grant-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.grant-card-grid dt {
  font-size: 11px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.grant-card-grid dd {
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Segmented control / language toggle */
.segmented,
.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  padding: 2px;
  gap: 2px;
}

.segmented button,
.lang-toggle button {
  height: 26px;
  padding: 0 10px;
  border-radius: 4px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--color-text-2);
  transition: background-color var(--dur), color var(--dur);
}

.segmented button:hover,
.lang-toggle button:hover {
  color: var(--color-text);
}

.segmented button.is-active,
.lang-toggle button.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.segmented button:focus-visible,
.lang-toggle button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

@media (max-width: 900px) {
  .segmented button,
  .lang-toggle button {
    min-height: 30px;
  }
}

/* Empty states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 28px 16px;
  gap: 6px;
}

.empty img,
.empty svg {
  width: 36px;
  height: 36px;
  margin-bottom: 6px;
}

.empty-title {
  font-size: var(--fs-md);
  font-weight: 600;
}

.empty-text {
  font-size: var(--fs-sm);
  color: var(--color-muted);
  max-width: 380px;
}

.empty .btn {
  margin-top: 8px;
}

/* Skeletons */
.skeleton {
  position: relative;
  overflow: hidden;
  background: #e8ebf0;
  border-radius: 4px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

.sk-line {
  height: 12px;
  margin-bottom: 10px;
}

.sk-line:last-child {
  margin-bottom: 0;
}

.sk-title {
  height: 16px;
  width: 35%;
  margin-bottom: 14px;
}

.sk-stat {
  height: 24px;
  width: 55%;
  margin: 8px 0 6px;
}

.w-20 {
  width: 20%;
}

.w-30 {
  width: 30%;
}

.w-40 {
  width: 40%;
}

.w-60 {
  width: 60%;
}

.w-80 {
  width: 80%;
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 340px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-info);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: var(--fs-sm);
  color: var(--color-text);
  animation: toast-in var(--dur) var(--ease);
}

.toast-icon {
  display: flex;
  color: var(--color-info);
}

.toast-icon svg {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.toast-success {
  border-left-color: var(--color-success);
}

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

.toast-error {
  border-left-color: var(--color-danger);
}

.toast-error .toast-icon {
  color: var(--color-danger);
}

.toast-warning {
  border-left-color: var(--color-warning);
}

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

.toast-msg {
  flex: 1;
}

.toast-close {
  color: var(--color-faint);
  margin: -2px -4px 0 0;
  padding: 3px;
  border-radius: 4px;
  display: flex;
}

.toast-close:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.toast-close svg {
  width: 14px;
  height: 14px;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur), transform var(--dur);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 560px) {
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-width: none;
  }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in var(--dur);
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  animation: modal-in var(--dur) var(--ease);
}

.modal-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.modal-icon svg {
  width: 20px;
  height: 20px;
}

.modal-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: 6px;
}

.modal-message {
  font-size: var(--fs-sm);
  color: var(--color-text-2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* Utilities */
.muted {
  color: var(--color-muted);
}

.small {
  font-size: var(--fs-xs);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.text-right {
  text-align: right;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
