:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #1a211e;
  --muted: #68716d;
  --line: #dce2df;
  --line-strong: #c8d0cc;
  --accent: #087a5b;
  --accent-hover: #066449;
  --accent-soft: #e9f5f0;
  --warning: #9a5a10;
  --warning-soft: #fff4df;
  --danger: #b33a35;
  --shadow: 0 12px 32px rgba(24, 42, 34, 0.08);
  font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.68; }

#app { min-height: 100vh; }
.topbar { height: 64px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.92); }
.topbar-inner {
  width: min(1080px, calc(100% - 48px));
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 680; font-size: 15px; }
.brand-mark {
  width: 26px;
  height: 26px;
  border: 7px solid var(--accent);
  border-right-color: #e59645;
  border-radius: 50%;
}
.utility { display: flex; align-items: center; gap: 18px; }
.health { display: flex; align-items: center; gap: 8px; color: #3f4b45; font-size: 13px; }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: #18a274; box-shadow: 0 0 0 4px #dff3eb; }
.ghost-button { border: 0; background: transparent; color: var(--muted); padding: 8px 0; font-size: 13px; }
.ghost-button:hover { color: var(--ink); }
.ghost-button:focus-visible, .primary-button:focus-visible { outline: 3px solid rgba(8,122,91,0.22); outline-offset: 2px; }

.shell { width: min(1080px, calc(100% - 48px)); margin: 0 auto; padding: 64px 0 80px; }
.heading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
h1 { margin: 0; font-size: 32px; line-height: 1.18; font-weight: 720; }
.updated { color: var(--muted); font-size: 13px; }

.rules-panel { overflow: hidden; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.rules-head, .rule-row { display: grid; grid-template-columns: 240px minmax(300px,1fr) 100px; gap: 24px; align-items: center; }
.rules-head { min-height: 48px; padding: 0 24px; border-bottom: 1px solid var(--line); background: #fafbfa; color: var(--muted); font-size: 12px; font-weight: 650; }
.rule-row { min-height: 116px; padding: 24px; }
.rule-row + .rule-row { border-top: 1px solid var(--line); }
.source-domain { color: var(--ink); font-weight: 650; overflow-wrap: anywhere; }
.source-scheme { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 450; }
.url-input, .field-input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  font-size: 14px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.url-input:focus, .field-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,122,91,0.12); }
.url-input[aria-invalid="true"], .field-input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(179,58,53,0.10); }
.url-input::placeholder, .field-input::placeholder { color: #98a09c; }
.status { justify-self: start; border-radius: 999px; padding: 5px 9px; background: var(--warning-soft); color: var(--warning); font-size: 12px; font-weight: 650; white-space: nowrap; }
.status.is-live { background: var(--accent-soft); color: var(--accent); }
.panel-footer { min-height: 72px; padding: 14px 24px; border-top: 1px solid var(--line); background: #fafbfa; display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.save-message { flex: 1; color: var(--accent); font-size: 13px; text-align: right; }
.save-message.is-error { color: var(--danger); }
.primary-button { min-width: 110px; height: 42px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; padding: 0 18px; font-size: 14px; font-weight: 650; box-shadow: 0 5px 14px rgba(8,122,91,0.18); }
.primary-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.login-main { display: grid; min-height: calc(100vh - 64px); place-items: center; padding: 52px 24px 84px; }
.login-panel { width: min(420px,100%); border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); padding: 36px; }
.login-panel h1 { margin-bottom: 30px; font-size: 27px; }
.field { display: block; margin-bottom: 20px; }
.field-label { display: block; margin-bottom: 8px; color: #3e4944; font-size: 13px; font-weight: 650; }
.form-message { margin: -3px 0 16px; color: var(--danger); font-size: 13px; line-height: 1.5; }
.login-panel .primary-button { width: 100%; margin-top: 8px; }

@media (prefers-reduced-motion: no-preference) {
  #login-view:not([hidden]), #dashboard-view:not([hidden]) { animation: enter 180ms ease-out; }
  @keyframes enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

@media (max-width: 760px) {
  .topbar-inner, .shell { width: min(100% - 32px,1080px); }
  .topbar { height: 58px; }
  .health { display: none; }
  .shell { padding: 42px 0 56px; }
  .heading-row { display: block; margin-bottom: 20px; }
  h1 { font-size: 27px; }
  .updated { display: block; margin-top: 9px; }
  .rules-head { display: none; }
  .rule-row { min-height: 0; grid-template-columns: 1fr auto; gap: 16px 12px; padding: 20px; }
  .source-domain { align-self: center; }
  .rule-row .url-input { grid-column: 1 / -1; grid-row: 2; }
  .status { grid-column: 2; grid-row: 1; }
  .panel-footer { min-height: 70px; padding: 14px 20px; flex-wrap: wrap; }
  .save-message { flex-basis: 100%; text-align: left; }
  .save-message:empty { display: none; }
  .primary-button { width: 100%; }
  .login-main { min-height: calc(100vh - 58px); align-items: start; padding-top: 54px; }
  .login-panel { border: 0; box-shadow: none; background: transparent; padding: 0; }
}
