/* SMS Gateway dashboard. Plain CSS, no build step. Colors are tokens on :root; dark mode follows the
   OS unless the user picked a theme (html[data-theme]). */

/* ============================================================================================
   Tokens
   ============================================================================================ */

:root {
  color-scheme: light;

  --bg: #f7f7f8;
  --bg-elevated: #ffffff;
  --bg-subtle: #f3f3f5;
  --bg-muted: #ebebef;
  --bg-overlay: rgb(15 15 20 / 0.45);
  --code-bg: #f8f8fa;
  --border: #e4e4e9;
  --border-strong: #d0d0d8;

  --text: #18181b;
  --text-muted: #5c5c68;
  --text-subtle: #858590;

  --accent: #5b5bd6;
  --accent-hover: #4b4bc5;
  --accent-text: #4747c2;
  --accent-soft: #eeeefd;
  --accent-contrast: #ffffff;
  --focus-ring: #6e6ef0;

  --success: #18794e;
  --success-solid: #22a06b;
  --success-soft: #e7f6ee;
  --success-border: #bfe5d0;
  --danger: #c4320a;
  --danger-solid: #d1361f;
  --danger-soft: #fdeeea;
  --danger-border: #f6cbbf;
  --warning: #9a5b00;
  --warning-solid: #e5a00d;
  --warning-soft: #fff5e1;
  --warning-border: #f3dca8;
  --info: #1f5fbf;
  --info-solid: #3b82f6;
  --info-soft: #eaf2fe;
  --info-border: #c6dafa;
  --teal: #0b7468;
  --teal-soft: #e2f5f2;
  --neutral-soft: #f0f0f3;

  --shadow-xs: 0 1px 2px rgb(16 16 24 / 0.05);
  --shadow-sm: 0 1px 3px rgb(16 16 24 / 0.07), 0 1px 2px rgb(16 16 24 / 0.04);
  --shadow-lg: 0 16px 40px -12px rgb(16 16 24 / 0.22), 0 4px 10px -4px rgb(16 16 24 / 0.08);

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 240px;
  --topbar-height: 56px;

  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0d0d10;
    --bg-elevated: #151518;
    --bg-subtle: #1b1b1f;
    --bg-muted: #24242a;
    --bg-overlay: rgb(0 0 0 / 0.6);
    --code-bg: #111114;
    --border: #27272d;
    --border-strong: #36363e;

    --text: #ececf1;
    --text-muted: #a3a3ae;
    --text-subtle: #777782;

    --accent: #5b5bd6;
    --accent-hover: #6b6be3;
    --accent-text: #a9a9ff;
    --accent-soft: rgb(110 110 240 / 0.16);
    --focus-ring: #8b8bf5;

    --success: #4cc38a;
    --success-solid: #2f9e6a;
    --success-soft: rgb(76 195 138 / 0.13);
    --success-border: rgb(76 195 138 / 0.3);
    --danger: #ff7b6b;
    --danger-solid: #d63f2b;
    --danger-soft: rgb(255 123 107 / 0.12);
    --danger-border: rgb(255 123 107 / 0.3);
    --warning: #f5b94a;
    --warning-solid: #d99a14;
    --warning-soft: rgb(245 185 74 / 0.12);
    --warning-border: rgb(245 185 74 / 0.3);
    --info: #7cb4ff;
    --info-solid: #3b82f6;
    --info-soft: rgb(124 180 255 / 0.12);
    --info-border: rgb(124 180 255 / 0.3);
    --teal: #4fd1c0;
    --teal-soft: rgb(79 209 192 / 0.12);
    --neutral-soft: #222228;

    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 18px 44px -12px rgb(0 0 0 / 0.7), 0 4px 12px -4px rgb(0 0 0 / 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0d0d10;
  --bg-elevated: #151518;
  --bg-subtle: #1b1b1f;
  --bg-muted: #24242a;
  --bg-overlay: rgb(0 0 0 / 0.6);
  --code-bg: #111114;
  --border: #27272d;
  --border-strong: #36363e;

  --text: #ececf1;
  --text-muted: #a3a3ae;
  --text-subtle: #777782;

  --accent: #5b5bd6;
  --accent-hover: #6b6be3;
  --accent-text: #a9a9ff;
  --accent-soft: rgb(110 110 240 / 0.16);
  --focus-ring: #8b8bf5;

  --success: #4cc38a;
  --success-solid: #2f9e6a;
  --success-soft: rgb(76 195 138 / 0.13);
  --success-border: rgb(76 195 138 / 0.3);
  --danger: #ff7b6b;
  --danger-solid: #d63f2b;
  --danger-soft: rgb(255 123 107 / 0.12);
  --danger-border: rgb(255 123 107 / 0.3);
  --warning: #f5b94a;
  --warning-solid: #d99a14;
  --warning-soft: rgb(245 185 74 / 0.12);
  --warning-border: rgb(245 185 74 / 0.3);
  --info: #7cb4ff;
  --info-solid: #3b82f6;
  --info-soft: rgb(124 180 255 / 0.12);
  --info-border: rgb(124 180 255 / 0.3);
  --teal: #4fd1c0;
  --teal-soft: rgb(79 209 192 / 0.12);
  --neutral-soft: #222228;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 18px 44px -12px rgb(0 0 0 / 0.7), 0 4px 12px -4px rgb(0 0 0 / 0.5);
}

/* ============================================================================================
   Base
   ============================================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

img,
svg {
  display: block;
}

.icon {
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

[tabindex="-1"]:focus:not(:focus-visible) {
  outline: none;
}

[hidden] {
  display: none !important;
}

:not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.08em 0.36em;
  overflow-wrap: anywhere;
}

::selection {
  background: rgb(91 91 214 / 0.25);
}

/* ============================================================================================
   Utilities
   ============================================================================================ */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 12.5px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.93em;
}

