:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #1b1d21;
  --ink-2: #5c616a;
  --ink-3: #8b909a;
  --line: #e4e6ea;
  --hover: #f6f7f8;
  --soft: #eef0f3;
  --accent: #ffdb4d;
  --accent-hover: #ffd21f;
  --red: #ff0000;
  --danger: #c5343a;
  --ok: #0f7b4c;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden], .hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--hover); color: var(--ink); }
.btn-block { width: 100%; }
.btn-link { border: 0; background: none; color: var(--ink-2); height: auto; padding: 8px; }
.btn-link:hover { color: var(--ink); text-decoration: underline; }

.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  text-align: center;
}
.login-logo { width: 40px; height: 44px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; font-weight: 650; }
.login-card p { margin: 0 0 18px; }
.login-checking { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0 8px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--ink-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-profile { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.login-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--soft); font-size: 22px; font-weight: 650; margin-bottom: 8px;
}
.login-profile-name { font-size: 17px; font-weight: 650; }
.login-profile-phone { margin-bottom: 14px; }
.login-tabs { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.login-tab { flex: 1; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--ink-2); }
.login-tab.active { background: var(--surface); color: var(--ink); }
.login-panel { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.qr-box {
  width: 220px; height: 220px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.qr-box img, .qr-box canvas, .qr-box svg { width: 100% !important; height: auto !important; }
.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); outline: none;
}
.input:focus { border-color: #c5c8ce; }
.login-status { min-height: 18px; margin: 12px 0 0; }
.login-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--red);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; }
.brand img { display: block; }
.top-spacer { flex: 1; }
.top-user { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }

.org { position: relative; }
.org-switch {
  min-width: 220px; max-width: 320px; height: 40px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 2px 28px 2px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  text-align: left; position: relative;
}
.org-switch:hover, .org-switch[aria-expanded="true"] { background: var(--hover); }
.org-switch::after {
  content: ""; position: absolute; right: 12px; top: 17px;
  border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid var(--ink-3);
}
.org-kicker { font-size: 11px; color: var(--ink-3); line-height: 1.1; }
.org-name { font-size: 13.5px; font-weight: 650; line-height: 1.2; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  width: 340px; max-height: min(420px, calc(100vh - 80px)); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
}
.org-item, .org-manage {
  width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border: 0; background: none; text-align: left; border-radius: 8px; padding: 8px 10px;
}
.org-item:hover, .org-manage:hover { background: var(--hover); }
.org-item.active { background: var(--soft); }
.org-item strong, .org-manage strong { font-weight: 650; }
.org-item span, .org-manage span { color: var(--ink-2); font-size: 12px; }
.org-menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

.shell { display: flex; min-height: calc(100vh - 56px); }
.sidenav {
  width: 220px; flex: none; padding: 16px 10px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.nav-label {
  margin: 14px 10px 6px; font-size: 11px; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3);
}
.nav-label:first-child { margin-top: 0; }
.nav-link {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px; border-radius: 8px; color: var(--ink);
}
.nav-link:hover { background: var(--hover); }
.nav-link.active { background: var(--soft); font-weight: 650; }
.content { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 6px; font-size: 22px; font-weight: 650; }
.page-head p { margin: 0; color: var(--ink-2); max-width: 720px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.stat b { display: block; font-size: 22px; font-weight: 650; }
.stat span { color: var(--ink-2); font-size: 13px; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px;
}
.panel h2 { margin: 0; padding: 14px 16px; font-size: 15px; font-weight: 650; border-bottom: 1px solid var(--line); }
.panel .pad { padding: 14px 16px; }
.meta { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.meta dt { color: var(--ink-2); }
.meta dd { margin: 0; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 650; color: var(--ink-2); background: var(--hover); }
tr:last-child td { border-bottom: 0; }
.scopes { display: flex; flex-wrap: wrap; gap: 6px; }
.scope {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: 999px; background: var(--soft); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: 999px; background: var(--soft); font-size: 12px; color: var(--ink-2);
}
.badge-ok { background: #e7f6ee; color: var(--ok); }
.badge-wait { background: #fff6d8; color: #7a5b00; }
.app-row { display: flex; gap: 12px; align-items: flex-start; }
.app-mark {
  width: 36px; height: 36px; border-radius: 8px; background: var(--soft);
  display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden;
}
.app-mark img { width: 100%; height: 100%; object-fit: cover; }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-2); }
.note {
  margin: 0 0 16px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink-2);
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.page-head > div { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 650; }
.field > span { font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 450; }
.scope-row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px 12px; align-items: start; }
.form-error { margin: 0; color: var(--danger); }
.secret-value { display: block; padding: 10px 12px; background: var(--hover); border-radius: 8px; word-break: break-all; }
.curl { margin: 0; padding: 10px 12px; background: #1b1d21; color: #f3f4f6; border-radius: 8px; overflow: auto; white-space: pre-wrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
details.panel > summary { padding: 14px 16px; cursor: pointer; font-weight: 650; }
details.panel[open] > summary { border-bottom: 1px solid var(--line); }
textarea.input { height: auto; min-height: 96px; padding: 8px 12px; resize: vertical; }
textarea.code { min-height: 180px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; font-weight: 400; }
select.input { height: 40px; }
.editor { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.editor-code { display: flex; flex-direction: column; gap: 12px; }
.preview { width: 100%; height: 280px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.btn:disabled { opacity: .6; cursor: default; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidenav { width: auto; display: flex; gap: 4px; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .nav-label { display: none; }
  .nav-link { white-space: nowrap; }
  .content { padding: 20px 16px 40px; }
  .stats, .meta, .scope-row, .editor { grid-template-columns: 1fr; }
  .org-switch { min-width: 160px; }
}
