:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #607080;
  --line: #d9e2ea;
  --green: #138a66;
  --green-dark: #0e6f55;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --red: #b42332;
  --amber: #a15c07;
  --shadow: 0 16px 40px rgba(37, 54, 75, .10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 0 16px;
}

button:hover {
  background: var(--green-dark);
}

button:disabled {
  background: #c6d0d9;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.admin-body {
  min-height: 100vh;
}

.admin-layout {
  width: min(1280px, calc(100vw - 32px));
  margin: 28px auto 40px;
}

.topbar {
  align-items: end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 4px;
}

.auth-box {
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 300px) auto;
  padding: 14px;
}

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

.metric,
.workspace-main,
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  gap: 4px;
  min-height: 110px;
  padding: 16px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  font-size: 25px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.selected-metric strong {
  font-size: 20px;
}

.ok-text {
  color: var(--green);
}

.bad-text {
  color: var(--red);
}

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

.workspace-main,
.side-panel {
  padding: 18px;
}

.workspace-side {
  display: grid;
  gap: 12px;
}

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

.section-heading p {
  color: var(--muted);
  margin-top: 5px;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.section-heading.compact button {
  min-height: 34px;
  padding: 0 12px;
}

.filter-bar {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}

.phone-cards {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.phone-card {
  align-items: start;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 6px;
  min-height: 142px;
  padding: 14px;
  text-align: left;
}

.phone-card:hover,
.phone-card.selected {
  background: var(--blue-soft);
  border-color: var(--blue);
  color: var(--text);
}

.phone-card.in-use {
  border-color: #bfe3d5;
}

.phone-select {
  background: transparent;
  color: var(--text);
  display: grid;
  gap: 6px;
  min-height: auto;
  padding: 0;
  text-align: left;
}

.phone-select:hover {
  background: transparent;
  color: var(--text);
}

.phone-name {
  font-size: 17px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.phone-id,
.phone-meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.chip {
  align-self: start;
  background: #eef8f4;
  border: 1px solid #bfe3d5;
  border-radius: 999px;
  color: var(--green-dark);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  justify-self: start;
  padding: 3px 9px;
}

.phone-status-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.usage-chip {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 9px;
}

.usage-chip.free {
  background: #eef2f6;
  color: var(--muted);
}

.usage-chip.busy {
  background: #fff4df;
  color: var(--amber);
}

.create-code-button {
  background: var(--blue);
  width: 100%;
}

.create-code-button:hover {
  background: #1d4ed8;
}

.history-row {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding-top: 10px;
}

.history-row > span {
  color: var(--muted);
  font-size: 13px;
}

.history-row > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-button {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: var(--amber);
  min-height: 32px;
  padding: 0 10px;
}

.history-button:hover {
  background: #ffedd5;
  color: #7c2d12;
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
}

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

.share-result {
  background: #10251f;
  border-radius: 8px;
  color: #dff8ee;
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 16px;
}

.share-result span,
.share-result small {
  color: #9fd9c5;
}

.share-result strong {
  color: #fff;
  font-size: 38px;
  letter-spacing: 0;
  line-height: 1;
}

.share-result button {
  background: var(--blue);
}

.share-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.share-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 10px;
}

.share-item.active {
  background: #f5fbf8;
}

.share-item.disabled {
  background: #f5f7f9;
  color: var(--muted);
}

.share-item strong,
.share-item span {
  display: block;
  overflow-wrap: anywhere;
}

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

.share-item button {
  background: #eef2f6;
  color: var(--red);
  min-height: 34px;
  padding: 0 12px;
}

.output {
  background: #111827;
  border-radius: 8px;
  color: #d7eeff;
  margin: 12px 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
}

.hidden {
  display: none !important;
}

.modal {
  align-items: center;
  background: rgba(13, 23, 35, .46);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.modal-panel {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(17, 24, 39, .25);
  display: grid;
  gap: 14px;
  max-width: 480px;
  padding: 20px;
  width: min(480px, 100%);
}

.modal-heading {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.icon-button {
  align-items: center;
  background: #eef2f6;
  color: var(--text);
  display: inline-flex;
  font-size: 22px;
  justify-content: center;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

.icon-button:hover {
  background: #dde6ee;
}

.modal-phone {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.replace-warning {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #9a3412;
  padding: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: end;
}

.secondary-button {
  background: #eef2f6;
  color: var(--text);
}

.secondary-button:hover {
  background: #dde6ee;
}

.viewer-body {
  background: #101820;
  min-height: 100vh;
}

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

.login-panel,
.web-login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px));
  margin: 14vh auto 0;
  padding: 24px;
}

.web-login-panel h1 {
  margin-bottom: 18px;
}

.web-login-form {
  display: grid;
  gap: 14px;
}

.message {
  color: var(--amber);
  margin-top: 14px;
  min-height: 22px;
}

.web-viewer {
  min-height: 100vh;
}

.cloud-console {
  background: #05080c;
  min-height: 100vh;
}

.control-rail {
  background: #f8fafc;
  border-right: 1px solid #d9e2ea;
  display: grid;
  gap: 14px;
  grid-auto-rows: max-content;
  min-width: 0;
  padding: 18px;
}

.device-summary {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 5px;
  padding-bottom: 14px;
}

.device-summary span {
  color: var(--muted);
  font-size: 13px;
}

.device-summary strong {
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.device-summary small {
  color: var(--muted);
}

.segmented-control {
  background: #e9eff5;
  border-radius: 8px;
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
}

.segmented-control button {
  background: transparent;
  color: var(--muted);
  min-height: 34px;
  padding: 0 8px;
}

.segmented-control button.active,
.segmented-control button:hover {
  background: #fff;
  color: var(--text);
}

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

.quick-actions button {
  background: #2563eb;
  min-width: 0;
  padding: 0 10px;
}

.quick-actions button:hover {
  background: #1d4ed8;
}

.toggle-line {
  align-items: center;
  display: flex;
  gap: 10px;
}

.toggle-line input {
  min-height: auto;
  width: auto;
}

.clipboard-box {
  display: grid;
  gap: 6px;
}

.clipboard-box textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 92px;
  padding: 10px;
  resize: vertical;
}

.phone-stage {
  align-items: center;
  background: #05080c;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-width: 0;
  overflow: hidden;
  padding: 0;
}

.mobile-layout {
  background: #05080c;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  width: 100vw;
}

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

  .auth-box,
  .workspace-grid,
  .stats-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .phone-stage {
    min-height: 100vh;
    padding: 0;
  }

  .mobile-layout {
    height: 100vh;
    min-height: 100vh;
  }
}
