:root {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --ink: #28332f;
  --muted: #73817b;
  --line: #dde6e1;
  --accent: #6f9586;
  --soft: #eef5f1;
  --danger: #b85b5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

body.locked {
  display: block;
}

body.locked .sidebar,
body.locked .main {
  display: none;
}

.login-screen {
  display: none;
}

body.locked .login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  display: grid;
  gap: 18px;
  box-shadow: 0 18px 55px rgba(40, 51, 47, 0.08);
}

.login-card h1 {
  font-size: 28px;
}

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

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button.ghost {
  background: var(--soft);
  color: var(--accent);
}

button.danger {
  background: #fff1f1;
  color: var(--danger);
  border: 1px solid #efd1d1;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand-kicker {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.brand strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.25;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
}

.tab.active {
  background: var(--soft);
  color: var(--accent);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

textarea {
  min-height: 160px;
  resize: vertical;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.main {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 20px;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.panel {
  display: none;
}

.active-panel {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.health-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.health-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.health-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.health-card.good {
  border-color: #cfe9d7;
  background: #f3fbf6;
}

.health-card.warn {
  border-color: #efd9b9;
  background: #fff8ed;
}

.mini-table {
  display: grid;
  gap: 8px;
}

.mini-table-row {
  display: grid;
  grid-template-columns: 170px 100px 150px 170px 150px 120px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-table-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  background: transparent;
  border: 0;
}

.stat,
.card,
.list-card,
.editor-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 32px;
}

.endpoint-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px 14px;
  align-items: center;
}

code {
  padding: 8px 10px;
  border-radius: 8px;
  background: #f2f5f3;
  color: #52665d;
}

.split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

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

.test-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.test-item.active {
  background: var(--soft);
  border-color: #c8ddd3;
}

.test-item span {
  color: var(--muted);
  font-size: 12px;
}

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

.inline-label {
  min-width: 260px;
}

.search-input {
  max-width: 360px;
}

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

.editor-card {
  display: grid;
  gap: 16px;
}

.danger-row {
  display: flex;
  justify-content: flex-end;
}

.apps-editor {
  display: grid;
  gap: 10px;
}

.operation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.operation-card {
  min-height: 172px;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 12px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--app-color, var(--line)) 18%, var(--line));
  border-radius: 8px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--app-accent, #fbfdfc) 92%, #fff) 0%, #fff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.operation-main {
  display: grid;
  gap: 8px;
}

.operation-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--app-color, var(--accent)) 14%, #fff);
  color: var(--app-color, var(--accent));
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.operation-main strong {
  font-size: 20px;
  color: var(--app-color, var(--ink));
}

.operation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.operation-meta span {
  padding: 5px 8px;
  border-radius: 999px;
  background: #f2f5f3;
}

.operation-meta .state-on {
  background: #e8f6ee;
  color: #2f8b58;
}

.operation-meta .state-off {
  background: #f5eeee;
  color: #a26060;
}

.operation-card button {
  width: 100%;
}

.operation-editor {
  display: none;
  gap: 16px;
}

.config-health {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.config-health-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.config-health ul {
  margin: 0;
  padding-left: 20px;
  color: #7a5a35;
  line-height: 1.7;
}

.preset-row,
.editor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.editor-tabs {
  padding: 8px;
  border-radius: 10px;
  background: #f2f5f3;
}

.editor-tab {
  background: transparent;
  color: var(--muted);
}

.editor-tab.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 6px 18px rgba(40, 51, 47, 0.06);
}

.editor-panel {
  display: none;
  gap: 16px;
}

.active-editor-panel {
  display: grid;
}

.hint-card {
  padding: 16px;
  border: 1px dashed #cbded5;
  border-radius: 8px;
  background: #fbfdfc;
}

.merchant-card {
  display: grid;
  gap: 16px;
}

.merchant-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.merchant-sidebar,
.merchant-detail {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdfc;
}

.merchant-sidebar {
  padding: 12px;
}

.merchant-list-head,
.merchant-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.merchant-list-head {
  padding: 4px 4px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.merchant-list {
  display: grid;
  gap: 12px;
}

.merchant-list-item {
  width: 100%;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.merchant-list-item.active {
  border-color: #c8ddd3;
  background: var(--soft);
}

.merchant-list-main strong {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
}

.merchant-list-main span {
  color: var(--muted);
  font-size: 12px;
}

.merchant-detail {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.merchant-detail-head h3 {
  margin: 0;
  font-size: 20px;
}

.merchant-detail-head p {
  margin-top: 6px;
}

.merchant-actions {
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  min-width: 220px;
}

.home-actions-card {
  display: grid;
  gap: 16px;
}

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

.home-action-editor {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdfc;
}

.home-action-editor__head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.home-action-editor__head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.home-action-editor__head strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.switch-row {
  min-width: 112px;
}

.home-action-preview {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e5ece8;
}

.home-action-preview__icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--soft);
  color: var(--accent);
  font-weight: 900;
}

.home-action-preview__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-action-preview strong,
.home-action-preview span {
  display: block;
}

.home-action-preview span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: center;
}

