:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f5ee;
  --ink: #20231f;
  --muted: #686e66;
  --line: #dce2d8;
  --green: #178b57;
  --green-dark: #0e643f;
  --amber: #b56a13;
  --red: #b42318;
  --violet: #5446a3;
  --shadow: 0 18px 45px rgba(35, 40, 32, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1,
.topbar h1,
.section-header h2,
.panel h3,
.doc-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: 28px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(23, 139, 87, 0.22);
  outline-offset: 2px;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  white-space: nowrap;
}

.button span,
.nav-item span {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 4px;
  background: rgba(32, 35, 31, 0.08);
  font-size: 12px;
  font-weight: 800;
}

.button.primary {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.button.danger {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.button.ghost {
  border-color: var(--line);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.account-chip {
  display: grid;
  line-height: 1.2;
  padding-right: 6px;
}

.account-chip strong {
  font-size: 14px;
}

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

.usage-text {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  min-height: 76px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  font-size: 23px;
}

.topbar-actions,
.actions-row,
.inline-form,
.field-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.workspace {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
}

.sidebar {
  align-self: start;
  display: grid;
  gap: 8px;
  position: sticky;
  top: 96px;
}

.nav-item {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  color: var(--muted);
  text-align: left;
}

.nav-item.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.section-header h2 {
  font-size: 24px;
}

.inline-form {
  justify-content: flex-end;
}

.inline-form input {
  width: min(300px, 55vw);
}

.instance-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 16px;
}

.panel,
.doc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(35, 40, 32, 0.05);
}

.panel-heading,
.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading.compact {
  margin-top: 18px;
}

.counter {
  min-width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 99px;
  color: var(--green-dark);
  background: var(--surface-strong);
  font-weight: 800;
}

.session-list,
.key-list,
.queue-list {
  display: grid;
  gap: 10px;
}

.session-item,
.key-item,
.queue-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.session-item {
  text-align: left;
}

.session-item.active {
  border-color: rgba(23, 139, 87, 0.55);
  box-shadow: inset 3px 0 0 var(--green);
}

.item-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
}

.item-title strong {
  overflow-wrap: anywhere;
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.status-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.connected {
  color: #fff;
  background: var(--green);
}

.status-pill.qr_pending,
.status-pill.connecting {
  color: #fff;
  background: var(--amber);
}

.status-pill.disconnected,
.status-pill.neutral {
  color: var(--muted);
  background: #ecefeb;
}

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

.qr-area {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(180px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.qr-frame {
  min-height: 300px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  display: grid;
  place-items: center;
  padding: 14px;
  text-align: center;
  color: var(--muted);
}

.qr-frame img {
  max-width: 100%;
  width: 260px;
  height: auto;
}

.meta-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.meta-list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.meta-list span,
.secret-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.meta-list strong,
.secret-box code,
.doc-card code {
  overflow-wrap: anywhere;
}

.split {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr);
  gap: 16px;
  align-items: end;
}

.secret-box {
  border: 1px solid rgba(84, 70, 163, 0.3);
  border-radius: 8px;
  padding: 12px;
  background: #f7f5ff;
}

.secret-box code {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
}

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

.doc-card.wide {
  grid-column: 1 / -1;
}

.doc-card p {
  color: var(--muted);
}

.doc-card h4 {
  margin: 14px 0 0;
  font-size: 14px;
}

.doc-card ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.doc-card .data-table {
  font-size: 13px;
}

pre {
  margin: 10px 0 0;
  padding: 12px;
  overflow-x: auto;
  border-radius: 8px;
  background: #20231f;
  color: #f5f8f2;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.empty-state,
.error-text {
  color: var(--muted);
  margin: 0;
}

.error-text {
  color: var(--red);
  min-height: 20px;
  margin-top: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #20231f;
  box-shadow: var(--shadow);
}

/* Manager panel: single-column workspace, stats, tables and dialogs */

.workspace.single {
  grid-template-columns: minmax(0, 1fr);
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 4px;
  box-shadow: 0 6px 18px rgba(35, 40, 32, 0.05);
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--green-dark);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

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

.actions-col {
  white-space: nowrap;
}

.actions-col .button {
  margin: 2px 4px 2px 0;
}

.dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(20, 23, 19, 0.45);
}

.dialog h3 {
  margin: 0 0 6px;
}

.dialog .actions-row {
  margin-top: 8px;
}

@media (max-width: 900px) {
  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .sidebar {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
  }

  .instance-layout,
  .qr-area,
  .split,
  .docs-grid {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .topbar-actions,
  .actions-row,
  .field-row {
    width: 100%;
  }

  .inline-form input,
  .inline-form select,
  .button,
  .field-row input {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .topbar,
  .workspace,
  .login-shell {
    padding: 14px;
  }

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

  .login-panel,
  .panel,
  .doc-card {
    padding: 14px;
  }
}
