:root {
  color-scheme: light;
  --bg: #eef2f6;
  --bg-accent: #e3f0fa;
  --panel: #ffffff;
  --panel-muted: #f2f5f8;
  --line: #dde5ec;
  --text: #1a2530;
  --muted: #64748b;
  --accent: #0068b4;
  --accent-strong: #00507f;
  --accent-soft: #e3f0fa;
  --danger: #b42318;
  --success: #12a150;
  --success-strong: #0c7d3e;
  --success-soft: #e3f8ec;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow-md: 0 8px 24px rgb(16 24 40 / 8%);
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 480px at 10% -10%, var(--bg-accent), transparent),
    var(--bg);
  background-attachment: fixed;
}

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

.shell {
  max-width: 1000px;
  padding: 32px 24px 64px;
  margin: 0 auto;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.query-panel {
  margin-bottom: 24px;
}

.query-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field-wide {
  grid-column: 1 / -1;
}

.combobox {
  position: relative;
}

.combobox-options {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow-md);
}

.combobox-option {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}

.combobox-option:hover,
.combobox-option.is-active {
  background: var(--accent-soft);
}

.combobox-empty {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
}

.form-field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.form-field input {
  min-height: 36px;
}

.form-field input:disabled {
  color: var(--muted);
  background: var(--panel-muted);
  opacity: 0.8;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(0 104 180 / 16%);
}

.password-field {
  display: flex;
  gap: 8px;
}

.password-field input {
  flex: 1;
}

.link-button {
  flex-shrink: 0;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
  cursor: pointer;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  transition: background 0.15s ease;
}

.link-button:hover {
  background: #cfe6f5;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  grid-column: 1 / -1;
  margin-top: 4px;
}

.btn {
  min-height: 36px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 4px 12px rgb(0 104 180 / 30%);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgb(0 104 180 / 36%);
}

.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: #cfe6f5;
}

.btn-small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.form-hint {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.alert {
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 13px;
  border-radius: 9px;
}

.alert-error {
  color: var(--danger);
  background: #fde2e1;
  border: 1px solid #f2b8b5;
}

.alert-success {
  color: var(--success-strong);
  background: var(--success-soft);
  border: 1px solid #b8ecce;
}

.alert-success a {
  color: inherit;
  font-weight: 700;
}

.alert-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #bfe0f2;
}

/* display:flex ở trên đè lên [hidden] mặc định của trình duyệt (cùng độ ưu tiên, CSS này định nghĩa sau) — ẩn tường minh lại khi có attribute hidden */
.alert-info[hidden] {
  display: none;
}

.alert-info .link-button {
  margin-left: auto;
}

.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.history-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.history-search {
  min-width: 240px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(0 104 180 / 16%);
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
}

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

.history-table th {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--panel-muted);
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-key {
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
}

.history-summary-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-date {
  white-space: nowrap;
  font-size: 13px;
}

.badge-edited {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
}

.history-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: nowrap;
}

.history-detail-row td {
  background: var(--panel-muted);
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

.history-page-info {
  font-size: 12px;
  color: var(--muted);
}

.kv-list {
  display: grid;
  gap: 6px;
}

.kv-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel);
  border-radius: 6px;
}

.kv-key {
  color: var(--muted);
  font-weight: 700;
}

.kv-value {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

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

@media (max-width: 640px) {
  .shell {
    padding: 20px 16px 48px;
  }

  .history-summary-cell {
    max-width: 160px;
  }
}