.upload-button {
  height: 38px;
  margin: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-sizing: border-box;
}

.upload-button:hover {
  border-color: var(--accent);
}

.upload-button input {
  display: none;
}

.empty-state {
  padding: 18px;
  border: 1px dashed #cbded5;
  border-radius: 8px;
  background: #fbfdfc;
}

.app-row {
  display: grid;
  grid-template-columns: 90px 150px minmax(160px, 1fr) minmax(150px, 1fr) 90px 80px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.table {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.table-row {
  display: grid;
  grid-template-columns: 64px minmax(240px, 1.2fr) minmax(220px, 1fr) 160px 150px;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  align-items: center;
}

.user-ident,
.row-actions {
  display: grid;
  gap: 6px;
}

.user-ident code,
.table-row code {
  word-break: break-all;
}

.table-row span {
  display: block;
}

.row-actions button {
  width: 100%;
}

.table-head {
  color: var(--muted);
  font-weight: 900;
  background: transparent;
  border: 0;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: 8px;
  background: #27332f;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

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

.users-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.users-toolbar .search-input { width: 220px; }
.users-toolbar select { width: 135px; }
.users-toolbar button { white-space: nowrap; }
.users-table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.users-table th { color: var(--muted); font-weight: 600; background: #f8faf9; }
.users-table th, .users-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.users-table tbody tr:hover { background: #f8faf9; }
.users-table strong { font-weight: 600; }
.users-table .user-detail-button { padding: 7px 12px; }
.user-nickname { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.account-badge { font-size: 12px; padding: 4px 7px; background: #eef5f1; color: #466d5e; border-radius: 4px; }
.account-badge.dev { background: #fff5e3; color: #876226; }
.users-empty { text-align: center; padding: 32px !important; color: var(--muted); }
.users-pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 12px; color: var(--muted); font-size: 13px; }
.users-pagination > div { display: flex; gap: 8px; }
.users-pagination button { width: 36px; height: 36px; padding: 0; font-size: 22px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.users-dialog { width: min(800px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); overflow: auto; }
.users-dialog::backdrop { background: rgba(20, 35, 29, .35); }
.users-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.users-dialog-head h2 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.users-dialog-head span { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.dialog-close { width: 32px; height: 32px; flex: 0 0 32px; padding: 0; background: transparent; color: var(--muted); font-size: 26px; font-weight: 400; }
.dialog-close:hover { background: var(--soft); }
.users-detail-tabs { display: flex; gap: 20px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.users-detail-tabs button { padding: 16px 0 13px; border-radius: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-size: 14px; white-space: nowrap; }
.users-detail-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.users-dialog-body { padding: 22px 24px; overflow-x: auto; }
.detail-table th, .detail-table td { white-space: normal; overflow-wrap: anywhere; vertical-align: top; }
.detail-table td:first-child { width: 28%; }
.report-storage-note, .rights-summary { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.user-report { padding: 18px 0; border-bottom: 1px solid var(--line); }
.user-report:first-of-type { padding-top: 0; }
.user-report:last-child { border-bottom: 0; padding-bottom: 0; }
.user-report header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.user-report h3 { margin: 0; font-size: 15px; }
.user-report time { color: var(--muted); font-size: 12px; }
.user-report > strong { font-size: 18px; }
.user-report p { line-height: 1.8; font-size: 14px; margin: 10px 0 0; overflow-wrap: anywhere; }
.report-short-label { display: inline-block; margin-left: 10px; font-size: 13px; color: var(--muted); }
.rights-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 24px; }
.rights-form label { display: grid; gap: 8px; font-size: 13px; min-width: 150px; flex: 1; }
.rights-form button { min-height: 42px; }
.cleanup-dialog { width: min(560px, calc(100vw - 32px)); }
.cleanup-dialog p { line-height: 1.8; font-size: 14px; overflow-wrap: anywhere; }
.cleanup-count strong { font-size: 26px; color: var(--danger); }
.cleanup-samples { color: var(--muted); }
.cleanup-warning { color: var(--danger); }
.users-dialog-footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); }
.danger-solid { background: var(--danger); }
.dialog-notice { margin: 0; padding: 12px 24px 0; font-size: 13px; color: var(--accent); }
.dialog-notice:empty { display: none; }

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }
  #users .section-head { flex-wrap: wrap; }
  .users-toolbar { width: 100%; }
  .users-toolbar .search-input { flex: 1; min-width: 180px; }

  .split,
  .stats-grid,
  .form-grid,
  .merchant-layout,
  .home-action-list,
  .app-row,
  .mini-table-row {
    grid-template-columns: 1fr;
  }
}
