:root {
  color-scheme: light;
  --paper: #f5f6f1;
  --ink: #17211c;
  --muted: #66736c;
  --line: #d8ddd3;
  --panel: #ffffff;
  --teal: #1d7f72;
  --teal-deep: #115e55;
  --amber: #a66f00;
  --red: #b63b32;
  --steel: #40566b;
  --shadow: 0 18px 45px rgba(23, 33, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(29, 127, 114, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(64, 86, 107, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: white;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(29, 127, 114, 0.28);
  outline-offset: 2px;
}

button.primary {
  background: var(--teal);
  border-color: var(--teal);
}

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

button.ghost {
  background: white;
  border-color: var(--line);
  color: var(--ink);
}

input,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcf8;
  color: var(--ink);
  padding: 0 12px;
}

textarea {
  line-height: 1.45;
  min-height: 92px;
  padding: 10px 12px;
  resize: vertical;
}

label,
.label,
.kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: clamp(32px, 5vw, 64px);
  font-weight: 900;
}

h2 {
  font-size: 22px;
}

.status,
.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--steel);
  font-size: 13px;
  font-weight: 800;
  padding: 8px 12px;
  white-space: nowrap;
}

.rule-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border: 2px solid var(--steel);
  border-left-width: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 16px 18px;
}

.rule-banner h2 {
  font-size: 26px;
}

.rule-banner p:last-child {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  margin: 8px 0 0;
}

.rule-banner.success {
  border-color: var(--teal);
  background: #f2fbf7;
}

.rule-banner.success h2 {
  color: var(--teal-deep);
}

.rule-banner.pending {
  border-color: var(--amber);
  background: #fff8e8;
}

.rule-banner.pending h2 {
  color: var(--amber);
}

.rule-banner.error {
  border-color: var(--red);
  background: #fff3f1;
}

.rule-banner.error h2 {
  color: var(--red);
}

.rule-banner-main {
  min-width: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 18px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  margin-bottom: 14px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.inline,
.actions,
.manual-grid,
.ports-editor {
  display: grid;
  gap: 10px;
}

.inline {
  grid-template-columns: minmax(0, 1fr) auto;
}

.actions {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.operation-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  min-height: 20px;
  margin: 12px 0 0;
}

.operation-status.error {
  color: var(--red);
}

.operation-status.success {
  color: var(--teal-deep);
}

.operation-status.pending {
  color: var(--amber);
}

.manual-grid {
  grid-template-columns: 1.1fr 1.4fr auto;
}

.sync-cloudflare {
  margin-top: 12px;
}

.ports-editor {
  grid-template-columns: minmax(0, 1fr);
}

.ports-editor button {
  justify-self: start;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
}

td code {
  border-radius: 4px;
  background: #edf3ef;
  color: var(--teal-deep);
  padding: 4px 6px;
}

.note-edit {
  min-width: 180px;
}

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

.row-action {
  background: white;
  border-color: var(--line);
  color: var(--red);
}

.row-save {
  background: white;
  border-color: var(--teal);
  color: var(--teal-deep);
}

.empty {
  display: none;
  color: var(--muted);
  padding: 18px 4px 4px;
}

.empty.show {
  display: block;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  margin-bottom: 24px;
}

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

.login-form button {
  margin-top: 8px;
}

.login-error {
  color: var(--red);
  margin: 14px 0 0;
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 1120px);
    margin: 16px auto;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .rule-banner {
    grid-template-columns: 1fr;
  }

  .rule-banner button {
    justify-self: start;
  }

  .grid,
  .inline,
  .manual-grid,
  .ports-editor {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
