:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-muted: #f5f5f4;
  --text: #1c1917;
  --text-muted: #57534e;
  --text-soft: #78716c;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --border-control: #8b857f;
  --primary: #c2410c;
  --primary-hover: #9a3412;
  --primary-soft: #fff7ed;
  --primary-soft-strong: #ffedd5;
  --focus: #c2410c;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #92400e;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05), 0 10px 30px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 20px 50px rgba(28, 25, 23, 0.16);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  --transition: 160ms ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.5rem, 1.2rem + 1vw, 1.9rem);
  font-weight: 700;
}

h2 {
  font-size: 1.25rem;
  font-weight: 650;
}

h3 {
  font-size: 1.05rem;
  font-weight: 650;
}

p {
  margin: 0;
}

a {
  color: var(--primary-hover);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--primary);
}

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

svg {
  display: block;
  flex-shrink: 0;
}

[hidden] {
  display: none !important;
}

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

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

::selection {
  background: var(--primary-soft-strong);
  color: var(--text);
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--transition);
}

.skip-link:focus {
  transform: translateY(0);
  color: #ffffff;
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.8rem 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  border: 1px solid var(--primary-soft-strong);
  background: var(--primary-soft);
  color: var(--primary);
}

.brand-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-large {
  gap: 0.75rem;
  margin-bottom: 1.4rem;
  font-size: 1.1rem;
}

.brand-large .brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header-user .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.user-email {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.925rem;
}

/* ---------- Main / views ---------- */

main {
  display: block;
}

#contenido-principal:focus {
  outline: none;
}

#contenido-principal:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 430px;
  padding: 2.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 0.4rem;
}

.login-subtitle {
  margin-bottom: 1.6rem;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-footnote {
  margin-top: 1.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 0.85rem;
  text-align: center;
}

#app-view {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ---------- Tabs ---------- */

.tabs {
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
}

.tablist {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
}

.tab {
  min-height: 48px;
  padding: 0.75rem 1rem;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition),
    background-color var(--transition);
}

.tab:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.tab[aria-selected='true'] {
  border-bottom-color: var(--primary);
  color: var(--primary-hover);
}

/* ---------- Panels ---------- */

.panel {
  display: block;
}