.strong {
  font-weight: 500;
}

.truncate {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spacer {
  flex: 1;
}

.numeric {
  font-variant-numeric: tabular-nums;
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.inline-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.clipboard-buffer {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.noscript {
  padding: 24px;
  text-align: center;
}

/* ============================================================================================
   Loading, skeletons, spinners
   ============================================================================================ */

.spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.75;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.splash {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--text-muted);
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-muted) 0%, var(--bg-subtle) 50%, var(--bg-muted) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-text {
  height: 12px;
  width: 55%;
}

.skeleton-value {
  height: 26px;
  width: 40%;
  margin-top: 14px;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

.pulse {
  position: relative;
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success-solid);
}

.pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: pulse-ring 1.8s ease-out infinite;
}

@keyframes pulse-ring {
  from {
    transform: scale(1);
    opacity: 0.6;
  }
  to {
    transform: scale(2.6);
    opacity: 0;
  }
}

/* ============================================================================================
   Buttons
   ============================================================================================ */

.btn {
  --spinner-color: currentColor;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgb(255 255 255 / 0.12);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-ghost {
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text);
}

.btn-danger {
  background: var(--danger-solid);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.text-danger {
  color: var(--danger);
}

.btn.text-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  gap: 6px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

.btn-icon {
  width: 34px;
  padding: 0;
}

.btn-sm.btn-icon {
  width: 28px;
}

.btn-block {
  width: 100%;
}

.btn.is-copied {
  color: var(--success);
}

/* Busy: hide the label but keep the button's size, and show a spinner in its place. */
.btn.is-busy {
  color: transparent !important;
}

.btn.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--text);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-primary.is-busy::after,
.btn-danger.is-busy::after {
  border-color: #fff;
  border-right-color: transparent;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: 500;
  text-align: left;
}

.link-button:hover {
  color: var(--accent-text);
  text-decoration: underline;
}

/* ============================================================================================
   Forms
   ============================================================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}

.field-optional {
  color: var(--text-subtle);
  font-size: 12px;
  font-weight: 400;
}

.field-hint {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.field-error {
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
}

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

.fieldset legend {
  padding: 0;
  margin-bottom: 8px;
}

.input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.input::placeholder {
  color: var(--text-subtle);
}

.input:hover:not(:disabled):not(:focus) {
  border-color: var(--text-subtle);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:disabled {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.input[readonly] {
  background: var(--bg-subtle);
}

.textarea {
  height: auto;
  min-height: 72px;
  padding: 9px 11px;
  line-height: 1.5;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  text-overflow: ellipsis;
}

.input-group {
  display: flex;
}

.input-group > .input:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group > .input:last-child {
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.input-group > .input:focus {
  position: relative;
  z-index: 1;
}

.input-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* The resolved sender shown under the Send page's Sender select. */
.sender-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 12.5px;
}

