:root {
  --bg: #f6f4ef;
  --surface: #fffcf5;
  --ink: #1c1b19;
  --muted: #5c5954;
  --line: #d8d3c9;
  --accent: #2f6feb;
  --accent-dim: #e8f0fe;
  --danger: #b42318;
  --radius: 8px;
  --font: "Literata", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

code,
.kbd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--accent-dim);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.small,
.small * {
  font-size: 0.92rem;
}

.tiny {
  font-size: 0.82rem;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
}

.layout {
  min-height: 100vh;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 25, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 40;
}

.overlay-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.field.tight {
  margin: 0;
  gap: 0;
}

.flex-grow {
  flex: 1 1 120px;
  min-width: 0;
}

.field span {
  font-size: 0.9rem;
  color: var(--muted);
}

.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.field.inline span {
  min-width: auto;
}

input,
select,
textarea {
  font: 500 0.875rem var(--mono);
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}

.input-compact {
  padding: 0.32rem 0.45rem;
  font-size: 0.8125rem;
}

.flt-select {
  min-width: 5.5rem;
  max-width: 7.5rem;
}

.btn-compact {
  padding: 0.32rem 0.55rem;
  font-size: 0.8125rem;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

.btn {
  font-family: var(--font);
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.55rem 0.9rem;
}

.btn.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.btn.secondary {
  background: var(--surface);
}

.btn.ghost {
  background: transparent;
}

.btn.small,
.btn.tiny {
  padding: 0.35rem 0.65rem;
  font-size: 0.88rem;
}

.btn.danger {
  border-color: #f5c6c2;
  color: var(--danger);
  background: #fff5f5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand-mark {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}

.shell {
  display: grid;
  grid-template-columns: minmax(240px, 280px) 1fr;
  gap: 0;
  min-height: calc(100vh - 48px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #faf8f3;
  padding: 0.65rem 0.7rem;
  overflow: auto;
}

.main {
  padding: 0.65rem 0.85rem;
  overflow: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.65rem;
}

.panel.flat {
  background: transparent;
  border: none;
  padding: 0;
}

.panel h3 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.account-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.account-item.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.account-item button {
  font-size: 0.8rem;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 42vh;
  overflow: auto;
}

.zone-item {
  text-align: left;
  width: 100%;
  padding: 0.38rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.zone-item:hover {
  background: var(--accent-dim);
}

.zone-item.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.65rem;
}

.banner h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.25;
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.records-section {
  margin-bottom: 0;
}

.records-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.45rem 0.65rem;
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.35rem;
  flex: 1 1 240px;
  min-width: 0;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.records-meta {
  margin: 0 0 0.35rem;
  line-height: 1.3;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  line-height: 1.35;
}

.table-record th,
.table-record td {
  padding: 0.32rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
}

.table th {
  background: var(--bg);
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: none;
}

.col-type {
  width: 4rem;
}

.col-narrow {
  width: 3.25rem;
  white-space: nowrap;
}

.col-actions {
  width: 5.5rem;
  text-align: right;
}

.col-name {
  min-width: 7rem;
  max-width: 14rem;
}

.col-content {
  min-width: 6rem;
}

.table tr:last-child td {
  border-bottom: none;
}

.cell-mono {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-word;
}

.pill {
  display: inline-block;
  padding: 0.06rem 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  background: #fff;
  line-height: 1.3;
}

.record-actions {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.td-actions {
  text-align: right;
  white-space: nowrap;
}

.btn-action {
  padding: 0.22rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.2;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.pager-tight {
  margin-top: 0.45rem;
  gap: 0.5rem;
}

.zone-pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.details summary {
  cursor: pointer;
  font-weight: 600;
  margin: 0.5rem 0;
}

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 25, 0.28);
  z-index: 30;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: min(520px, 100%);
  background: var(--surface);
  height: 100%;
  overflow: auto;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.08);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.drawer-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.drawer-body {
  padding: 0.75rem 0.85rem 1.5rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  max-width: min(90vw, 480px);
  text-align: center;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }

  .list {
    max-height: 26vh;
  }
}

@media (max-width: 720px) {
  .records-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    align-items: stretch;
  }

  .toolbar-filters .flt-select {
    max-width: none;
  }

  .toolbar-filters .field.flex-grow {
    grid-column: 1 / -1;
  }

  .toolbar-filters #records-search {
    grid-column: 1 / -1;
  }

  .toolbar-actions #record-new {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 0.5rem;
  }

  .table.table-record thead {
    display: none;
  }

  .table.table-record tbody {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.35rem 0.4rem;
  }

  .table.table-record tr.record-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto auto;
    column-gap: 0.5rem;
    row-gap: 0.2rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    align-items: start;
  }

  .table.table-record tr.record-row td {
    display: block;
    padding: 0;
    border: none;
    vertical-align: top;
  }

  .table.table-record .td-type {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
  }

  .table.table-record .td-actions {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: center;
  }

  .table.table-record .td-actions::before {
    display: none !important;
    content: none !important;
  }

  .table.table-record .td-name {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 0.8rem;
  }

  .table.table-record .td-name::before {
    content: "名称 ";
    font-size: 0.68rem;
    color: var(--muted);
  }

  .table.table-record .td-content {
    grid-column: 1 / -1;
    grid-row: 3;
    font-size: 0.78rem;
    max-height: 4.2em;
    overflow: auto;
  }

  .table.table-record .td-content::before {
    content: "内容 ";
    font-size: 0.68rem;
    color: var(--muted);
    display: block;
    margin-bottom: 0.1rem;
  }

  .table.table-record .td-ttl {
    grid-column: 1;
    grid-row: 4;
    font-size: 0.72rem;
    color: var(--muted);
    align-self: end;
  }

  .table.table-record .td-ttl::before {
    content: "TTL ";
    color: var(--muted);
    font-size: 0.65rem;
  }

  .table.table-record .td-proxy {
    grid-column: 2;
    grid-row: 4;
    font-size: 0.72rem;
    color: var(--muted);
    justify-self: end;
    align-self: end;
    text-align: right;
  }

  .table.table-record .td-proxy::before {
    content: "代理 ";
    color: var(--muted);
    font-size: 0.65rem;
  }

  .record-actions {
    gap: 0.35rem;
  }

  .btn-action {
    min-height: 2rem;
    min-width: 2.75rem;
    padding: 0.28rem 0.5rem;
    font-size: 0.78rem;
  }

  .banner {
    padding: 0.45rem 0.55rem;
  }

  .banner-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .banner-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }
}

@media (min-width: 641px) {
  .table.table-record tr:nth-child(even) td {
    background: rgba(246, 244, 239, 0.35);
  }
}
