/* GitHub light inspired interface */
:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-muted: #f6f8fa;
  --surface-subtle: #f0f3f6;
  --border: #d0d7de;
  --border-muted: #d8dee4;
  --border-strong: #8c959f;
  --text: #24292f;
  --text-muted: #57606a;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-muted: #ddf4ff;
  --danger-bg: #ffebe9;
  --danger-border: #ff8182;
  --danger-text: #cf222e;
  --focus: rgba(9, 105, 218, .28);
  --shadow-sm: 0 1px 0 rgba(27, 31, 36, .04);
  --radius: 6px;
  --topbar-h: 48px;
  --px: 24px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 var(--px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.userbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.username-chip {
  display: inline-flex;
  align-items: center;
  max-width: 34vw;
  height: 26px;
  padding: 0 8px;
  overflow: hidden;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  padding: 18px var(--px) 28px;
}

.content-head {
  margin-bottom: 16px;
}

h1 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
}

p {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

input {
  width: 100%;
  height: 32px;
  padding: 5px 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
  outline: none;
}

select {
  width: 100%;
  height: 32px;
  padding: 4px 30px 4px 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
  outline: none;
}

input::placeholder {
  color: var(--text-muted);
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 32px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

button:hover,
.button-link:hover {
  background: var(--surface-subtle);
  border-color: var(--border-strong);
  color: var(--text);
  text-decoration: none;
}

button.primary {
  background: #1f883d;
  border-color: rgba(31, 136, 61, .9);
  color: #ffffff;
}

button.primary:hover {
  background: #1a7f37;
  color: #ffffff;
}

.primary-link {
  background: #1f883d;
  border-color: rgba(31, 136, 61, .9);
  color: #ffffff;
}

.primary-link:hover {
  background: #1a7f37;
  border-color: #1a7f37;
  color: #ffffff;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 8px;
  color: var(--text-muted);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
}

.topbar-link:hover {
  color: var(--text);
  background: var(--surface-muted);
  text-decoration: none;
}

.ghost-button {
  height: 28px;
  padding: 0 8px;
  color: var(--text-muted);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  font-size: 12px;
}

.ghost-button:hover {
  background: var(--surface-muted);
  border-color: var(--border);
}

.alert {
  margin: 10px 0;
  padding: 8px 12px;
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  font-size: 13px;
}

.notice {
  margin: 0 0 12px;
  padding: 8px 12px;
  color: #116329;
  background: #dafbe1;
  border: 1px solid #4ac26b;
  border-radius: var(--radius);
  font-size: 13px;
}

.login-panel {
  max-width: 360px;
  margin: 48px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-panel h1 {
  margin-bottom: 18px;
  font-size: 22px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.stack-form button.primary {
  height: 36px;
  margin-top: 4px;
}

.table-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.table-item {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
}

.table-item:hover {
  border-color: var(--border-strong);
  box-shadow: 0 3px 10px rgba(27, 31, 36, .08);
  text-decoration: none;
}

.table-item strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-item p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.45;
}

.table-source {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.table-item code,
code {
  display: inline-block;
  max-width: 100%;
  padding: 1px 5px;
  overflow: hidden;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--border-muted);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.back-link::before {
  content: "<-";
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.table-meta {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  min-width: 0;
}

.filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
  color: var(--text-muted);
  font-size: 12px;
}

.table-toolbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.button-link.compact {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.scroll-hint {
  display: none;
}

.table-wrap {
  position: relative;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.table-wrap:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
  outline: none;
}

.table-wrap::after {
  position: sticky;
  right: 0;
  display: block;
  width: 28px;
  height: 0;
  margin-left: auto;
  content: "";
  pointer-events: none;
  box-shadow: -16px 0 16px -16px rgba(27, 31, 36, .22);
  opacity: 0;
  transition: opacity 160ms ease;
}

.table-wrap.has-overflow::after {
  opacity: 1;
}

.table-wrap::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-wrap::-webkit-scrollbar-track {
  background: var(--surface-muted);
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #afb8c1;
  border: 2px solid var(--surface-muted);
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

table {
  width: 100%;
  min-width: max(760px, var(--table-min-width));
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

th,
td {
  min-width: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-muted);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  vertical-align: middle;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 3;
  color: var(--text);
  background: var(--surface-muted);
  border-bottom-color: var(--border);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:nth-child(even) td {
  background: #fcfcfd;
}

tbody tr:hover td {
  background: var(--accent-muted);
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border-muted);
}

th:first-child {
  z-index: 4;
  background: var(--surface-muted);
}

tbody tr:nth-child(even) td:first-child {
  background: #fcfcfd;
}

tbody tr:hover td:first-child {
  background: var(--accent-muted);
}

tbody tr:last-child td {
  border-bottom: none;
}

.empty {
  padding: 32px 16px !important;
  color: var(--text-muted);
  text-align: center;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.pagination a {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
}

.pagination a:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  text-decoration: none;
}

.error-panel {
  max-width: 480px;
  margin: 48px auto;
  padding: 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.error-panel h1 {
  margin-bottom: 8px;
}

.content-head-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.admin-users-wrap {
  overflow-x: auto;
}

.admin-users-table {
  min-width: 780px;
  table-layout: auto;
}

.admin-users-table th:first-child,
.admin-users-table td:first-child {
  position: static;
  box-shadow: none;
}

.admin-users-table strong {
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.active {
  color: #116329;
  background: #dafbe1;
  border-color: #4ac26b;
}

.status-badge.inactive {
  color: var(--text-muted);
  background: var(--surface-muted);
}

.actions-cell {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.admin-form {
  display: grid;
  gap: 20px;
}

.admin-section {
  min-width: 0;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.admin-section h2 {
  margin: 0 0 12px;
  font-size: 17px;
  letter-spacing: 0;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 360px));
  gap: 12px;
}

.account-grid input[readonly] {
  color: var(--text-muted);
  background: var(--surface-muted);
}

.toggle-row,
.permission-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.toggle-row {
  margin-top: 14px;
}

.check-label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.permission-list {
  display: grid;
  gap: 8px;
}

.permission-item {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.permission-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.permission-title {
  display: grid;
  grid-template-columns: auto minmax(100px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.permission-title code {
  justify-self: start;
}

.row-filter-editor {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-muted);
}

.row-filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.filter-rows {
  display: grid;
  gap: 6px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 120px minmax(160px, 1fr) 32px;
  gap: 6px;
}

.remove-filter-button {
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--danger-text);
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
}

.remove-filter-button:hover {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.admin-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -8px calc(var(--px) * -1) -28px;
  padding: 10px var(--px);
  background: rgba(246, 248, 250, .96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.action-spacer {
  flex: 1 1 auto;
}

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

.danger-button:hover {
  color: #ffffff;
  background: var(--danger-text);
  border-color: var(--danger-text);
}

@media (max-width: 760px) {
  :root {
    --px: 12px;
    --topbar-h: 46px;
  }

  .topbar {
    padding: 0 var(--px);
  }

  .brand {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page {
    padding: 12px var(--px) 20px;
  }

  .content-head {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 22px;
  }

  p,
  .table-meta {
    font-size: 12px;
  }

  .login-panel {
    margin: 20px auto;
    padding: 18px;
  }

  .table-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .content-head-row {
    align-items: stretch;
  }

  .content-head-row .primary-link {
    align-self: flex-end;
  }

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

  .permission-main,
  .permission-title {
    align-items: flex-start;
  }

  .permission-main {
    display: grid;
  }

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

  .permission-title code {
    grid-column: 1 / -1;
  }

  .filter-row {
    grid-template-columns: minmax(0, 1fr) 110px 32px;
  }

  .filter-row input[name="filter_value"] {
    grid-column: 1 / 3;
    grid-row: 2;
  }

  .filter-row .remove-filter-button {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: stretch;
    height: auto;
  }

  .admin-form-actions {
    margin-bottom: -20px;
  }

  .filter-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }

  .filter-fields {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .filter-actions {
    justify-content: stretch;
  }

  .filter-actions button,
  .filter-actions .button-link {
    flex: 1 1 0;
  }

  .scroll-hint {
    display: inline;
  }

  .table-toolbar {
    align-items: flex-start;
  }

  .table-toolbar-meta {
    display: grid;
    gap: 2px;
  }

  .table-wrap {
    margin-right: calc(var(--px) * -1);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
  }

  table {
    min-width: max(720px, var(--table-min-width));
  }

  th,
  td {
    padding: 7px 10px;
    font-size: 12px;
    scroll-snap-align: start;
  }

  th:first-child,
  td:first-child {
    max-width: 160px;
    overflow-wrap: anywhere;
  }

  .pagination {
    justify-content: stretch;
  }

  .pagination a {
    flex: 1 1 0;
    justify-content: center;
  }
}