/* Switch (role="switch") */
.switch {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color 0.15s;
}

.switch[aria-checked="true"] {
  background: var(--accent);
}

.switch:disabled {
  opacity: 0.6;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s;
}

.switch[aria-checked="true"] .switch-thumb {
  transform: translateX(16px);
}

.switch-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.switch-label {
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

/* Segmented control (radio group) */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--bg-muted);
}

.segmented-option {
  position: relative;
}

.segmented-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segmented-option span {
  display: block;
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.segmented-option input:checked + span {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented-option input:focus-visible + span {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

/* Checkbox cards */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.checkbox-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}

.checkbox-card:hover {
  border-color: var(--border-strong);
}

.checkbox-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.checkbox-card input {
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.checkbox-card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.checkbox-card-label {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
}

.checkbox-card-description {
  color: var(--text-muted);
  font-size: 12.5px;
}

/* ============================================================================================
   Callouts, badges, chips
   ============================================================================================ */

.callout {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius);
  background: var(--info-soft);
  font-size: 13.5px;
}

.callout:not(:has(.callout-icon)) {
  display: block;
}

.callout-icon {
  margin-top: 2px;
  color: var(--info);
}

.callout-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.callout-title {
  font-weight: 600;
}

.callout-warning {
  border-color: var(--warning-border);
  background: var(--warning-soft);
}

.callout-warning .callout-icon {
  color: var(--warning);
}

.callout-danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.callout-danger .callout-icon,
.callout-danger:not(:has(.callout-icon)) {
  color: var(--danger);
}

.callout-success {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.callout-success .callout-icon {
  color: var(--success);
}

.badge {
  --badge-color: var(--text-muted);
  --badge-bg: var(--neutral-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-color);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-neutral {
  --badge-color: var(--text-muted);
  --badge-bg: var(--neutral-soft);
}

.badge-success,
.status-delivered {
  --badge-color: var(--success);
  --badge-bg: var(--success-soft);
}

.badge-info,
.status-dispatched,
.status-sending,
.status-pending {
  --badge-color: var(--info);
  --badge-bg: var(--info-soft);
}

.badge-warning,
.status-expired {
  --badge-color: var(--warning);
  --badge-bg: var(--warning-soft);
}

.status-failed {
  --badge-color: var(--danger);
  --badge-bg: var(--danger-soft);
}

.status-sent {
  --badge-color: var(--accent-text);
  --badge-bg: var(--accent-soft);
}

.status-received {
  --badge-color: var(--teal);
  --badge-bg: var(--teal-soft);
}

.status-queued,
.status-cancelled,
.status-unknown {
  --badge-color: var(--text-muted);
  --badge-bg: var(--neutral-soft);
}

.status-sending .badge-dot,
.status-pending .badge-dot,
.status-dispatched .badge-dot {
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--neutral-soft);
  font-family: var(--font-mono);
  font-size: 12px;
}

.encoding-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--neutral-soft);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.encoding-badge.is-unicode {
  background: var(--warning-soft);
  color: var(--warning);
}

/* Direction arrows, online dots, battery */
.direction {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: none;
}

.direction-out {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.direction-in {
  background: var(--teal-soft);
  color: var(--teal);
}

.online-dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}

.online-dot.is-online {
  background: var(--success-solid);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.battery {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.battery-body {
  position: relative;
  display: block;
  width: 22px;
  height: 11px;
  padding: 1.5px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
}

.battery-body::after {
  content: "";
  position: absolute;
  top: 2px;
  right: -4px;
  width: 2px;
  height: 4px;
  border-radius: 0 1px 1px 0;
  background: currentColor;
}

.battery-fill {
  display: block;
  height: 100%;
  border-radius: 1px;
  background: currentColor;
}

.battery.is-medium .battery-fill {
  background: var(--warning-solid);
}

.battery.is-low {
  color: var(--danger);
}

.battery.is-charging .battery-fill,
.battery-bolt {
  color: var(--success);
  background-color: transparent;
}

.battery.is-charging .battery-fill {
  background: var(--success-solid);
}

/* ============================================================================================
   App shell
   ============================================================================================ */

.skip-link {
  position: fixed;
  top: -48px;
  left: 12px;
  z-index: 2000;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
}

.skip-link:focus {
  top: 12px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 14px 0 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.18);
}

.menu-button {
  display: none;
}

.sidebar-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 12px;
}

.nav-group + .nav-group {
  margin-top: 18px;
}

.nav-heading {
  padding: 0 10px 6px;
  color: var(--text-subtle);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
}

.nav-link:hover {
  background: var(--bg-muted);
  color: var(--text);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.nav-link[aria-current="page"] .icon {
  color: var(--accent-text);
}

.account {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px 12px 14px;
  border-top: 1px solid var(--border);
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
}

.account-text {
  flex: 1;
  min-width: 0;
  margin-left: 4px;
}

.account-name,
.account-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-name {
  font-size: 13px;
  font-weight: 500;
}

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

.main {
  min-width: 0;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 32px 40px 72px;
}

.main > * {
  max-width: 1200px;
  margin-inline: auto;
}

.main:focus {
  outline: none;
}

/* ============================================================================================
   Page structure
   ============================================================================================ */

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

.page-heading {
  min-width: 0;
  max-width: 680px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
}

.page-description {
  margin-top: 4px;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.card-link {
  font-size: 13px;
  font-weight: 500;
}

.card-body {
  padding: 18px;
}

.card-body > .list {
  margin: -18px;
}

.section-label {
  margin: 0 0 8px;
  color: var(--text-subtle);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Empty / loading / error states */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 44px 24px;
  text-align: center;
}

.state-loading {
  flex-direction: row;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
}

.state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-muted);
}

.state-error .state-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.state-title {
  font-size: 15px;
  font-weight: 600;
}

.state-description {
  max-width: 440px;
  color: var(--text-muted);
}

.state-action {
  margin-top: 10px;
}

.main > .state-empty,
.main > div > .state-empty,
.main > div > .state-error,
.main > div > .state-loading {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

/* Definition lists */
.definition-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

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

.definition dt {
  color: var(--text-muted);
  font-size: 13px;
}

.definition dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Code */
.code-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  overflow: hidden;
}

.code-block + .code-block,
.code-block + p,
p + .code-block,
.table-scroll + p,
.code-block + .table-scroll {
  margin-top: 12px;
}

.code-block-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 5px 6px 5px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.code-block-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.code-block pre,
.json-block {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  tab-size: 2;
}

.code-block pre:focus-visible,
.json-block:focus-visible {
  outline-offset: -2px;
}

.json-block {
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
}

.copyable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
}

.copyable .copyable-value {
  min-width: 0;
  padding: 4px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  overflow-wrap: normal;
}

/* Tables */
.table-scroll {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

.table th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.table-compact th {
  padding: 8px 12px;
}

.table-compact td {
  padding: 9px 12px;
}

.table-card .table {
  min-width: 640px;
}

.cell-actions {
  text-align: right;
  white-space: nowrap;
}

.cell-error {
  max-width: 280px;
  color: var(--danger);
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px;
}

/* Rows in cards */
.list {
  display: flex;
  flex-direction: column;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 18px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 13.5px;
}

.list-row:first-child {
  border-top: 0;
}

.list-row:hover {
  background: var(--bg-subtle);
  text-decoration: none;
}

.list-row:focus-visible {
  outline-offset: -2px;
}

.list-row-main {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 500;
}

.list-row-subtitle {
  margin-top: 1px;
  color: var(--text-muted);
  font-size: 12.5px;
}

.list-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

/* ============================================================================================
   Toasts
   ============================================================================================ */

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 11px 10px 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s, transform 0.18s;
}

.toast-icon {
  margin-top: 2px;
  color: var(--info);
}

.toast-success .toast-icon {
  color: var(--success);
}

.toast-error .toast-icon {
  color: var(--danger);
}

.toast-warning .toast-icon {
  color: var(--warning);
}

.toast-message {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin: -1px 0 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--text-subtle);
}

