:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111b2d;
  --surface-raised: #162238;
  --surface-input: #0d1626;
  --line: #293852;
  --line-strong: #3a4d6b;
  --accent: #e8ad3a;
  --accent-hover: #f2bd52;
  --blue: #6598ef;
  --green: #51c789;
  --red: #e26d76;
  --text: #f2f5fa;
  --text-soft: #c3ccda;
  --muted: #8f9db2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { overflow-x: clip; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

.ambient { display: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  color: #17110a;
  font-size: 22px;
  font-weight: 800;
  background: var(--accent);
  border-radius: 12px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(23px, 3vw, 30px); letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 21px; letter-spacing: -.015em; }
h3 { margin-bottom: 0; font-size: 16px; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .035em;
}

.account-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
}

.small-button,
.revoke-button,
.danger-button,
.icon-button {
  color: var(--text-soft);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
}

.small-button {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 650;
}

.small-button:hover,
.icon-button:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: #536887;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr);
  gap: 20px;
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 64px;
}

.voxel-card {
  padding: 25px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .16);
}

.card-heading,
.section-title-row,
.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.priority-badge {
  padding: 7px 10px;
  color: #f4c76d;
  font-size: 11px;
  font-weight: 650;
  background: rgba(232, 173, 58, .1);
  border: 1px solid rgba(232, 173, 58, .32);
  border-radius: 999px;
}

label,
legend {
  display: block;
  margin: 20px 0 8px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  padding: 13px 14px;
  color: var(--text);
  background: var(--surface-input);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

input::placeholder,
textarea::placeholder {
  color: #74839a;
}

textarea {
  min-height: 142px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(101, 152, 239, .14);
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.field-hint,
.helper,
.empty-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.field-hint { margin: 9px 0 0; }
.helper { margin: 16px 0 0; }
.empty-hint { margin: 10px 0; }

.device-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  min-height: 40px;
}

.device-choice {
  position: relative;
}

.device-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.device-choice span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-input);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  cursor: pointer;
}

.device-choice span::before {
  content: "";
  width: 14px;
  height: 14px;
  background: transparent;
  border: 1px solid #65748a;
  border-radius: 4px;
}

.device-choice input:focus-visible + span {
  outline: 3px solid rgba(101, 152, 239, .22);
  outline-offset: 2px;
}

.device-choice input:checked + span {
  color: #f7e8c5;
  background: rgba(232, 173, 58, .12);
  border-color: rgba(232, 173, 58, .62);
}

.device-choice input:checked + span::before {
  content: "✓";
  display: grid;
  place-items: center;
  color: #17110a;
  font-size: 11px;
  font-weight: 900;
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button,
.secondary-button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
  padding: 15px 17px;
  color: #181108;
  font-size: 14px;
  font-weight: 750;
  background: var(--accent);
}

