:root {
  --zmath-bg: #071116;
  --zmath-panel: #0d1a20;
  --zmath-line: #28414a;
  --zmath-text: #edf8f7;
  --zmath-muted: #9bb0b5;
  --zmath-accent: #34ebe0;
  --zmath-warm: #f3c969;
  --zmath-danger: #ff8e86;
}

#zmath-auto-launcher {
  position: fixed;
  right: 16px;
  bottom: 72px;
  z-index: 6000;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--zmath-line);
  border-radius: 6px;
  background: var(--zmath-bg);
  color: var(--zmath-text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  font: 700 13px/1 system-ui, sans-serif;
  cursor: pointer;
}

#zmath-auto-launcher[data-state="ready"] {
  border-color: var(--zmath-accent);
  color: var(--zmath-accent);
}

#zmath-auto-launcher[data-state="matrix"] {
  border-color: var(--zmath-warm);
  color: var(--zmath-warm);
}

#zmath-auto-panel {
  position: fixed;
  right: 16px;
  bottom: 120px;
  z-index: 6001;
  width: min(430px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 140px));
  overflow: auto;
  border: 1px solid var(--zmath-line);
  border-radius: 8px;
  background: var(--zmath-panel);
  color: var(--zmath-text);
  box-shadow: 0 22px 64px rgba(0, 0, 0, 0.58);
  font: 14px/1.45 system-ui, sans-serif;
}

#zmath-auto-panel[hidden] {
  display: none;
}

.zmath-auto-head,
.zmath-auto-row,
.zmath-auto-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zmath-auto-head {
  position: sticky;
  top: 0;
  z-index: 1;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--zmath-line);
  background: var(--zmath-panel);
}

.zmath-auto-head strong {
  font-size: 15px;
}

.zmath-auto-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--zmath-muted);
  font-size: 22px;
  cursor: pointer;
}

.zmath-auto-body {
  padding: 14px;
}

.zmath-auto-state {
  margin: 0 0 12px;
  padding: 9px 10px;
  border-left: 3px solid var(--zmath-warm);
  background: #101f25;
  color: var(--zmath-muted);
}

.zmath-auto-state[data-state="ready"] {
  border-color: var(--zmath-accent);
  color: var(--zmath-text);
}

.zmath-auto-state[data-state="opening"] {
  border-color: var(--zmath-accent);
  color: var(--zmath-text);
}

.zmath-auto-automatic {
  display: grid;
  gap: 4px;
  border: 1px solid var(--zmath-line);
  border-left: 3px solid var(--zmath-accent);
  border-radius: 6px;
  padding: 10px;
  background: #09171b;
}

.zmath-auto-automatic strong {
  color: var(--zmath-accent);
  font-size: 13px;
}

.zmath-auto-automatic p {
  margin: 0;
  color: var(--zmath-muted);
  font-size: 12px;
}

.zmath-auto-quick-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.zmath-auto-quick-links a {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  padding: 7px 8px;
  color: var(--zmath-text);
  background: #102127;
  font-size: 12px;
  font-weight: 750;
  text-align: center;
  text-decoration: none;
}

.zmath-auto-quick-links a:hover,
.zmath-auto-quick-links a:focus-visible {
  border-color: var(--zmath-accent);
  color: var(--zmath-accent);
}

.zmath-auto-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--zmath-line);
  border-radius: 6px;
  overflow: hidden;
}

.zmath-auto-status-grid > div {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 10px;
  background: #09151a;
}

.zmath-auto-status-grid > div:nth-child(odd) {
  border-right: 1px solid var(--zmath-line);
}

.zmath-auto-status-grid > div:nth-child(-n + 2) {
  border-bottom: 1px solid var(--zmath-line);
}

.zmath-auto-status-grid span {
  color: var(--zmath-muted);
  font-size: 11px;
  font-weight: 700;
}

.zmath-auto-status-grid strong {
  overflow-wrap: anywhere;
  color: var(--zmath-text);
  font-size: 12px;
}

.zmath-auto-status-grid strong[data-state="ready"],
.zmath-auto-status-grid strong[data-state="on"] {
  color: var(--zmath-accent);
}

.zmath-auto-status-grid strong[data-state="off"] {
  color: var(--zmath-danger);
}

.zmath-auto-layer-note,
.zmath-auto-room-setup p {
  margin: 9px 0 0;
  color: var(--zmath-muted);
  font-size: 12px;
}

.zmath-auto-room-setup {
  margin: 0;
}

.zmath-auto-simple {
  display: grid;
  gap: 8px;
}

.zmath-auto-simple p {
  margin: 0;
  color: var(--zmath-muted);
  font-size: 12px;
}

.zmath-auto-field {
  display: grid;
  gap: 5px;
  margin: 12px 0;
}

.zmath-auto-field span {
  color: var(--zmath-muted);
  font-size: 12px;
  font-weight: 700;
}

.zmath-auto-field input[type="password"],
.zmath-auto-field input[type="file"] {
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  background: #061015;
  color: var(--zmath-text);
  padding: 8px 10px;
}

