:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --bg-elevated: #fbfaf7;
  --surface: #ffffff;
  --surface-raised: #f7f6f2;
  --surface-soft: #f0eee8;
  --text: #20242a;
  --text-soft: #3b424b;
  --muted: #68727e;
  --muted-strong: #505965;
  --gold: #966200;
  --gold-strong: #795000;
  --gold-soft: rgba(173, 116, 8, 0.1);
  --gold-line: rgba(156, 102, 0, 0.25);
  --success: #187a45;
  --success-soft: rgba(24, 122, 69, 0.09);
  --danger: #b8352e;
  --danger-soft: rgba(184, 53, 46, 0.08);
  --info: #316cc7;
  --info-soft: rgba(49, 108, 199, 0.09);
  --warning: #936611;
  --line: #e0e2e3;
  --line-strong: #cbd0d3;
  --shadow-sm: 0 1px 2px rgba(32, 36, 42, 0.05), 0 7px 20px rgba(32, 36, 42, 0.045);
  --shadow-md: 0 2px 5px rgba(32, 36, 42, 0.07), 0 20px 50px rgba(32, 36, 42, 0.09);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 15px;
  --font-sans: "Fira Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Fira Code", Consolas, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(rgba(32, 36, 42, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 36, 42, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 78%);
  content: "";
  pointer-events: none;
}

body::after {
  position: fixed;
  top: -180px;
  left: 15%;
  z-index: -1;
  width: 620px;
  height: 360px;
  border-radius: 50%;
  background: rgba(220, 159, 37, 0.11);
  filter: blur(90px);
  content: "";
  pointer-events: none;
}

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

button,
a {
  -webkit-tap-highlight-color: rgba(245, 184, 61, 0.14);
  touch-action: manipulation;
}

button {
  margin: 0;
}

a {
  color: var(--gold);
  text-decoration: none;
}

svg {
  display: block;
  flex: 0 0 auto;
}

h1,
h2,
p,
dl,
dd,
ul {
  margin: 0;
}

h1,
h2 {
  text-wrap: balance;
}

input,
textarea,
select,
button,
a {
  outline: none;
}

:focus-visible {
  outline: 3px solid rgba(245, 184, 61, 0.72);
  outline-offset: 3px;
}

::selection {
  background: var(--gold);
  color: #15120b;
}

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

.skip-link {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #15120b;
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform 180ms var(--ease-out);
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 246, 0.92);
  backdrop-filter: blur(16px);
}

.header-inner {
  display: flex;
  max-width: 1240px;
  min-height: 72px;
  margin: 0 auto;
  padding: 0 28px;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  color: var(--text);
}

