/* Interactive primitives: panels, buttons, toolbars, form controls, notices and
   menus. Every interactive element carries the full state set — default, hover,
   focus, active, disabled, loading.

   Data-display primitives (tables, pills, avatars, metrics, pagination) live in
   data.css, which loads alongside this file. */

/* ---------- panel ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel + .panel {
  margin-top: var(--space-4);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: 46px;
}
.panel-head h2 {
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: -0.006em;
}
.panel-head p {
  font-size: var(--text-sm);
  color: var(--ink-2);
  margin-top: 1px;
}
.panel-head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}
.panel-body {
  padding: var(--space-4);
}
.panel-foot {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

.cols {
  display: grid;
  gap: var(--space-4);
  align-items: start;
}
.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.cols-main {
  grid-template-columns: minmax(0, 1.85fr) minmax(280px, 1fr);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.btn svg {
  width: 14px;
  height: 14px;
  flex: none;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--ink-3);
}
.btn:active {
  background: var(--surface-3);
}
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-inverse);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-primary:active {
  background: var(--accent-hover);
}

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

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

.btn-sm {
  height: 26px;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
}
.btn-lg {
  height: 36px;
  padding: 0 var(--space-5);
  font-size: var(--text-base);
}

.btn.is-loading {
  color: transparent;
  pointer-events: none;
  position: relative;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 13px;
  border: 2px solid currentcolor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--ink-2);
  animation: spin 620ms linear infinite;
}
.btn-primary.is-loading::after {
  color: var(--ink-inverse);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-group {
  display: inline-flex;
}
.btn-group .btn {
  border-radius: 0;
  margin-left: -1px;
}
.btn-group .btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
  margin-left: 0;
}
.btn-group .btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}
.btn-group .btn.is-on,
.btn-group label.btn:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-ink);
  font-weight: 600;
  z-index: var(--z-base);
}
.btn-group label.btn:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
}
.toolbar-spacer {
  flex: 1;
}

.filter-input {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 180px;
}
.filter-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-input svg {
  width: 14px;
  height: 14px;
  color: var(--ink-3);
  flex: none;
}
.filter-input input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font-size: var(--text-md);
}
.filter-input input::placeholder {
  color: var(--ink-3);
}

select.select {
  height: 28px;
  padding: 0 26px 0 var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%236a6f76' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E")
    no-repeat right 7px center / 12px;
  font-size: var(--text-md);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
}
select.select:hover {
  border-color: var(--ink-3);
}
select.select:focus-visible {
  border-color: var(--accent);
}

/* ---------- forms ---------- */

.field {
  margin-bottom: var(--space-4);
}
.field:last-child {
  margin-bottom: 0;
}
.field label,
.field .label {
  display: block;
  font-size: var(--text-md);
  font-weight: 550;
  margin-bottom: 5px;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="tel"],
.field input:not([type]),
.field select,
.field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.field textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.55;
}
.field input:hover:not(:disabled),
.field textarea:hover:not(:disabled) {
  border-color: var(--ink-3);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder,
.field textarea::placeholder {
  /* 4.6:1 — placeholders are text and hold the same contrast bar as body copy. */
  color: var(--ink-3);
}
.field input:disabled,
.field select:disabled {
  background: var(--surface-3);
  color: var(--ink-3);
  cursor: not-allowed;
}
.field-hint {
  font-size: var(--text-sm);
  color: var(--ink-2);
  margin-top: 5px;
}
.field-error {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-sm);
  color: var(--danger);
  font-weight: 500;
  margin-top: 5px;
}
.field-error svg {
  width: 13px;
  height: 13px;
  flex: none;
}
.field.has-error input,
.field.has-error textarea {
  border-color: var(--danger);
}
.field.has-error input:focus,
.field.has-error textarea:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--text-md);
  color: var(--ink-2);
  cursor: pointer;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* ---------- notices ---------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid;
  border-radius: var(--radius);
  font-size: var(--text-md);
  margin-bottom: var(--space-4);
}
.notice svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 1px;
}
.notice-error {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: oklch(0.4 0.152 27);
}
.notice-ok {
  background: var(--ok-soft);
  border-color: var(--ok-line);
  color: oklch(0.4 0.09 156);
}
.notice-warn {
  background: var(--warn-soft);
  border-color: var(--warn-line);
  color: oklch(0.42 0.108 63);
}
.notice-info {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-ink);
}

/* ---------- dropdown menu ---------- */

.menu {
  position: relative;
}
.menu-panel {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  min-width: 196px;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}
.menu-panel[hidden] {
  display: none;
}
.menu-panel a,
.menu-panel button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 6px var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
}
.menu-panel a:hover,
.menu-panel button:hover {
  background: var(--surface-3);
}
.menu-panel svg {
  width: 14px;
  height: 14px;
  color: var(--ink-3);
  flex: none;
}
.menu-sep {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--border);
}
.menu-head {
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
}
.menu-head strong {
  display: block;
  font-size: var(--text-md);
}
.menu-head small {
  display: block;
  font-size: var(--text-sm);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- misc ---------- */

code.inline {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 0 4px;
  border-radius: var(--radius-sm);
}

.stack-v {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.muted {
  color: var(--ink-2);
}
.faint {
  color: var(--ink-3);
}
.nowrap {
  white-space: nowrap;
}

.menu-panel-wide {
  min-width: 296px;
}
.menu-item-stacked {
  display: block !important;
  padding: var(--space-2) !important;
  line-height: 1.45;
}
.menu-item-stacked strong {
  font-weight: 600;
}
.menu-item-stacked small {
  display: block;
  font-size: var(--text-sm);
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-item-stacked .msg-tag {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.menu-empty {
  padding: var(--space-4) var(--space-2);
  text-align: center;
  font-size: var(--text-md);
  color: var(--ink-2);
}
