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

:root {
  --paper: #ffffff;
  --wash: #f5f7fb;
  --wash-strong: #e9edf6;
  --ink: #151823;
  --muted: #687084;
  --line: #d8deea;
  --primary: #2458d6;
  --primary-soft: #e9efff;
  --green: #0e8f68;
  --green-soft: #e4f6ef;
  --amber: #a96d10;
  --amber-soft: #fff2d7;
  --red: #c64132;
  --red-soft: #fde9e5;
  --teal: #0d7f8f;
  --shadow: 0 18px 50px rgba(25, 32, 50, 0.08);
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--wash);
  color: var(--ink);
  font-family: var(--sans);
}

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

button,
.file-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-button:focus-within,
.file-pick:focus-within {
  outline: 3px solid rgba(36, 88, 214, 0.18);
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  min-height: 42px;
  padding: 10px 11px;
}

textarea {
  min-height: 124px;
  resize: vertical;
  line-height: 1.45;
}

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

label span {
  line-height: 1.1;
}

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

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

th {
  background: #f8faff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 14px;
}

.app-bar {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  z-index: 3;
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(25, 32, 50, 0.1);
}

.brand span {
  display: grid;
  gap: 1px;
}

.brand strong {
  font-size: 18px;
  line-height: 1;
}

.brand small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.bar-actions,
.bulk-actions,
.production-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-session {
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 255, 0.88);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
}

.admin-auth-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(160px, 220px) auto auto;
  gap: 10px;
  align-items: end;
}

.production-actions {
  justify-content: flex-end;
}

.status-chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  background: var(--paper);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-chip.online {
  border-color: rgba(14, 143, 104, 0.2);
  background: var(--green-soft);
  color: var(--green);
}

.status-chip.blocked {
  border-color: rgba(198, 65, 50, 0.18);
  background: var(--red-soft);
  color: var(--red);
}

.dashboard-shell {
  width: min(1720px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 360px minmax(620px, 1fr) 380px;
  gap: 18px;
  padding: 18px;
}

.control-stack {
  display: grid;
  align-content: start;
  gap: 18px;
}

.tool-panel,
.manager-panel,
.payload-panel,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.tool-panel,
.payload-panel,
.manager-panel {
  padding: 18px;
}

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

.panel-heading h1,
.panel-heading h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.profile-form,
.bulk-form {
  display: grid;
  gap: 13px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.avatar-field {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.avatar-preview,
.avatar-cell {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2458d6, #0e8f68);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 10px 18px rgba(25, 32, 50, 0.14);
}

.avatar-preview {
  width: 72px;
  height: 72px;
  font-size: 22px;
}

.avatar-cell img,
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-pick,
.file-button {
  position: relative;
}

.file-pick {
  min-height: 52px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fafbfe;
  padding: 12px;
  cursor: pointer;
}

.file-pick input,
.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.file-pick.wide {
  min-height: 58px;
}

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

.secondary-button,
.file-button {
  border-color: rgba(36, 88, 214, 0.16);
  background: var(--primary-soft);
  color: var(--primary);
}

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

.danger-button {
  border-color: rgba(198, 65, 50, 0.14);
  background: var(--red-soft);
  color: var(--red);
}

.button-icon {
  min-width: 24px;
  height: 24px;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.34);
  color: currentColor;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  padding: 14px;
  min-height: 82px;
}

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

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 28px;
  line-height: 1;
}

.manager-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 190px 160px;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.bulk-actions {
  justify-content: flex-start;
  padding: 12px 0 16px;
}

.table-wrap {
  max-height: calc(100vh - 322px);
  min-height: 390px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.profile-cell {
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 11px;
}

.profile-name {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.profile-name strong,
.profile-name span,
.mono {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-name span,
.muted {
  color: var(--muted);
}

.mono {
  display: inline-block;
  max-width: 240px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.status-pill,
.count-chip {
  min-height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.count-chip {
  background: var(--wash-strong);
  color: var(--muted);
}

.status-pill {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.ready {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.created {
  background: var(--primary-soft);
  color: var(--primary);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.payload-panel {
  position: sticky;
  top: 90px;
  align-self: start;
  display: grid;
  grid-template-rows: auto minmax(560px, calc(100vh - 174px));
}

#payloadOutput {
  min-height: 0;
  height: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #283044;
  background: #fbfcff;
  white-space: pre;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin-top: 14px;
  padding: 22px;
  color: var(--muted);
  display: grid;
  gap: 6px;
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: 8px;
  background: #151823;
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 18px 40px rgba(25, 32, 50, 0.22);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
  font-weight: 800;
}

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

.is-hidden {
  display: none !important;
}

@media (max-width: 1320px) {
  .dashboard-shell {
    grid-template-columns: 340px minmax(580px, 1fr);
  }

  .mono {
    max-width: 190px;
  }

  .row-actions button {
    min-width: 32px;
    width: 32px;
    padding: 0;
  }

  .row-actions .button-icon {
    min-width: 22px;
    height: 22px;
  }

  .row-actions button span:not(.button-icon) {
    width: 1px;
    height: 1px;
    margin: -1px;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    overflow: hidden;
    position: absolute;
  }

  .payload-panel {
    grid-column: 1 / -1;
    position: static;
    grid-template-rows: auto 420px;
  }
}

@media (max-width: 980px) {
  .app-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .bar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-session {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-auth-form {
    grid-template-columns: 1fr 1fr;
  }

  .production-actions {
    justify-content: flex-start;
  }

  .dashboard-shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .manager-toolbar {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .app-bar {
    padding: 12px;
  }

  .dashboard-shell {
    padding: 12px;
  }

  .field-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .bar-actions button,
  .bar-actions .file-button,
  .admin-auth-form button,
  .production-actions button,
  .status-chip,
  .bulk-actions button {
    width: 100%;
  }

  .admin-auth-form {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .profile-cell {
    min-width: 180px;
  }
}