.brand-symbol {
  display: grid;
  width: 40px;
  height: 40px;
  border: 1px solid var(--gold-line);
  border-radius: 11px;
  background: var(--gold-soft);
  color: var(--gold);
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.brand-symbol svg {
  width: 23px;
  height: 23px;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.15;
}

.brand-copy strong {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-copy span {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.67rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  position: relative;
  display: inline-flex;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  align-items: center;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 180ms ease, color 180ms ease;
}

.nav-link svg {
  width: 19px;
  height: 19px;
}

.nav-link:hover {
  background: rgba(32, 36, 42, 0.05);
  color: var(--text);
}

.nav-link.is-active {
  background: var(--gold-soft);
  color: var(--gold);
}

.nav-link.is-active::after {
  position: absolute;
  right: 14px;
  bottom: 3px;
  left: 14px;
  height: 2px;
  border-radius: 999px;
  background: var(--gold);
  content: "";
}

.nav-logout {
  margin-left: 8px;
  border-left: 1px solid var(--line);
  border-radius: 0 10px 10px 0;
}

.app-main {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 44px 28px max(72px, env(safe-area-inset-bottom));
}

.app-main:focus {
  outline: none;
}

.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.eyebrow {
  display: inline-flex;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  line-height: 1.4;
  text-transform: uppercase;
}

.page-head {
  display: flex;
  margin-bottom: 24px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}

.page-title-group {
  min-width: 0;
}

.page-title-group > .eyebrow {
  margin-bottom: 9px;
}

.page-title-group h1 {
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.page-title-group > h1 {
  margin-top: 4px;
}

.page-title-group > p {
  max-width: 620px;
  margin-top: 9px;
  color: var(--muted-strong);
  font-size: 1rem;
}

.title-line {
  display: flex;
  align-items: center;
  gap: 13px;
}

.count-pill {
  display: inline-flex;
  min-height: 26px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  align-items: center;
  background: var(--surface-raised);
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms var(--ease-out);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-icon {
  width: 19px;
  height: 19px;
}

.btn-primary {
  border-color: #d89b24;
  background: #e6aa33;
  color: #2c210c;
  box-shadow: 0 7px 18px rgba(170, 111, 0, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.46);
}

.btn-primary:hover:not(:disabled) {
  border-color: #c98c19;
  background: #dc9e27;
  box-shadow: 0 9px 22px rgba(150, 98, 0, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.48);
}

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

.btn-secondary:hover:not(:disabled) {
  border-color: var(--gold-line);
  background: #e9e7e0;
  color: var(--text);
}

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

.btn-ghost:hover {
  background: rgba(32, 36, 42, 0.05);
  color: var(--text);
}

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

.btn-danger:hover:not(:disabled) {
  border-color: rgba(184, 53, 46, 0.2);
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-small {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.btn-full {
  width: 100%;
}

.alert {
  display: flex;
  padding: 13px 14px;
  border: 1px solid rgba(184, 53, 46, 0.23);
  border-radius: var(--radius-md);
  align-items: flex-start;
  gap: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
}

.alert svg {
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

/* Login */
.login-page {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(28px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  place-items: center;
}

.auth-shell {
  display: grid;
  width: min(100%, 1000px);
  min-height: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.auth-intro {
  position: relative;
  display: flex;
  overflow: hidden;
  padding: 52px;
  border-right: 1px solid var(--line);
  flex-direction: column;
  justify-content: space-between;
  background: #f0ede4;
}

.auth-intro::before {
  position: absolute;
  right: -150px;
  bottom: -160px;
  width: 430px;
  height: 430px;
  border: 1px solid rgba(245, 184, 61, 0.14);
  border-radius: 50%;
  box-shadow: 0 0 0 54px rgba(245, 184, 61, 0.025), 0 0 0 108px rgba(245, 184, 61, 0.018);
  content: "";
}

.auth-intro::after {
  position: absolute;
  right: 46px;
  bottom: 42px;
  width: 92px;
  height: 2px;
  background: var(--gold);
  box-shadow: 0 0 20px rgba(173, 116, 8, 0.24);
  content: "";
}

.brand-static,
.auth-message,
.auth-features {
  position: relative;
  z-index: 1;
}

.brand-static {
  pointer-events: none;
}

.auth-message {
  margin: auto 0;
  padding: 64px 0;
}

.auth-message h1 {
  max-width: 480px;
  margin-top: 13px;
  font-size: clamp(2.25rem, 5vw, 3.45rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1.02;
}

.auth-message p {
  max-width: 470px;
  margin-top: 20px;
  color: var(--muted-strong);
  font-size: 1.02rem;
  line-height: 1.65;
}

.auth-features {
  display: grid;
  padding: 0;
  gap: 10px;
  color: var(--text-soft);
  font-size: 0.86rem;
  list-style: none;
}

.auth-features li {
  display: flex;
  align-items: center;
  gap: 9px;
}

.auth-features svg {
  width: 20px;
  height: 20px;
  color: var(--gold);
}

.auth-panel {
  display: flex;
  padding: 54px 48px;
  flex-direction: column;
  justify-content: center;
  background: var(--surface);
}

.auth-panel-head {
  display: flex;
  margin-bottom: 30px;
  align-items: flex-start;
  gap: 15px;
}

.auth-lock {
  display: grid;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  flex: 0 0 auto;
  background: var(--surface-raised);
  color: var(--gold);
  place-items: center;
}

.auth-lock svg {
  width: 22px;
  height: 22px;
}

.auth-panel-head h2 {
  margin-top: 5px;
  font-size: 1.55rem;
  letter-spacing: -0.025em;
}

.auth-panel-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-panel .alert {
  margin-bottom: 20px;
}

.login-form {
  display: grid;
  gap: 20px;
}

.security-note {
  display: flex;
  margin-top: 22px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.76rem;
}

.security-note svg {
  width: 16px;
  height: 16px;
}

/* Fields and forms */
.field {
  min-width: 0;
}

.field > label,
.field-label-row label {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 600;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.optional-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.required {
  color: var(--gold);
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"],
select {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  min-height: 132px;
  padding: 13px 14px;
  line-height: 1.6;
  resize: vertical;
}

select {
  cursor: pointer;
}

input::placeholder,
textarea::placeholder {
  color: #8a929c;
  opacity: 1;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(245, 184, 61, 0.11);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}

.input-with-icon {
  position: relative;
}

.input-with-icon > svg {
  position: absolute;
  top: 50%;
  left: 14px;
  z-index: 1;
  width: 19px;
  height: 19px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.input-with-icon > input {
  padding-left: 43px;
}

.mono-input {
  font-family: var(--font-mono);
  font-size: 0.9rem !important;
  font-variant-numeric: tabular-nums;
}

.field-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.field-hint[data-state="loading"] {
  color: var(--info);
}

.field-hint[data-state="success"] {
  color: var(--success);
}

.field-hint[data-state="error"] {
  color: var(--danger);
}

.form-page-head {
  max-width: 900px;
  margin-right: auto;
  margin-left: auto;
}

.back-link {
  display: inline-flex;
  min-height: 36px;
  margin-bottom: 21px;
  align-items: center;
  gap: 7px;
  color: var(--muted-strong);
  font-size: 0.86rem;
  font-weight: 500;
  transition: color 180ms ease;
}

.back-link:hover {
  color: var(--gold);
}

.back-link svg {
  width: 18px;
  height: 18px;
}

.form-alert {
  max-width: 900px;
  margin: -8px auto 20px;
}

.rule-form {
  max-width: 900px;
  margin: 0 auto;
  overflow: hidden;
}

.form-section {
  padding: 28px 32px 30px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  margin-bottom: 23px;
  align-items: flex-start;
  gap: 14px;
}

.section-number {
  display: inline-grid;
  width: 34px;
  height: 34px;
  border: 1px solid var(--gold-line);
  border-radius: 10px;
  flex: 0 0 auto;
  background: var(--gold-soft);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  place-items: center;
}

.section-heading h2 {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.form-section > .field + .field,
.form-section > .field + .form-grid,
.form-section > .form-grid + .field {
  margin-top: 20px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

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

.input-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.input-action-row .btn {
  min-width: 142px;
}

.btn-spinner {
  display: none;
  width: 17px;
  height: 17px;
  border: 2px solid rgba(32, 36, 42, 0.22);
  border-top-color: currentColor;
  border-radius: 50%;
}

.btn.is-loading .resolve-icon {
  display: none;
}

.btn.is-loading .btn-spinner {
  display: block;
  animation: spin 700ms linear infinite;
}

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

.priority-field {
  max-width: 240px;
}

.check-grid {
  display: grid;
  margin-top: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.check-card {
  position: relative;
  display: flex;
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease, transform 180ms var(--ease-out);
}

.check-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

.check-card:active {
  transform: scale(0.995);
}

.check-card > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-control {
  display: grid;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  flex: 0 0 auto;
  background: var(--surface-soft);
  color: #16120a;
  place-items: center;
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.check-control svg {
  width: 14px;
  height: 14px;
  opacity: 0;
  transform: scale(0.65);
  transition: opacity 140ms ease, transform 180ms var(--ease-out);
}

.check-card input:checked + .check-control {
  border-color: var(--gold);
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(245, 184, 61, 0.1);
}

.check-card input:checked + .check-control svg {
  opacity: 1;
  transform: scale(1);
}

.check-card input:focus-visible + .check-control {
  outline: 3px solid rgba(245, 184, 61, 0.72);
  outline-offset: 3px;
}

.check-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.check-copy strong {
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 600;
}

.check-copy small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.check-card-featured {
  grid-column: 1 / -1;
  min-height: 72px;
  border-color: var(--gold-line);
  background: var(--gold-soft);
}

.form-actions {
  display: flex;
  padding: 18px 32px;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-raised);
}

/* Rule list */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.rule-card {
  position: relative;
  display: flex;
  min-width: 0;
  overflow: hidden;
  flex-direction: column;
}

.rule-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--gold);
  content: "";
}

.rule-card.is-inactive::before {
  background: #9ba2a9;
}

.rule-card.is-inactive {
  background: #f8f8f6;
}

.rule-card.is-inactive .trigger-block,
.rule-card.is-inactive .rule-details,
.rule-card.is-inactive .rule-meta {
  opacity: 0.74;
}

.rule-head {
  display: flex;
  padding: 18px 18px 14px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rule-title {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  gap: 9px;
}

.rule-title > div {
  min-width: 0;
}

.rule-number {
  display: grid;
  width: 29px;
  height: 29px;
  border: 1px solid var(--line);
  border-radius: 8px;
  flex: 0 0 auto;
  background: var(--surface-raised);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  place-items: center;
}

.rule-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rule-title h2 {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.3;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-active,
.status-sent {
  border-color: rgba(24, 122, 69, 0.2);
  background: var(--success-soft);
  color: var(--success);
}

.status-paused,
.status-ignored {
  border-color: var(--line);
  background: rgba(104, 114, 126, 0.08);
  color: var(--muted-strong);
}

.status-error {
  border-color: rgba(184, 53, 46, 0.2);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-received,
.status-processing {
  border-color: rgba(49, 108, 199, 0.2);
  background: var(--info-soft);
  color: var(--info);
}

.status-neutral {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--muted-strong);
}

.rule-body {
  display: flex;
  padding: 0 18px 14px;
  flex: 1;
  flex-direction: column;
}

.trigger-block {
  padding: 10px 12px;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-md);
  background: var(--gold-soft);
}

.data-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted-strong);
  font-size: 0.68rem;
  font-weight: 500;
}

.trigger-value {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.trigger-value code {
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 600;
}

.match-chip {
  display: inline-flex;
  min-height: 21px;
  padding: 2px 6px;
  border: 1px solid rgba(245, 184, 61, 0.18);
  border-radius: 6px;
  align-items: center;
  color: #795000;
  font-size: 0.63rem;
  white-space: nowrap;
}

.rule-details {
  display: grid;
  padding: 12px 0;
  gap: 10px;
}

.rule-details > div {
  min-width: 0;
}

.rule-details dt {
  display: flex;
  margin-bottom: 3px;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
}

.rule-details dt svg {
  width: 14px;
  height: 14px;
}

.rule-details dd {
  overflow-wrap: anywhere;
  color: var(--text-soft);
  font-size: 0.81rem;
  line-height: 1.4;
}

.code-subtle {
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.message-preview {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.external-link {
  display: block;
  overflow: hidden;
  color: var(--gold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.external-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.rule-meta {
  display: flex;
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
}

.rule-meta strong {
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-weight: 500;
}

.rule-actions {
  display: flex;
  padding: 9px 14px 11px;
  border-top: 1px solid var(--line);
  align-items: center;
  gap: 5px;
  background: rgba(32, 36, 42, 0.018);
}

.rule-actions form:last-child {
  margin-left: auto;
}

.empty-state {
  display: flex;
  min-height: 390px;
  padding: 54px 28px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 21px;
  border: 1px solid var(--gold-line);
  border-radius: 18px;
  background: var(--gold-soft);
  color: var(--gold);
  place-items: center;
}

.empty-icon svg {
  width: 31px;
  height: 31px;
}

.empty-state h2 {
  max-width: 520px;
  margin-top: 8px;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  letter-spacing: -0.025em;
}

.empty-state p {
  max-width: 530px;
  margin-top: 10px;
  color: var(--muted-strong);
}

.empty-state .btn {
  margin-top: 24px;
}

/* History */
.live-indicator {
  display: inline-flex;
  min-height: 37px;
  padding: 0 12px;
  border: 1px solid rgba(24, 122, 69, 0.2);
  border-radius: 999px;
  align-items: center;
  gap: 8px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.live-indicator > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(24, 122, 69, 0.09);
}

.history-surface {
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  height: 46px;
  background: var(--surface-raised);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr {
  transition: background-color 160ms ease;
}

tbody tr:hover:not(.table-empty) {
  background: rgba(32, 36, 42, 0.025);
}

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

.date-value {
  color: var(--text-soft);
  white-space: nowrap;
}

.date-value span {
  margin-left: 3px;
  color: var(--muted);
}

.user-value {
  color: var(--gold);
  font-weight: 500;
  overflow-wrap: anywhere;
}

.comment-value {
  display: block;
  min-width: 160px;
  max-width: 260px;
  overflow-wrap: anywhere;
  color: var(--text-soft);
}

.rule-value {
  display: block;
  max-width: 180px;
  overflow-wrap: anywhere;
  color: var(--muted-strong);
}

.detail-cell {
  max-width: 250px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.76rem;
}

.table-empty td {
  height: 310px;
  text-align: center;
}

.table-empty td > * {
  margin-right: auto;
  margin-left: auto;
}

.table-empty strong,
.table-empty td > span:last-child {
  display: block;
}

.table-empty strong {
  margin-top: 15px;
  color: var(--text);
  font-size: 1rem;
}

.table-empty td > span:last-child {
  max-width: 430px;
  margin-top: 6px;
  color: var(--muted);
}

.empty-icon-small {
  width: 48px;
  height: 48px;
  margin-bottom: 0;
  border-radius: 14px;
}

.empty-icon-small svg {
  width: 24px;
  height: 24px;
}

@media (max-width: 980px) {
  .rules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth-shell {
    grid-template-columns: 1fr 400px;
  }

  .auth-intro {
    padding: 40px;
  }

  .auth-message h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 820px) {
  .auth-shell {
    max-width: 560px;
    grid-template-columns: 1fr;
  }

  .auth-intro {
    min-height: 310px;
    padding: 34px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .auth-message {
    padding: 54px 0 8px;
  }

  .auth-message h1 {
    max-width: 430px;
    font-size: 2.25rem;
  }

  .auth-message p {
    margin-top: 14px;
  }

  .auth-features {
    display: none;
  }

  .auth-panel {
    padding: 42px 34px;
  }

  .history-surface {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .table-wrap {
    overflow: visible;
  }

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

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 14px;
  }

  tbody tr {
    padding: 10px 16px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }

  tbody tr:hover:not(.table-empty) {
    background: var(--surface);
  }

  tbody td {
    display: grid;
    min-height: 48px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: start;
    gap: 14px;
  }

  tbody td::before {
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.64rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    content: attr(data-label);
  }

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

  .comment-value,
  .rule-value,
  .detail-cell {
    max-width: none;
  }

  .table-empty {
    display: block;
    padding: 0;
  }

  .table-empty td {
    display: block;
    height: auto;
    min-height: 280px;
    padding: 48px 24px;
    border: 0;
  }

  .table-empty td::before {
    display: none;
  }
}

@media (max-width: 680px) {
  .header-inner {
    display: block;
    min-height: auto;
    padding: max(11px, env(safe-area-inset-top)) 14px 7px;
  }

  .header-inner > .brand {
    margin: 0 4px 10px;
  }

  .brand-symbol {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand-symbol svg {
    width: 21px;
    height: 21px;
  }

  .main-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .nav-link {
    min-width: 0;
    padding: 0 8px;
    justify-content: center;
    font-size: 0.78rem;
  }

  .nav-link svg {
    width: 17px;
    height: 17px;
  }

  .nav-logout {
    margin-left: 0;
    border-left: 0;
    border-radius: 10px;
  }

  .nav-link.is-active::after {
    right: 24%;
    left: 24%;
  }

  .app-main {
    padding: 34px 18px max(64px, env(safe-area-inset-bottom));
  }

  .page-head {
    margin-bottom: 22px;
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
  }

  .page-head > .btn {
    width: 100%;
  }

  .title-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .page-title-group h1 {
    font-size: 1.8rem;
  }

  .history-head .live-indicator {
    align-self: flex-start;
  }

  .form-page-head {
    margin-bottom: 24px;
  }

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

  .check-card-featured {
    grid-column: auto;
  }

  .form-section {
    padding: 26px 20px 30px;
  }

  .section-heading {
    margin-bottom: 24px;
  }

  .input-action-row {
    grid-template-columns: 1fr;
  }

  .input-action-row .btn {
    width: 100%;
  }

  .priority-field {
    max-width: none;
  }

  .form-actions {
    padding: 18px 20px max(18px, env(safe-area-inset-bottom));
  }

  .form-actions .btn {
    flex: 1;
  }

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

  .rule-head {
    padding: 16px 16px 13px;
  }

  .rule-body {
    padding: 0 16px 14px;
  }

  .rule-actions {
    padding: 10px 16px 12px;
  }

  .btn-small {
    min-height: 44px;
  }
}

@media (max-width: 520px) {
  .login-page {
    display: block;
    padding: 0;
  }

  .auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .auth-intro {
    min-height: 255px;
    padding: max(24px, env(safe-area-inset-top)) 22px 26px;
  }

  .auth-message {
    padding: 42px 0 0;
  }

  .auth-message h1 {
    margin-top: 10px;
    font-size: 1.9rem;
  }

  .auth-message p {
    display: none;
  }

  .auth-panel {
    padding: 34px 22px max(36px, env(safe-area-inset-bottom));
  }

  .auth-panel-head {
    margin-bottom: 26px;
  }

  .rule-head {
    flex-direction: row;
  }

  .rule-title {
    width: 100%;
  }

  .rule-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rule-actions form,
  .rule-actions .btn {
    width: 100%;
  }

  .rule-actions form:last-child {
    grid-column: auto;
    margin-left: 0;
  }

  .rule-meta {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 6px;
  }

  .rule-meta > span[aria-hidden="true"] {
    display: inline;
  }

  .empty-state {
    min-height: 350px;
    padding: 42px 20px;
  }

  tbody td {
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
