:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #18212f;
  --muted: #5e6b7a;
  --line: #d9e2ec;
  --brand: #1f4e79;
  --brand-strong: #174064;
  --accent: #d97706;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  letter-spacing: 0;
}

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

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(18px, 4vw, 42px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 4px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 20px;
}

.status {
  background: #eef5fb;
  border: 1px solid #c9dceb;
  border-radius: 6px;
  color: var(--brand);
  min-width: 92px;
  padding: 8px 12px;
  text-align: center;
}

.layout {
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 1440px;
  padding: 22px clamp(14px, 3vw, 34px) 42px;
}

.toolbar,
.section-heading {
  align-items: end;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.search-wrap {
  display: grid;
  gap: 7px;
  width: min(620px, 100%);
}

label {
  color: var(--muted);
  display: grid;
  font-size: 14px;
  font-weight: 700;
  gap: 7px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 9px 14px;
}

.primary {
  background: var(--brand);
  color: white;
}

.primary:hover {
  background: var(--brand-strong);
}

.secondary {
  background: white;
  border-color: #b8c7d8;
  color: var(--brand);
}

.danger {
  background: #fff5f5;
  border-color: #ffc9c9;
  color: var(--danger);
}

.table-panel,
.rules {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 246px);
}

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

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

th {
  background: #eef5fb;
  color: var(--brand);
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  line-height: 1.5;
}

.action-col {
  width: 132px;
}

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

.row-actions button {
  min-height: 34px;
  padding: 6px 10px;
}

.empty {
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

.rules {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

.rule-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.rule-section h3 {
  background: #eef5fb;
  color: var(--brand);
  font-size: 16px;
  margin: 0;
  padding: 12px 14px;
}

.rule-item {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 12px 14px;
}

.rule-item strong {
  color: var(--ink);
}

.rule-item span {
  color: var(--muted);
}

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

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(24, 33, 47, 0.25);
  max-width: 620px;
  padding: 0;
  width: calc(100vw - 28px);
}

dialog::backdrop {
  background: rgba(12, 20, 31, 0.45);
}

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

.dialog-head,
.dialog-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  min-height: 34px;
  padding: 0 8px;
}

@media (max-width: 820px) {
  .topbar,
  .toolbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .status {
    text-align: left;
  }
}