.primary-button:hover { background: var(--accent-hover); }
.primary-button:active { background: #d79c2c; }

.secondary-button {
  margin-top: 18px;
  padding: 13px 14px;
  color: #f4f7fb;
  font-size: 13px;
  font-weight: 650;
  background: #315d9f;
}

.secondary-button:hover { background: #3d6db3; }

.primary-button:disabled,
.secondary-button:disabled {
  opacity: .55;
  cursor: wait;
}

.form-result {
  min-height: 22px;
  margin: 14px 0 0;
  color: #8ab5fa;
  font-size: 13px;
}

.form-result.error { color: #f18c94; }

.side-column {
  display: grid;
  gap: 20px;
  align-content: start;
}

.helper code {
  color: #9fc1f7;
  overflow-wrap: anywhere;
}

.pairing-result {
  display: grid;
  gap: 7px;
  margin-top: 20px;
  padding: 17px;
  text-align: center;
  background: rgba(101, 152, 239, .08);
  border: 1px solid rgba(101, 152, 239, .42);
  border-radius: 10px;
}

.pairing-result[hidden] { display: none; }
.pairing-result small { color: var(--muted); font-weight: 600; }
.pairing-result strong {
  color: #a9c8fa;
  font: 750 clamp(24px, 7vw, 34px)/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .09em;
}
.pairing-result span { color: var(--text-soft); font-size: 12px; }
.pairing-result.expired { border-color: rgba(226, 109, 118, .62); }
.pairing-result.expired strong,
.pairing-result.expired span { color: #f18c94; }

.count-badge {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  color: #f8d996;
  font-size: 13px;
  font-weight: 700;
  background: rgba(232, 173, 58, .1);
  border: 1px solid rgba(232, 173, 58, .32);
  border-radius: 999px;
}

.device-list {
  display: grid;
  gap: 9px;
  margin-top: 18px;
}

.device-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  min-height: 72px;
  padding: 11px 12px;
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.device-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 40px;
  color: #8cb4f3;
  font-size: 23px;
  background: #15223a;
  border-radius: 7px;
}

.device-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.device-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.device-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-actions {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: end;
  gap: 7px;
  min-width: 156px;
}

.status-pill {
  grid-column: 1 / -1;
  justify-self: end;
  font-size: 10px;
  font-weight: 700;
}

.status-pill.online { color: #72d59f; }
.status-pill.offline { color: var(--muted); }
.status-pill.revoked { color: #f18c94; }

.revoke-button,
.danger-button {
  padding: 7px 9px;
  font-size: 11px;
  font-weight: 650;
}

.revoke-button {
  color: #e8b9bd;
  border-color: rgba(226, 109, 118, .34);
}

.danger-button {
  color: #f18c94;
  border-color: rgba(226, 109, 118, .42);
}

.revoke-button:hover,
.danger-button:hover {
  color: #ffd5d8;
  background: rgba(226, 109, 118, .1);
  border-color: rgba(226, 109, 118, .68);
}

.danger-button:disabled {
  opacity: .5;
  cursor: wait;
}

.parents-card { padding: 20px 24px; }

.parents-card > summary {
  display: flex;
  cursor: pointer;
  list-style: none;
}

.parents-card > summary::-webkit-details-marker { display: none; }

.parents-card > summary::after {
  content: "+";
  margin-left: auto;
  color: var(--muted);
  font-size: 22px;
  font-weight: 500;
}

.parents-card[open] > summary::after { content: "−"; }
.parents-card > summary .eyebrow { display: block; }
.parents-card > summary strong { font-size: 18px; }

.parent-list {
  display: grid;
  gap: 7px;
  margin-top: 18px;
}

.parent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.parent-copy { display: grid; min-width: 0; }
.parent-row span { color: var(--muted); font-size: 12px; }
.parent-actions { display: flex; align-items: center; gap: 8px; }
.current-parent {
  color: #72d59f !important;
  font-size: 10px !important;
  font-weight: 700;
}

.history-card { grid-column: 1 / -1; }
.history-actions { display: flex; align-items: center; gap: 9px; }

.icon-button {
  width: 36px;
  height: 36px;
  color: var(--text-soft);
  font-size: 20px;
}

.message-history {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 24px;
  padding: 17px;
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.history-main p {
  margin: 8px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.history-title-row time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.delivery-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.stat {
  padding: 6px 9px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.stat.acknowledged {
  color: #8addae;
  border-color: rgba(81, 199, 137, .38);
}

details {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

summary { cursor: pointer; }

.delivery-details {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.delivery-detail {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 8px 10px;
  background: #0a1220;
  border-radius: 7px;
}

.delivery-detail strong { color: var(--text-soft); }
.delivery-detail.overdue {
  color: #f0a2a8;
  border-left: 3px solid var(--red);
}

.deadline-state {
  grid-column: 1 / -1;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  border-radius: 8px;
}

.deadline-state.countdown {
  color: #f2c66f;
  background: rgba(232, 173, 58, .08);
  border: 1px solid rgba(232, 173, 58, .3);
}

.deadline-state.confirmed {
  color: #83daaa;
  background: rgba(81, 199, 137, .08);
  border: 1px solid rgba(81, 199, 137, .3);
}

.deadline-state.overdue {
  color: #ffdadd;
  background: rgba(226, 109, 118, .12);
  border: 1px solid rgba(226, 109, 118, .55);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(460px, 100%);
}

.login-card {
  padding: clamp(26px, 6vw, 38px);
}

.login-hero { text-align: center; }

.login-hero p:last-child {
  max-width: 350px;
  margin: 12px auto 0;
  color: var(--muted);
  line-height: 1.55;
}

.login-mark { margin: 0 auto 20px; }

.security-note {
  display: grid;
  gap: 4px;
  margin-top: 24px;
  padding: 12px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  background: var(--surface-input);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.security-note strong { color: #83daaa; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .history-card { grid-column: auto; }
  .account-area #account-name { display: none; }
}

@media (max-width: 560px) {
  .topbar,
  .layout {
    width: min(100% - 24px, 1200px);
  }

  .topbar { padding: 18px 0; }
  .voxel-card { padding: 20px; border-radius: 13px; }
  .priority-badge { display: none; }
  .history-item { grid-template-columns: 1fr; }
  .delivery-stats { justify-content: flex-start; }
  .device-row { grid-template-columns: 30px minmax(0, 1fr); }
  .device-icon { width: 30px; height: 38px; }
  .device-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    min-width: 0;
  }
  .status-pill { justify-self: start; }
  .device-actions button { min-height: 34px; }
  .delivery-detail { display: grid; }
}