.toast-close:hover {
  background: var(--bg-muted);
  color: var(--text);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ============================================================================================
   Modals and drawers (<dialog>)
   ============================================================================================ */

.modal {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal[open] {
  display: grid;
}

.modal::backdrop {
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
}

.modal-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.16s ease-out;
}

.modal-sm {
  max-width: 440px;
}

.modal-md {
  max-width: 540px;
}

.modal-lg {
  max-width: 900px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 0;
}

.modal-heading {
  flex: 1;
  min-width: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.modal-description {
  margin-top: 4px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.modal-close {
  margin: -6px -8px 0 0;
}

.modal-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 20px 20px;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 14px 14px;
  background: var(--bg-subtle);
}

.modal-footer:empty {
  display: none;
}

.confirm-message {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* Drawer variant: full-height panel on the right. */
.modal-drawer {
  padding: 0;
  overflow: hidden;
}

.modal-drawer .modal-panel {
  width: min(500px, 100%);
  max-width: none;
  height: 100%;
  margin: 0 0 0 auto;
  border-width: 0 0 0 1px;
  border-radius: 0;
  animation: drawer-in 0.2s ease-out;
}

.modal-drawer .modal-header {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.modal-drawer .modal-body {
  flex: 1;
  overflow-y: auto;
}

.modal-drawer .modal-footer {
  border-radius: 0;
}

@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

/* ============================================================================================
   Sign in / register
   ============================================================================================ */

.auth-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 16px;
  background:
    radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.auth-brand {
  margin-bottom: 22px;
}

.auth-main {
  width: 100%;
  max-width: 400px;
}

.auth-main:focus {
  outline: none;
}

.auth-card {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
}

.auth-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.auth-subtitle {
  margin: 6px 0 22px;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form .btn {
  height: 38px;
  margin-top: 4px;
}

.auth-footer {
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: center;
}

/* ============================================================================================
   Overview
   ============================================================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  min-height: 108px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xs);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.stat-icon {
  color: var(--text-subtle);
}

.stat-value {
  margin-top: 10px;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-hint {
  margin-top: auto;
  padding-top: 4px;
  color: var(--text-muted);
  font-size: 12.5px;
}

.tone-success .stat-icon {
  color: var(--success);
}

.tone-danger .stat-icon,
.tone-danger .stat-value {
  color: var(--danger);
}

.tone-warning .stat-icon {
  color: var(--warning);
}

.stats-error {
  grid-column: 1 / -1;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

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

/* ============================================================================================
   Devices
   ============================================================================================ */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 16px;
  align-items: start;
}

.device-card {
  display: flex;
  flex-direction: column;
}

.device-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 0;
}

.device-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.device-card.is-disabled .device-avatar {
  background: var(--bg-muted);
  color: var(--text-subtle);
}

.device-heading {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

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

.device-card-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 14px;
  font-size: 13px;
}

.device-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.device-status.is-online {
  color: var(--success);
  font-weight: 500;
}

.device-facts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 12px;
  margin: 0 18px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.device-facts .definition {
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
}

.device-facts dt {
  font-size: 12px;
}

.device-section {
  padding: 14px 18px 0;
}

.sim-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sim {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.sim-icon {
  margin-top: 3px;
  color: var(--text-muted);
}

.sim-text {
  min-width: 0;
  flex: 1 1 auto;
}

.sim-name {
  font-size: 13px;
  font-weight: 500;
}

.sim-edit {
  flex: none;
  margin-top: -2px;
}

.sim-note {
  margin: 10px 0 0;
}

.device-card-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

/* Pairing */
.pair-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 28px;
}

.pair-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 240px;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: 14px;
  /* QR codes need a light background in every theme. */
  background: #fff;
  color: #3f3f46;
  overflow: hidden;
}

.qr-image {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.qr-frame.is-expired .qr-image {
  filter: blur(3px);
  opacity: 0.3;
}

.qr-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #18181b;
  font-weight: 600;
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  font-size: 13px;
}

.qr-error {
  color: #b42318;
}

.qr-error .btn-secondary {
  background: #fff;
  border-color: #d0d0d8;
  color: #18181b;
}

.pair-code {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.pair-code-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.countdown {
  width: 240px;
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: center;
}

.countdown-track {
  display: block;
  height: 4px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--bg-muted);
  overflow: hidden;
}

.countdown-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 1s linear;
}

.countdown.is-urgent {
  color: var(--warning);
}

.countdown.is-urgent .countdown-fill {
  background: var(--warning-solid);
}

.pair-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  display: flex;
  gap: 12px;
}