.panel:focus-visible {
  outline-offset: 8px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-subtitle {
  margin-top: 0.35rem;
  color: var(--text-muted);
  max-width: 62ch;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem;
  margin-bottom: 1.1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.toolbar .field-inline {
  flex: 0 1 260px;
}

.toolbar .field-inline:first-child {
  flex: 1 1 280px;
}

.result-count {
  margin-left: auto;
  align-self: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field label,
.editor-label {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

.required-mark {
  color: var(--danger);
  margin-left: 0.1rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-control);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.55;
}

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

input:hover,
select:hover,
textarea:hover {
  border-color: #a8a29e;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

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

input[aria-invalid='true'],
select[aria-invalid='true'],
textarea[aria-invalid='true'] {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.hint {
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.45;
}

.field-error,
.form-error,
.inline-error {
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.45;
}

.form-error {
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-soft);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.form-grid .field-full,
.form-grid .form-actions,
.form-grid .form-error {
  grid-column: 1 / -1;
}

.form-grid-narrow {
  max-width: 640px;
  margin-bottom: 1.25rem;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.form-grid-narrow .form-actions {
  grid-column: 2;
}

.form-grid-narrow .form-error {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 0.925rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}

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

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

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(154, 52, 18, 0.24);
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-control);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
  border-color: #a8a29e;
}

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

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

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

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

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger-solid:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #ffffff;
}

.btn-small {
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  font-size: 0.86rem;
}

.btn-block {
  width: 100%;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition),
    border-color var(--transition);
}

.icon-button:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

/* ---------- Cards ---------- */

.card {
  margin-bottom: 1.5rem;
  padding: 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.card-subtitle {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.925rem;
}

/* ---------- Badges and status ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  min-height: 26px;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
}

.badge svg {
  width: 13px;
  height: 13px;
}

.badge-severity-mandatory {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: #991b1b;
}

.badge-severity-recommended {
  border-color: var(--primary-soft-strong);
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.badge-severity-optional {
  border-color: var(--border);
  background: var(--surface-muted);
  color: #44403c;
}

.badge-role {
  border-color: var(--primary-soft-strong);
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.status svg {
  width: 14px;
  height: 14px;
}

.status-active {
  color: var(--success);
}

.status-inactive {
  color: var(--text-muted);
}

.tag {
  display: inline-block;
  margin: 0.1rem 0.25rem 0.1rem 0;
  padding: 0.08rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: nowrap;
}

/* ---------- Tables ---------- */

.data-list {
  min-height: 2rem;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.table-scroll:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-caption {
  padding: 0.85rem 1rem 0.25rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
}

.data-table th {
  padding: 0.7rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}

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

.data-table tbody tr {
  transition: background-color var(--transition);
}

.data-table tbody tr:hover {
  background: #fcfcfb;
}

.cell-id {
  font-family: var(--mono);
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}

.cell-title {
  min-width: 190px;
  max-width: 320px;
  font-weight: 600;
}

.cell-title-text {
  display: block;
}

.cell-rule {
  display: block;
  min-width: 0;
}

.cell-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.cell-tags .tag {
  margin: 0;
}

.cell-sub {
  display: block;
  margin-top: 0.15rem;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.cell-stack {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

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

.cell-updated {
  min-width: 150px;
}

.cell-actions {
  min-width: 170px;
  width: 190px;
}

.row-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  min-width: 0;
}

.row-actions .btn {
  flex: 0 0 auto;
  justify-content: flex-start;
  white-space: nowrap;
}

.table-note {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin-top: 0.6rem;
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.45;
}

.table-note svg {
  flex: 0 0 auto;
  margin-top: 0.12rem;
}

.role-select {
  min-width: 132px;
}

/* ---------- Empty / loading states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.empty-state h2 {
  font-size: 1.1rem;
}

.empty-state p {
  max-width: 44ch;
  color: var(--text-muted);
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 1px solid var(--primary-soft-strong);
  background: var(--primary-soft);
  color: var(--primary);
}

.skeleton-table {
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.skeleton-row {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

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

.skeleton {
  height: 14px;
  border-radius: 5px;
  background: linear-gradient(90deg, #f5f5f4 25%, #ebe9e7 50%, #f5f5f4 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton:nth-child(1) {
  width: 12%;
}

.skeleton:nth-child(2) {
  width: 34%;
}

.skeleton:nth-child(3) {
  width: 18%;
}

.skeleton:nth-child(4) {
  width: 16%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- Token callout ---------- */

.token-callout {
  margin-bottom: 1.25rem;
  padding: 1.1rem;
  border: 1px solid var(--primary-soft-strong);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-lg);
  background: var(--primary-soft);
}

.token-callout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.token-warning {
  margin-top: 0.35rem;
  color: var(--primary-hover);
  font-weight: 600;
  font-size: 0.9rem;
}

.token-name {
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.token-value-row {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.token-value {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius);
  background: var(--text);
  color: #fafaf9;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 70;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: min(380px, calc(100vw - 2rem));
  padding: 0.85rem 0.9rem 0.85rem 1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--success);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

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

.toast-message {
  flex: 1 1 auto;
  font-size: 0.9rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* ---------- Modals ---------- */

.modal {
  width: min(760px, calc(100vw - 2rem));
  max-width: 100%;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal-small {
  width: min(480px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgba(28, 25, 23, 0.48);
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2rem);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.4rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  padding-top: 0.5rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1.4rem;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ---------- Editor ---------- */

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.25rem;
}

.editor-modes {
  display: inline-flex;
  padding: 0.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.editor-modes .btn {
  border: 0;
  background: transparent;
}

.editor-modes .btn[aria-pressed='true'] {
  background: var(--surface);
  color: var(--primary-hover);
  box-shadow: var(--shadow-sm);
}

#rule-content {
  min-height: 260px;
  font-family: var(--mono);
  font-size: 0.88rem;
}

.preview {
  min-height: 260px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow-wrap: anywhere;
}

/* ---------- Markdown ---------- */

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 1.3em 0 0.5em;
  line-height: 1.3;
}

.markdown h1 {
  font-size: 1.5rem;
}

.markdown h2 {
  font-size: 1.25rem;
}

.markdown h3 {
  font-size: 1.1rem;
}

.markdown p {
  margin: 0.75em 0;
}

.markdown ul,
.markdown ol {
  margin: 0.75em 0;
  padding-left: 1.5rem;
}

.markdown li {
  margin: 0.25em 0;
}

.markdown blockquote {
  margin: 1em 0;
  padding: 0.35rem 0 0.35rem 0.9rem;
  border-left: 3px solid var(--primary-soft-strong);
  color: var(--text-muted);
}

.markdown code {
  padding: 0.1rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 0.86em;
}

.markdown pre {
  margin: 1em 0;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: #fafaf9;
  overflow-x: auto;
}

.markdown pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 0.84rem;
  white-space: pre;
}

.markdown a {
  color: var(--primary-hover);
  font-weight: 600;
}

.markdown hr {
  margin: 1.4em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.markdown .empty-preview {
  color: var(--text-soft);
  font-style: italic;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .header-inner {
    padding: 0.7rem 1rem;
  }

  .user-email {
    max-width: 160px;
  }

  #app-view {
    padding: 0 1rem 3rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-narrow .form-actions {
    grid-column: 1;
  }

  .toolbar .field-inline,
  .toolbar .field-inline:first-child {
    flex: 1 1 100%;
  }

  .result-count {
    margin-left: 0;
    flex-basis: 100%;
    text-align: right;
  }
}

@media (max-width: 820px) {
  .panel-head {
    flex-direction: column;
  }

  .panel-head .btn {
    align-self: stretch;
  }

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

  .table-scroll {
    overflow-x: visible;
    border: 0;
    background: transparent;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

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

  .data-table tr {
    margin-bottom: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.38rem 0;
    border: 0;
    text-align: right;
  }

  .data-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-soft);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: left;
    text-transform: uppercase;
  }

  .data-table td > * {
    min-width: 0;
  }

  .data-table td.cell-actions {
    flex-direction: column;
    align-items: stretch;
    margin-top: 0.5rem;
    padding-top: 0.7rem;
    border-top: 1px solid var(--border);
    text-align: left;
    min-width: 0;
    width: auto;
  }

  .data-table td.cell-actions::before {
    margin-bottom: 0.2rem;
  }

  .cell-updated {
    min-width: 0;
  }

  .row-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .row-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .cell-title {
    max-width: none;
  }

  .cell-tags {
    justify-content: flex-end;
  }

  .cell-id {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 700px) {
  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'brand logout'
      'meta meta';
    align-items: center;
    column-gap: 1rem;
    row-gap: 0.5rem;
  }

  .header-user {
    display: contents;
  }

  .brand {
    grid-area: brand;
  }

  .brand-name {
    white-space: normal;
    line-height: 1.2;
  }

  #logout-button {
    grid-area: logout;
    justify-self: end;
  }

  .user-email {
    grid-column: 1;
    grid-row: 2;
    max-width: none;
    min-width: 0;
  }

  #user-role {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }
}

@media (max-width: 560px) {
  .login-card {
    padding: 1.5rem 1.2rem;
    border-radius: var(--radius-lg);
  }

  .header-inner {
    gap: 0.5rem;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .header-user .btn {
    padding-inline: 0.7rem;
  }

  .tabs {
    margin-bottom: 1.25rem;
  }

  .tab {
    padding-inline: 0.65rem;
  }

  .toolbar,
  .card {
    padding: 1rem;
  }

  .modal {
    width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .modal-form {
    max-height: calc(100dvh - 1rem);
  }

  .modal-head,
  .modal-body,
  .modal-actions {
    padding-inline: 1rem;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .token-value-row {
    flex-direction: column;
  }

  .token-value-row .btn {
    width: 100%;
  }

  .toast {
    right: 0.5rem;
    bottom: 0.5rem;
    width: calc(100vw - 1rem);
  }
}

@media (max-width: 360px) {
  .header-inner {
    padding-inline: 0.65rem;
  }

  .brand-name {
    font-size: 0.88rem;
  }

  .header-user .btn {
    font-size: 0.8rem;
    padding-inline: 0.55rem;
  }

  #app-view {
    padding-inline: 0.65rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