.zmath-auto-row {
  justify-content: space-between;
  margin: 10px 0;
}

.zmath-auto-row label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zmath-auto-actions {
  flex-wrap: wrap;
  margin-top: 12px;
}

.zmath-auto-actions button,
.zmath-auto-secondary {
  min-height: 38px;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  background: #14262d;
  color: var(--zmath-text);
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.zmath-auto-actions button {
  flex: 1 1 150px;
}

.zmath-auto-actions .zmath-auto-primary {
  border-color: var(--zmath-accent);
  background: var(--zmath-accent);
  color: #031014;
}

.zmath-auto-setup {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--zmath-accent);
  border-radius: 5px;
  background: var(--zmath-accent);
  color: #031014;
  font-weight: 800;
  cursor: pointer;
}

.zmath-auto-setup[hidden] {
  display: none;
}

.zmath-auto-setup:disabled,
.zmath-auto-actions button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.zmath-auto-recovery {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  border: 1px solid var(--zmath-warm);
  border-radius: 6px;
  padding: 10px;
  background: #16170f;
}

.zmath-auto-recovery[hidden] {
  display: none;
}

.zmath-auto-recovery code {
  overflow-wrap: anywhere;
  color: var(--zmath-warm);
  font-size: 13px;
}

.zmath-auto-recovery button {
  width: fit-content;
  min-height: 34px;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  background: #14262d;
  color: var(--zmath-text);
  padding: 0 10px;
  font-weight: 700;
  cursor: pointer;
}

.zmath-auto-recovery small {
  color: var(--zmath-muted);
}

.zmath-auto-advanced {
  margin-top: 14px;
  border-top: 1px solid var(--zmath-line);
  padding-top: 2px;
}

.zmath-auto-advanced > summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  color: var(--zmath-text);
  cursor: pointer;
  font-weight: 750;
  list-style: none;
}

.zmath-auto-advanced > summary::-webkit-details-marker {
  display: none;
}

.zmath-auto-advanced > summary::after {
  content: "+";
  color: var(--zmath-accent);
  font-size: 20px;
  font-weight: 500;
}

.zmath-auto-advanced[open] > summary::after {
  content: "-";
}

.zmath-auto-advanced-body {
  border-top: 1px solid rgba(40, 65, 74, 0.68);
  padding-top: 12px;
  animation: zmath-auto-reveal 140ms ease-out;
}

.zmath-auto-section h3 {
  margin: 0 0 10px;
  color: var(--zmath-text);
  font-size: 13px;
}

.zmath-auto-section .zmath-auto-simple {
  margin-top: 12px;
}

.zmath-auto-subsection {
  border-top: 1px solid var(--zmath-line);
  margin-top: 12px;
}

.zmath-auto-subsection > summary {
  position: relative;
  display: flex;
  min-height: 44px;
  align-items: center;
  padding-right: 28px;
  color: var(--zmath-text);
  font-size: 13px;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.zmath-auto-subsection > summary::-webkit-details-marker {
  display: none;
}

.zmath-auto-subsection > summary::after {
  content: "+";
  position: absolute;
  right: 4px;
  color: var(--zmath-accent);
  font-size: 18px;
  font-weight: 500;
}

.zmath-auto-subsection[open] > summary::after {
  content: "−";
}

.zmath-auto-subsection-body {
  border-left: 2px solid rgba(52, 235, 224, 0.28);
  padding: 0 0 12px 12px;
  animation: zmath-auto-reveal 140ms ease-out;
}

.zmath-auto-subsection-body > p:first-child {
  margin: 0 0 10px;
  color: var(--zmath-muted);
  font-size: 12px;
  line-height: 1.5;
}

.zmath-auto-help-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--zmath-accent);
  font-size: 12px;
  font-weight: 750;
  text-underline-offset: 3px;
}

.zmath-auto-identifiers {
  display: grid;
  gap: 0;
  margin: 10px 0 0;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  overflow: hidden;
}

