/* ==========================================================================
   Components: buttons, fields, surfaces, status, tables, toast, dialog,
   skeleton, empty/error states, progress ring + meter, ripple
   ========================================================================== */

/* ---- Buttons ---- */
.primary,
.ghost-btn,
.save-mini,
.lang-switch {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--r-sm);
  font: 600 var(--fs-sm) / 1 var(--font-display);
  white-space: nowrap;
  user-select: none;
  transition:
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-base) var(--ease-out),
    background-color var(--t-base) var(--ease-out),
    border-color var(--t-base) var(--ease-out),
    color var(--t-base) var(--ease-out);
}
.primary {
  color: #fff;
  background: var(--grad-brand);
  box-shadow: var(--sh-brand);
}
.primary:hover:not(:disabled) {
  background: var(--grad-brand-hover);
  box-shadow: 0 12px 28px rgb(10 134 173 / 0.42);
  transform: translateY(-2px);
}
.primary:active:not(:disabled),
.ghost-btn:active:not(:disabled),
.save-mini:active:not(:disabled),
.choice:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
}
.primary.wide {
  width: 100%;
  min-height: 52px;
  font-size: var(--fs-md);
}
.primary b {
  display: inline-block;
  transition: transform var(--t-base) var(--ease-out);
}
html[dir='rtl'] .primary:hover b {
  transform: translateX(-4px);
}
html[dir='ltr'] .primary:hover b {
  transform: translateX(4px);
}
.ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  color: var(--ink-700);
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
}
.ghost-btn:hover:not(:disabled) {
  border-color: var(--aqua-400);
  background: var(--aqua-50);
  color: var(--aqua-700);
  transform: translateY(-1px);
  box-shadow: var(--sh-1);
}
.ghost-btn.active {
  color: #fff;
  background: var(--ink-900);
  border-color: var(--ink-900);
}
.ghost-btn.active:hover {
  background: var(--ink-800);
  color: #fff;
}
.save-mini {
  min-height: 40px;
  padding: 0 14px;
  color: var(--aqua-700);
  background: var(--aqua-50);
  border: 1px solid var(--aqua-200);
}
.save-mini:hover:not(:disabled) {
  color: #fff;
  background: var(--grad-brand);
  border-color: transparent;
  box-shadow: var(--sh-brand);
}
.lang-switch {
  min-height: 40px;
  padding: 0 14px;
  color: var(--aqua-700);
  background: var(--aqua-50);
  border: 1px solid var(--aqua-200);
}
.lang-switch:hover {
  background: var(--aqua-100);
}
.btn-busy {
  pointer-events: none;
  color: transparent !important;
}
.btn-busy::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgb(255 255 255 / 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.ghost-btn.btn-busy::after,
.save-mini.btn-busy::after {
  border-color: var(--aqua-200);
  border-top-color: var(--aqua-600);
}
.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.22;
  transform: scale(0);
  pointer-events: none;
  animation: ripple 0.6s var(--ease-out) forwards;
}

/* ---- Fields ---- */
input:not([type='checkbox'], [type='radio'], [type='file']),
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  transition:
    border-color var(--t-base) var(--ease-out),
    box-shadow var(--t-base) var(--ease-out),
    background-color var(--t-base) var(--ease-out);
}
input::placeholder,
textarea::placeholder {
  color: var(--ink-300);
}
input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--aqua-400);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--aqua-500);
  box-shadow: var(--focus);
  outline: none;
}
input:disabled,
select:disabled {
  background: var(--ink-50);
  color: var(--ink-400);
}
select {
  appearance: none;
  padding-inline-end: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2355788a' stroke-width='2.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-size: 16px;
  background-position: left 13px center;
}
html[dir='ltr'] select {
  background-position: right 13px center;
}
textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}
input[type='file'] {
  width: 100%;
  padding: 8px;
  border: 1.5px dashed var(--aqua-200);
  border-radius: var(--r-sm);
  background: var(--aqua-50);
  color: var(--ink-600);
  font-size: var(--fs-sm);
  cursor: pointer;
}
input[type='file']::file-selector-button {
  margin-inline-end: 10px;
  padding: 7px 12px;
  border: 0;
  border-radius: var(--r-xs);
  background: var(--grad-brand);
  color: #fff;
  font: 600 var(--fs-xs) var(--font-display);
  cursor: pointer;
}
input[type='number'] {
  font-family: var(--font-display);
}
.control {
  min-height: 42px;
}
.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}
.field label,
.control-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-600);
}
.control-label {
  display: grid;
  gap: 6px;
}

/* ---- Surfaces ---- */
.surface {
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
}