.step-number {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
}

.step-body {
  min-width: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

.step-body p + p {
  margin-top: 2px;
}

.step-title {
  color: var(--text);
  font-weight: 600;
}

.server-url-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.server-url-actions {
  display: flex;
  justify-content: flex-start;
}

.url-warning:empty {
  display: none;
}

.url-warning .callout p + p {
  margin-top: 4px;
}

.pair-waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 13.5px;
}

.pair-waiting .pulse {
  background: var(--accent);
}

.pair-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 8px;
  text-align: center;
}

.success-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
}

.pair-success-title {
  font-size: 18px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ============================================================================================
   Send SMS
   ============================================================================================ */

.send-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.send-main,
.send-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.send-aside {
  position: sticky;
  top: 24px;
}

.send-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.unicode-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12.5px;
}

.unicode-note .icon {
  margin-top: 2px;
}

.advanced {
  border: 1px solid var(--border);
  border-radius: 10px;
}

.advanced summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  list-style: none;
  cursor: pointer;
}

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

.advanced summary:hover {
  background: var(--bg-subtle);
}

.advanced-chevron {
  transition: transform 0.15s;
}

.advanced[open] .advanced-chevron {
  transform: rotate(90deg);
}

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 6px 14px 16px;
}

.ttl-amount {
  flex: 0 0 120px;
}

