/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.1s, box-shadow 0.16s;
}

.btn:hover {
  background: var(--card-soft);
  border-color: var(--line-strong);
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, #000);
  border-color: transparent;
}

.btn-soft {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-ink);
}

.btn-soft:hover {
  background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent));
  border-color: transparent;
}

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

.btn-ghost:hover {
  background: var(--hover);
  border-color: transparent;
  color: var(--ink);
}

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

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 86%, #000);
  border-color: transparent;
}

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

.btn-sm {
  height: 32px;
  padding: 0 11px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-lg {
  height: 44px;
  padding: 0 20px;
  font-size: 14.5px;
  border-radius: 11px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 38px;
  padding: 0;
  flex: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--ink);
}

.icon-btn.is-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------- forms ---------- */
.field {
  display: block;
  margin-bottom: 15px;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
}

.field-hint {
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.input {
  height: 38px;
  padding-top: 0;
  padding-bottom: 0;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.textarea {
  min-height: 110px;
  line-height: 1.6;
  resize: vertical;
}

.select {
  height: 38px;
  padding-top: 0;
  padding-bottom: 0;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2391847b' 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 12px center;
  padding-right: 32px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-wrap {
  position: relative;
}

.input-wrap .input {
  padding-right: 40px;
}

.input-wrap .icon-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
}

input[type='color'] {
  appearance: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: none;
  cursor: pointer;
}

input[type='color']::-webkit-color-swatch-wrapper {
  padding: 3px;
}

input[type='color']::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

/* ---------- segmented / tabs ---------- */
.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-active {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 33px;
  padding: 0 13px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
}

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

.tab.is-active {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.tab.is-active .tab-count {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------- menus ---------- */
.menu {
  position: relative;
  display: inline-block;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 60;
  min-width: 208px;
  padding: 5px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 44px -18px rgba(40, 25, 15, 0.35), var(--shadow-sm);
  animation: menu-in 0.14s ease both;
}

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

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.menu-item:hover {
  background: var(--hover);
  color: var(--ink);
}

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

.menu-item.is-danger:hover {
  background: var(--danger-soft);
}

.menu-item .icon {
  color: var(--muted);
}

.menu-item.is-danger .icon {
  color: currentColor;
}

.menu-sep {
  height: 1px;
  margin: 5px 6px;
  background: var(--line);
}

.menu-label {
  padding: 7px 10px 4px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.03em;
}

/* ---------- dialog ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100dvh - 44px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

dialog.modal.modal-wide {
  width: min(680px, calc(100vw - 28px));
}

dialog.modal::backdrop {
  background: rgba(28, 20, 15, 0.42);
  backdrop-filter: blur(3px);
  animation: backdrop-in 0.2s ease both;
}

dialog.modal[open] {
  animation: modal-in 0.24s cubic-bezier(0.2, 0.75, 0.3, 1) both;
}

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

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

.modal-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 44px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px -30px rgba(35, 20, 10, 0.45);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 22px 22px 12px;
}

.modal-head h2 {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.modal-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.modal-head .icon-btn {
  margin-left: auto;
  flex: none;
}

.modal-body {
  padding: 6px 22px 22px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-soft) 45%, var(--card));
}

.modal-foot .modal-foot-left {
  margin-right: auto;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- toast / busy ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 28px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 15px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 450;
  line-height: 1.35;
  box-shadow: 0 12px 36px -12px rgba(30, 18, 10, 0.4);
  animation: toast-in 0.24s cubic-bezier(0.2, 0.8, 0.3, 1) both;
  pointer-events: auto;
}

.toast .icon {
  color: color-mix(in srgb, var(--bg) 80%, var(--accent));
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

.toast.is-error .icon {
  color: #fff;
}

.toast.is-leaving {
  animation: toast-out 0.2s ease both;
}

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

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

.busy {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(28, 20, 15, 0.42);
  backdrop-filter: blur(4px);
}

.busy-card {
  width: min(320px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}

.busy-spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 14px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.busy-text {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
}

.busy-bar {
  height: 4px;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.busy-bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s ease;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------- badges / callouts ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--card-soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.callout {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 16%, var(--line));
  border-radius: 11px;
  background: var(--accent-faint);
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.55;
}

.callout .icon {
  margin-top: 1px;
  color: var(--accent-ink);
}

.callout-warn {
  border-color: color-mix(in srgb, var(--warn) 22%, var(--line));
  background: var(--warn-soft);
}

.callout-warn .icon {
  color: var(--warn);
}

.callout-ok {
  border-color: color-mix(in srgb, var(--ok) 22%, var(--line));
  background: var(--ok-soft);
}

.callout-ok .icon {
  color: var(--ok);
}

kbd {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  line-height: 1;
}

/* ---------- panels / empty ---------- */
.panel {
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-soft {
  background: color-mix(in srgb, var(--card-soft) 55%, var(--card));
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.panel-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.empty {
  padding: 46px 26px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--card) 55%, transparent);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.empty h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.empty p {
  max-width: 400px;
  margin: 6px auto 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- progress ---------- */
.progress {
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* ---------- dropzone ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 30px 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card-soft) 50%, var(--card));
  text-align: center;
  transition: border-color 0.16s, background 0.16s;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-faint);
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 2px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.dropzone strong {
  font-size: 13.5px;
  font-weight: 550;
}

.dropzone span {
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- misc ---------- */
.link-btn {
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
}

.link-btn:hover {
  text-decoration-color: currentColor;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card-soft);
  font-size: 11.5px;
  color: var(--muted);
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex: none;
}

@media (max-width: 600px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .modal-head {
    padding: 18px 18px 10px;
  }

  .modal-body {
    padding: 6px 18px 18px;
  }

  .modal-foot {
    padding: 12px 18px 16px;
  }

  dialog.modal {
    max-height: calc(100dvh - 20px);
  }

  .modal-card {
    max-height: calc(100dvh - 20px);
  }
}