/* ---- Status pills ---- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  font: 600 var(--fs-xs) / 1.4 var(--font-display);
  white-space: nowrap;
  color: var(--ink-600);
  background: var(--ink-100);
}
.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-pill.done {
  color: var(--mint-700);
  background: var(--mint-100);
}
.status-pill.issue {
  color: var(--coral-700);
  background: var(--coral-100);
}
.status-pill.na {
  color: var(--ink-500);
  background: var(--ink-100);
}

/* ---- Tables ---- */
.table-scroll,
.activity-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.activity-table {
  min-width: 560px;
}
.activity-table th {
  position: sticky;
  top: 0;
  padding: 14px 18px;
  text-align: start;
  font: 500 var(--fs-xs) / 1.4 var(--font-display);
  color: var(--ink-500);
  background: rgb(243 247 250 / 0.9);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.activity-table td {
  padding: 14px 18px;
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.activity-table tbody tr {
  transition: background-color var(--t-fast);
}
.activity-table tbody tr:hover {
  background: var(--aqua-50);
}
.activity-table tbody tr:last-child td {
  border-bottom: 0;
}
.activity-table td:first-child b {
  font-weight: 600;
}
.brand-thumb {
  width: 44px;
  height: 44px;
  object-fit: contain;
  padding: 4px;
  border-radius: var(--r-sm);
  background: var(--ink-50);
  border: 1px solid var(--line);
}

/* ---- Toast ---- */
#toast {
  position: fixed;
  z-index: 90;
  inset-block-end: 24px;
  inset-inline-end: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 13px 18px 13px 16px;
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 500;
  border-radius: var(--r-md);
  background: var(--ink-900);
  box-shadow: var(--sh-3);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition:
    opacity var(--t-base) var(--ease-out),
    transform var(--t-base) var(--ease-spring);
}
#toast.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
#toast .toast-ico {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--mint-500);
}
#toast.error .toast-ico {
  background: var(--coral-500);
}
#toast .toast-ico .ico {
  width: 16px;
  height: 16px;
  stroke-width: 2.6;
}
#toast::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  height: 3px;
  background: var(--mint-500);
  transform-origin: right;
  transform: scaleX(0);
}
#toast.error::after {
  background: var(--coral-500);
}
#toast.show::after {
  animation: toastBar var(--toast-ms, 3500ms) linear forwards;
}
@keyframes toastBar {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

/* ---- Dialog ---- */
.dialog-shade {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(6 28 39 / 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn var(--t-base) ease both;
}
.dialog-shade.closing {
  animation: fadeOut 160ms ease both;
}
.dialog-shade.closing .dialog {
  animation: dialogOut 160ms ease both;
}
.dialog {
  width: min(480px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  display: grid;
  gap: 14px;
  padding: 26px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  animation: dialogIn var(--t-slow) var(--ease-spring) both;
}
.dialog h3 {
  font-size: var(--fs-xl);
}
.dialog p {
  color: var(--text-soft);
  font-size: var(--fs-sm);
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 6px;
}
html[dir='rtl'] .dialog-actions {
  justify-content: flex-start;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
}
@keyframes fadeOut {
  to {
    opacity: 0;
  }
}
@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }
}
@keyframes dialogOut {
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

/* ---- Skeleton loading ---- */
.skeleton {
  display: block;
  border-radius: var(--r-sm);
  background: linear-gradient(100deg, var(--ink-100) 30%, var(--ink-50) 50%, var(--ink-100) 70%) 0 0 / 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.sk-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.sk-card {
  display: grid;
  gap: 12px;
  padding: 22px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.sk-rows {
  display: grid;
  gap: 1px;
  padding: 10px 20px;
}
.sk-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
}
.sk-row .skeleton:first-child {
  width: 38px;
  height: 38px;
  border-radius: 50%;
}

/* ---- Empty / error states ---- */
.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 44px 24px;
  text-align: center;
  color: var(--text-soft);
  font-size: var(--fs-sm);
}
.empty-state .empty-art {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-bottom: 6px;
  border-radius: 24px;
  color: var(--aqua-600);
  background: linear-gradient(145deg, var(--aqua-100), var(--aqua-50));
  box-shadow: inset 0 0 0 1px var(--aqua-200);
}
.empty-state .empty-art .ico {
  width: 34px;
  height: 34px;
  stroke-width: 1.5;
}
.empty-state.error .empty-art {
  color: var(--coral-500);
  background: linear-gradient(145deg, var(--coral-100), #fff4f2);
  box-shadow: inset 0 0 0 1px rgb(234 93 79 / 0.25);
}
.empty-state h4 {
  color: var(--text);
  font-size: var(--fs-lg);
}
.empty-state p {
  max-width: 42ch;
}
.empty-state .ghost-btn,
.empty-state .primary {
  margin-top: 10px;
}

/* ---- Progress ring (one memorable detail: compliance at a glance) ---- */
.ring {
  --size: 64px;
  --stroke: 7px;
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: conic-gradient(var(--ring-color, var(--mint-500)) calc(var(--p) * 1%), var(--ink-100) 0);
  transition: --p 1s var(--ease-out);
}
.ring::before {
  content: '';
  position: absolute;
  inset: var(--stroke);
  border-radius: 50%;
  background: var(--surface);
}
.ring b {
  position: relative;
  font: 600 var(--fs-sm) / 1 var(--font-display);
  color: var(--ink-900);
}
.ring b i {
  font-style: normal;
  font-size: 0.7em;
  opacity: 0.6;
}

/* ---- Meter (thin progress bar) ---- */
.progress-line {
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--ink-100);
  overflow: hidden;
}
.progress-line i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint-500), #5fdcb0);
  transform-origin: right;
  animation: grow 0.9s var(--ease-out) both;
}
html[dir='ltr'] .progress-line i {
  transform-origin: left;
}
@keyframes grow {
  from {
    transform: scaleX(0);
  }
}