.ttl-unit {
  flex: 0 0 auto;
  width: auto;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.summary-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13.5px;
}

.summary-item dt {
  flex: none;
  color: var(--text-muted);
}

.summary-item dd {
  margin: 0;
  min-width: 0;
  font-weight: 500;
  text-align: right;
  overflow-wrap: anywhere;
}

.preview-body {
  display: flex;
  justify-content: flex-end;
  background: var(--bg-subtle);
}

.sms-bubble {
  max-width: 100%;
  padding: 9px 13px;
  border-radius: 18px 18px 4px 18px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sms-bubble.is-empty {
  background: var(--bg-muted);
  color: var(--text-subtle);
  font-style: italic;
}

.send-result .card-header {
  background: var(--success-soft);
}

.success-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--success-solid);
  color: #fff;
}

.batch-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.result-list {
  margin: 10px 0 12px;
  padding: 0;
  list-style: none;
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.result-item .muted {
  flex: 1;
  text-align: right;
}

/* ============================================================================================
   Messages
   ============================================================================================ */

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

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.toolbar-filters .select {
  width: auto;
  min-width: 140px;
  max-width: 220px;
  height: 34px;
  font-size: 13.5px;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-input {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input .icon {
  position: absolute;
  left: 10px;
  color: var(--text-subtle);
  pointer-events: none;
}

.search-input .input {
  width: 200px;
  height: 34px;
  padding-left: 30px;
  font-size: 13.5px;
}

.filter-chip-slot:empty {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 6px 0 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 13px;
}

.filter-chip-remove {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-muted);
}

.filter-chip-remove:hover {
  color: var(--text);
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 6px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.messages-table .message-row {
  cursor: pointer;
}

.messages-table .message-row:hover td {
  background: var(--bg-subtle);
}

.messages-table td {
  white-space: nowrap;
}

.messages-table .col-direction {
  width: 44px;
  padding-right: 0;
}

.messages-table .col-body {
  width: 100%;
  max-width: 0;
}

.body-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
}

.messages-table .col-device {
  max-width: 180px;
  color: var(--text-muted);
}

.messages-table .col-created,
.messages-table .col-updated {
  color: var(--text-muted);
  font-size: 13px;
}

/* Message detail drawer */
.detail-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.message-body {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.modal-body > .section-label {
  margin: 6px 0 -6px;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  position: relative;
  padding: 0 0 14px 24px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  top: 16px;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: var(--border-strong);
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-dot {
  position: absolute;
  top: 5px;
  left: 0;
  width: 11px;
  height: 11px;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-elevated);
}

.timeline-sentAt .timeline-dot {
  border-color: var(--accent);
}

.timeline-deliveredAt .timeline-dot {
  border-color: var(--success-solid);
  background: var(--success-solid);
}

.timeline-failedAt .timeline-dot {
  border-color: var(--danger-solid);
  background: var(--danger-solid);
}

.timeline-receivedAt .timeline-dot {
  border-color: var(--teal);
}

.timeline-label {
  font-size: 13.5px;
  font-weight: 500;
}

.timeline-time {
  color: var(--text-muted);
  font-size: 12.5px;
}

/* ============================================================================================
   API keys
   ============================================================================================ */

.key-reveal {
  display: flex;
  gap: 8px;
}

.key-reveal .input {
  font-size: 13px;
}

.key-reveal .btn {
  height: 36px;
}

.keys-table .key-prefix {
  font-size: 12.5px;
}

/* ============================================================================================
   Webhooks
   ============================================================================================ */

.webhook-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.webhook-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.webhook-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.webhook-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.webhook-card.is-disabled .webhook-icon {
  background: var(--bg-muted);
  color: var(--text-subtle);
}

.webhook-title {
  flex: 1;
  min-width: 0;
}

.webhook-url {
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.webhook-meta {
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.secret-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.secret-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.secret-row .secret-value {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  overflow-wrap: normal;
}

.secret-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.webhook-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.deliveries-toggle .chevron {
  transition: transform 0.15s;
}

.deliveries-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.deliveries-panel {
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

.deliveries-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.deliveries-head .section-label {
  margin: 0;
}

.deliveries-body .table-scroll {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.deliveries-body .table th {
  background: var(--bg-elevated);
}

.deliveries-body .state-loading {
  padding: 20px;
}

.deliveries-empty {
  padding: 12px 0 4px;
}

/* ============================================================================================
   API docs
   ============================================================================================ */

.docs-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  gap: 28px;
  align-items: start;
}

.docs-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.docs-toc {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.docs-toc .nav-heading {
  padding-left: 10px;
}

.toc-link {
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: left;
}

.toc-link:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.docs-section {
  scroll-margin-top: 24px;
}

.docs-section p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.docs-section .table-scroll {
  border: 1px solid var(--border);
  border-radius: 10px;
}

.docs-section .table-scroll + p {
  margin-top: 16px;
}

.docs-title {
  margin-bottom: 10px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.docs-subtitle {
  margin: 22px 0 10px;
  font-size: 14.5px;
  font-weight: 600;
}

.docs-note {
  margin-top: 16px;
}

.docs-base {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.docs-base .section-label {
  margin: 0;
}

.main > .callout,
.docs-device:not(:empty) {
  margin-bottom: 16px;
}

.docs-device-label {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13.5px;
}

.docs-device-label .select {
  width: auto;
  min-width: 200px;
}

/* ============================================================================================
   Responsive
   ============================================================================================ */

@media (max-width: 1100px) {
  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .docs-toc {
    display: none;
  }

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

  .send-aside {
    position: static;
  }

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

/* Sidebar collapses into a top bar with a dropdown menu. */
@media (max-width: 900px) {
  .sidebar {
    position: sticky;
    inset: 0 0 auto;
    width: 100%;
    height: var(--topbar-height);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
  }

  .sidebar-top {
    padding: 0 8px 0 16px;
  }

  .menu-button {
    display: inline-flex;
  }

  .sidebar-panel {
    display: none;
    position: absolute;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    max-height: calc(100vh - var(--topbar-height));
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
  }

  .sidebar.is-open .sidebar-panel {
    display: flex;
  }

  .nav {
    padding: 8px 10px 12px;
  }

  .nav-link {
    height: 40px;
  }

  .main {
    margin-left: 0;
    padding: 24px 20px 64px;
  }
}

@media (max-width: 760px) {
  .pair-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

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

  .checkbox-grid,
  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Messages table becomes a list of cards. */
  .messages-table {
    display: block;
    min-width: 0 !important;
  }

  .messages-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .messages-table tbody {
    display: block;
  }

  .messages-table tr {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    grid-template-areas:
      "direction phone status"
      "body body body"
      "device device created";
    gap: 6px 10px;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }

  .messages-table tr:last-child {
    border-bottom: 0;
  }

  .messages-table td {
    display: block;
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
    border: 0 !important;
  }

  .messages-table .col-direction {
    grid-area: direction;
  }

  .messages-table .col-phone {
    grid-area: phone;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .messages-table .col-status {
    grid-area: status;
  }

  .messages-table .col-body {
    grid-area: body;
  }

  .messages-table .col-device {
    grid-area: device;
    min-width: 0;
    font-size: 12.5px;
  }

  .messages-table .col-created {
    grid-area: created;
    text-align: right;
    font-size: 12.5px;
  }

  .messages-table .col-updated {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 20px 16px 56px;
  }

  .page-header {
    align-items: stretch;
    margin-bottom: 18px;
  }

  .page-title {
    font-size: 20px;
  }

  .page-actions {
    width: 100%;
  }

  .stat-value {
    font-size: 22px;
  }

  .stat-card {
    min-height: 96px;
  }

  .toolbar-filters,
  .toolbar-filters > * {
    width: 100%;
  }

  .toolbar-filters .select {
    flex: 1 1 140px;
    max-width: none;
  }

  .toolbar-filters .search-input .input {
    width: 100%;
  }

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

  .toolbar-filters > .search-input,
  .toolbar-filters > .filter-chip-slot {
    grid-column: 1 / -1;
  }

  .toolbar-end {
    width: 100%;
    justify-content: space-between;
  }

  .list-row {
    padding: 11px 14px;
  }

  .list-row-meta .connection-badge {
    display: none;
  }

  .modal {
    padding: 8px;
  }

  .modal-header {
    padding: 16px 16px 0;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }

  .modal-drawer {
    padding: 0;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
  }

  .key-reveal {
    flex-direction: column;
  }

  .definition {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .device-facts .definition {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-card {
    padding: 22px 18px;
  }

  .card-body {
    padding: 16px;
  }

  .card-body > .list {
    margin: -16px;
  }

  .card-header {
    padding: 12px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
