:root {
  color: #17211f;
  background: #f1f5f2;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #17211f;
  --muted: #68736f;
  --line: #d7dfdb;
  --surface: #ffffff;
  --accent: #087f6b;
  --accent-dark: #066354;
  --danger: #b33a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(19, 57, 49, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 57, 49, 0.035) 1px, transparent 1px),
    #f1f5f2;
  background-size: 28px 28px;
}

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

button {
  cursor: pointer;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 92px;
  padding: 18px clamp(20px, 4vw, 56px);
  color: #f5fffb;
  background: #152a25;
  border-bottom: 4px solid #20a98d;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: #10251f;
  background: #77d8c2;
  border-radius: 6px;
  font: 800 14px/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.08em;
}

.site-header h1,
.panel-heading h2,
.dialog-heading h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.site-header h1 {
  font-size: clamp(20px, 3vw, 28px);
}

.eyebrow {
  margin: 0 0 4px;
  color: #67cdb6;
  font: 700 10px/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.18em;
}

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 0;
  color: #c5d7d1;
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.language-toggle {
  min-height: 34px;
  padding: 0 11px;
  color: #e7f5f0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #49645c;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

.language-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: #77d8c2;
}

.state-dot {
  width: 8px;
  height: 8px;
  background: #d4a848;
  border-radius: 50%;
}

.connection-state.connected .state-dot {
  background: #64d29d;
  box-shadow: 0 0 0 4px rgba(100, 210, 157, 0.14);
}

.connection-state.error .state-dot {
  background: #e66c6c;
}

main {
  width: min(1500px, calc(100% - 40px));
  margin: 28px auto 48px;
}

.control-panel,
.records-panel,
.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(26, 53, 46, 0.06);
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) minmax(240px, 1.4fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
  border-radius: 8px;
}

.control-panel:has(.token-field[hidden]) {
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 1.4fr) auto auto;
}

label {
  display: grid;
  gap: 7px;
  color: #485550;
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  color: var(--ink);
  background: #fbfdfc;
  border: 1px solid #cbd5d1;
  border-radius: 5px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 107, 0.12);
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 700;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

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

.button-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.button-secondary {
  color: #34423e;
  background: #f7faf8;
  border-color: #cbd5d1;
}

.button-secondary:hover:not(:disabled) {
  background: #edf3f0;
  border-color: #aebdb7;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0;
}

.summary-grid article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: 8px;
}

.summary-grid span {
  color: var(--muted);
  font-size: 13px;
}

.summary-grid strong {
  font: 700 25px/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.records-panel {
  overflow: hidden;
  border-radius: 8px;
}

.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2,
.dialog-heading h2 {
  font-size: 20px;
}

.panel-heading > p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.table-shell {
  position: relative;
  overflow-x: auto;
  min-height: 250px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid #e4eae7;
}

th {
  color: #5f6b67;
  background: #f8faf9;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f7fbf9;
}

td.code,
.record-type {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

td.record-value {
  min-width: 240px;
  max-width: 480px;
  overflow-wrap: anywhere;
}

.record-type {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 4px 7px;
  color: #0a6254;
  background: #e3f4ef;
  border: 1px solid #bde0d6;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 750;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.status-badge::before {
  width: 7px;
  height: 7px;
  background: #35a174;
  border-radius: 50%;
  content: "";
}

.status-badge.disabled {
  color: #7a8581;
}

.status-badge.disabled::before {
  background: #9ca6a2;
}

.actions-column {
  width: 190px;
  text-align: right;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.text-button {
  padding: 5px 7px;
  color: #285e53;
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 12px;
}

.text-button:hover {
  background: #e9f3ef;
}

.text-button.danger {
  color: var(--danger);
}

.text-button.danger:hover {
  background: #fbecec;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 250px;
  color: var(--muted);
  gap: 6px;
}

.empty-state strong {
  color: #46534f;
}

.empty-state[hidden],
table[hidden] {
  display: none;
}

dialog {
  width: min(620px, calc(100% - 32px));
  padding: 0;
  color: var(--ink);
  background: white;
  border: 1px solid #bfcac6;
  border-radius: 9px;
  box-shadow: 0 26px 80px rgba(13, 35, 29, 0.28);
}

dialog::backdrop {
  background: rgba(10, 27, 23, 0.58);
  backdrop-filter: blur(2px);
}

#recordForm {
  padding: 22px;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.icon-button {
  width: 34px;
  height: 34px;
  color: #53615c;
  background: transparent;
  border: 1px solid #d7dfdb;
  border-radius: 5px;
  font-size: 22px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.full-width {
  grid-column: 1 / -1;
}

.form-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #e0e6e3;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: min(420px, calc(100% - 48px));
  padding: 12px 15px;
  color: white;
  background: #19312b;
  border-left: 4px solid #62c9af;
  border-radius: 5px;
  box-shadow: 0 12px 40px rgba(9, 31, 25, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-left-color: #e56e6e;
}

@media (max-width: 980px) {
  .control-panel,
  .control-panel:has(.token-field[hidden]) {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .site-header {
    padding: 16px 18px;
  }

  .connection-state {
    display: none;
  }

  main {
    width: calc(100% - 24px);
    margin-top: 16px;
  }

  .control-panel,
  .control-panel:has(.token-field[hidden]),
  .summary-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .search-field,
  .full-width {
    grid-column: auto;
  }

  .summary-grid article {
    padding: 13px 16px;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}
