* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font);
  font-synthesis: none;
}

button, input, textarea, select {
  font: inherit;
}

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-heading h1,
.panel-heading h2,
dialog h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}

input, textarea, select {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input, select {
  height: var(--btn-h);
  padding: 0 11px;
}

textarea {
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

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

input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgb(5 150 105 / 14%);
}

input[readonly] {
  color: var(--ink-soft);
  background: var(--surface-soft);
}

.button {
  display: inline-flex;
  height: var(--btn-h);
  min-height: var(--btn-h);
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

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

.button-secondary {
  color: var(--ink-soft);
  background: var(--surface-soft);
  border-color: var(--line);
}

.button-secondary:hover:not(:disabled) {
  background: var(--hover-soft);
  border-color: var(--line-strong);
}

.button-danger {
  color: var(--red);
  background: transparent;
  border-color: var(--danger-border);
}

.button-danger:hover:not(:disabled) {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.button-ghost {
  color: var(--ink-soft);
  background: transparent;
  border-color: transparent;
}

.button-ghost:hover:not(:disabled) {
  background: var(--surface-soft);
}

.button-block { width: 100%; }

/* Compact buttons in headings / toolbars / rows */
.panel-heading .button,
.inline-heading .button,
.content-header .button,
.header-actions .button,
.page-toolbar .button,
.list-toolbar .button,
.list-pagination .button,
.settings-actions .button {
  height: var(--btn-h-sm);
  min-height: var(--btn-h-sm);
  padding: 0 10px;
  font-size: 12px;
}

.row-actions .button {
  height: 28px;
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
}

.panel-heading .button-primary,
.inline-heading .button-primary,
.header-actions .button-primary,
.page-toolbar .button-primary {
  min-width: 88px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 12px;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  color: var(--ink-soft);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
}

.status-badge.active,
.status-badge[data-tone="success"] {
  color: var(--brand-ink);
  background: var(--brand-soft);
  border-color: var(--success-border);
}

.status-badge[data-tone="warning"] {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: var(--warning-border);
}

.status-badge[data-tone="danger"] {
  color: var(--red);
  background: var(--red-soft);
  border-color: var(--danger-border);
}

.status-badge[data-tone="info"] {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: var(--info-border);
}

.table-wrap {
  overflow-x: auto;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Standalone tables (not nested in a panel) keep a light frame */
.admin-page > .table-wrap,
.page-body > .table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  color: var(--ink-soft);
  font-size: 13px;
}

tbody tr:hover td {
  background: var(--hover-row);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td strong {
  color: var(--ink);
  font-weight: 650;
}

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

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.empty-state {
  margin: 0;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.list-toolbar,
.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.list-toolbar label,
.page-toolbar label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.list-toolbar label > span,
.page-toolbar label > span {
  flex: 0 0 auto;
  white-space: nowrap;
}

.list-toolbar select,
.list-toolbar input,
.page-toolbar select,
.page-toolbar input {
  width: auto;
  min-width: 110px;
  height: 30px;
  padding: 0 8px;
}

.list-search {
  display: inline-flex;
  flex: 1 1 180px;
  min-width: 160px;
  align-items: center;
  gap: 6px;
}

.list-search input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 140px;
}

.list-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.pagination-navigation {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-button {
  width: 34px;
  min-width: 34px;
  height: 32px;
  min-height: 32px;
  padding: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  color: #fff;
  background: var(--toast-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 600;
}

@media (max-width: 900px) {
  .toast {
    right: 12px;
    left: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    max-width: none;
    text-align: center;
  }

  .table-wrap {
    margin-inline: -2px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 640px;
  }

  th, td {
    padding: 10px 10px;
  }

  .list-toolbar,
  .page-toolbar {
    align-items: stretch;
  }

  .list-toolbar label,
  .page-toolbar label,
  .list-search {
    flex: 1 1 100%;
  }

  .list-toolbar select,
  .list-toolbar input,
  .page-toolbar select,
  .page-toolbar input,
  .list-search input {
    width: 100%;
    min-width: 0;
  }

  .list-pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination-navigation {
    justify-content: space-between;
  }

  .drawer {
    width: 100vw;
    border-left: 0;
  }

  .drawer:has(.release-drawer-form) {
    width: 100vw;
  }

  .drawer-header,
  .drawer-footer,
  .drawer-body {
    padding: 14px 16px;
  }

  .drawer-footer-actions {
    flex-wrap: wrap;
  }

  .drawer-footer-actions .button {
    flex: 1 1 calc(50% - 4px);
  }
}

.toast.error {
  background: var(--red);
}

dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgb(15 23 42 / 42%);
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 20px;
}

dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.codes-dialog textarea {
  min-height: 180px;
  font-family: var(--mono);
  font-size: 12px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 70;
  display: grid;
  width: min(480px, 100vw);
  height: 100vh;
  grid-template-rows: auto 1fr auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}

.drawer:has(.release-drawer-form) {
  width: min(520px, 100vw);
}

.drawer-header,
.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.drawer-footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
}

.drawer-body {
  overflow: auto;
  padding: 22px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(15 23 42 / 28%);
}