.zmath-auto-identifiers > div {
  display: grid;
  grid-template-columns: minmax(120px, 0.72fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 9px;
  background: #09151a;
}

.zmath-auto-identifiers > div + div {
  border-top: 1px solid var(--zmath-line);
}

.zmath-auto-identifiers dt,
.zmath-auto-identifiers dd {
  min-width: 0;
  margin: 0;
}

.zmath-auto-identifiers dt {
  color: var(--zmath-muted);
  font-size: 11px;
  font-weight: 700;
}

.zmath-auto-identifiers code {
  color: var(--zmath-text);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.zmath-auto-field input[type="file"]::file-selector-button {
  min-height: 30px;
  margin-right: 8px;
  border: 1px solid var(--zmath-line);
  border-radius: 4px;
  padding: 0 9px;
  color: var(--zmath-text);
  background: #14262d;
  font-weight: 700;
  cursor: pointer;
}

@keyframes zmath-auto-reveal {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}

.zmath-auto-diagnostic {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  border-top: 1px solid var(--zmath-line);
  padding-top: 12px;
}

.zmath-auto-diagnostic button {
  width: fit-content;
  min-height: 36px;
  border: 1px solid var(--zmath-line);
  border-radius: 5px;
  background: #14262d;
  color: var(--zmath-text);
  padding: 0 11px;
  font-weight: 700;
  cursor: pointer;
}

.zmath-auto-diagnostic p {
  margin: 0;
  color: var(--zmath-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.zmath-auto-diagnostic p[data-state="passed"] {
  color: var(--zmath-accent);
}

.zmath-auto-danger {
  color: var(--zmath-danger) !important;
}

.zmath-auto-meta {
  margin: 10px 0 0;
  color: var(--zmath-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

#zmath-auto-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 7000;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 1px solid var(--zmath-line);
  border-radius: 6px;
  background: #071116;
  color: var(--zmath-text);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.52);
}

#zmath-auto-toast[hidden] {
  display: none;
}

.zmath-auto-opened {
  margin-top: 5px;
  padding: 8px 10px;
  border-left: 3px solid var(--zmath-accent);
  background: rgba(52, 235, 224, 0.07);
  color: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.zmath-auto-opened::before {
  content: "Protected";
  display: block;
  margin-bottom: 4px;
  color: var(--zmath-accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.zmath-auto-opened[data-state="locked"] {
  border-left-color: var(--zmath-warm);
  background: rgba(243, 201, 105, 0.07);
}

.zmath-auto-opened[data-state="legacy"] {
  border-left-color: var(--zmath-warm);
  background: rgba(243, 201, 105, 0.07);
}

.zmath-auto-opened[data-state="legacy"]::before {
  content: "Earlier protected message";
  color: var(--zmath-warm);
}

.zmath-auto-opened[data-state="locked"]::before {
  content: "Protected message";
  color: var(--zmath-warm);
}

.zmath-auto-opened[data-state="opening"]::before {
  content: "Opening securely";
}

.zmath-auto-opened[data-state="syncing"] {
  border-left-color: var(--zmath-accent);
  background: rgba(52, 235, 224, 0.05);
}

.zmath-auto-opened[data-state="syncing"]::before {
  content: "Preparing protection";
}

.zmath-room-control-event {
  display: none !important;
}

.zmath-auto-ciphertext-source,
.zmath-auto-legacy-hidden {
  display: none !important;
}

.zmath-room-control {
  display: grid;
  gap: 8px;
  margin-top: 5px;
  border-left: 3px solid var(--zmath-warm);
  padding: 9px 10px;
  background: rgba(243, 201, 105, 0.07);
  color: inherit;
  overflow-wrap: anywhere;
}

.zmath-room-control[hidden] {
  display: none !important;
}

.zmath-room-control::before {
  content: "Protected room key";
  color: var(--zmath-warm);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.zmath-room-control[data-state="ready"],
.zmath-room-control[data-state="sent"] {
  border-left-color: var(--zmath-accent);
  background: rgba(52, 235, 224, 0.07);
}

.zmath-room-control[data-state="ready"]::before,
.zmath-room-control[data-state="sent"]::before {
  color: var(--zmath-accent);
}

.zmath-room-control-action {
  width: fit-content;
  min-height: 36px;
  border: 1px solid var(--zmath-accent);
  border-radius: 5px;
  background: var(--zmath-accent);
  color: #031014;
  padding: 0 11px;
  font-weight: 800;
  cursor: pointer;
}

.zmath-room-control-action:disabled {
  cursor: progress;
  opacity: 0.68;
}

.zmath-auto-busy {
  cursor: progress !important;
  opacity: 0.72;
}

.zmath-auto-control-sync [contenteditable="true"],
.zmath-auto-control-sync textarea,
.zmath-auto-control-sync .mx_MessageComposer_sendMessage {
  pointer-events: none !important;
}

.zmath-auto-control-sync [contenteditable="true"],
.zmath-auto-control-sync textarea {
  color: transparent !important;
  caret-color: transparent !important;
}

@media (max-width: 600px) {
  #zmath-auto-launcher {
    right: 10px;
    bottom: 64px;
  }

  #zmath-auto-panel {
    right: 6px;
    top: calc(var(--cc-bar-height, 48px) + env(safe-area-inset-top) + 6px);
    bottom: max(8px, env(safe-area-inset-bottom));
    width: calc(100vw - 12px);
    max-height: none;
    border-radius: 6px;
  }

  .zmath-auto-body {
    padding: 12px;
  }

  .zmath-auto-status-grid {
    grid-template-columns: 1fr;
  }

  .zmath-auto-status-grid > div:nth-child(odd) {
    border-right: 0;
  }

  .zmath-auto-status-grid > div,
  .zmath-auto-status-grid > div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--zmath-line);
  }

  .zmath-auto-status-grid > div:last-child {
    border-bottom: 0;
  }

  .zmath-auto-actions,
  .zmath-auto-actions button,
  .zmath-auto-diagnostic button {
    width: 100%;
  }

  .zmath-auto-actions button {
    flex-basis: 100%;
  }

  .zmath-auto-identifiers > div {
    grid-template-columns: 1fr;
  }
}
