:root {
  color-scheme: light;
  --bg: #f3efe6;
  --ink: #1b1914;
  --muted: #6d655b;
  --muted-soft: #b5aca0;
  --line: #e3d9c8;
  --card: #fffdf8;
  --accent: #0e6b52;
  --accent-ink: #f4fff9;
  --warn: #8a5a12;
  --bad: #8d2b2b;
  --in: #0e6b52;
  --out: #1d4e89;
  --shadow: 0 1px 0 rgba(27, 25, 20, 0.04);
  font-family: IRANSans, Tahoma, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding: 28px 22px 48px;
  font-family: IRANSans, Tahoma, sans-serif;
  font-weight: 400;
}

button, input, textarea, code {
  font-family: inherit;
}

.top, .lead, .grid, .composer, .streams {
  max-width: 1080px;
  margin-inline: auto;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

h1, h2 { font-weight: 650; margin: 0; }

h1 { font-size: 32px; }

h2 { font-size: 16px; }

.lead {
  color: var(--muted);
  line-height: 1.7;
  margin: 14px auto 18px;
}

.status {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

.status[data-state="ok"] { color: var(--accent); }
.status[data-state="warn"] { color: var(--warn); }
.status[data-state="bad"],
.status[data-state="off"] { color: var(--bad); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 4fr);
  gap: 14px;
  align-items: stretch;
}

.streams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.composer { margin-top: 14px; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.count {
  min-width: 28px;
  text-align: center;
  border-radius: 999px;
  background: #efe8da;
  padding: 2px 8px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: 700;
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: lining-nums tabular-nums;
}

.token-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

#my-token {
  flex: 1;
  font-size: 28px;
  letter-spacing: 0.04em;
  background: #f7f3ea;
  border-radius: 12px;
  padding: 10px 12px;
  direction: ltr;
  text-align: left;
}

input, textarea {
  color: inherit;
}

button {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

#connected-at { margin: 10px 0 0; }

.send-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.send-form .field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  min-width: 0;
  white-space: nowrap;
}

.send-form .field-label {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 13px;
}

.send-form .field-token {
  flex: 0 0 auto;
}

.send-form .field-token input {
  width: 148px;
}

.send-form .field-text {
  flex: 1 1 auto;
  min-width: 120px;
}

.send-form .field-text input {
  width: 100%;
}

.send-form #send-button {
  flex: 0 0 auto;
  height: 42px;
  padding-inline: 20px;
}

input, textarea {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  direction: rtl;
  height: 42px;
}

#target-token {
  direction: ltr;
  text-align: left;
  letter-spacing: 0.08em;
  font-family: Consolas, "Cascadia Mono", monospace;
}

.composer .error {
  margin: 10px 0 0;
  color: var(--bad);
  font-size: 14px;
}

.device-grid, .log {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.device-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
}

.device-grid > li {
  list-style: none;
}

.device-card {
  padding: 0;
  border: 0;
  background: transparent;
  min-width: 118px;
  max-width: 140px;
  display: block;
  text-align: center;
}

.device-card.pickable {
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.device-card.pickable:hover .device-inner {
  border-color: #c9baa4;
  box-shadow: 0 6px 18px rgba(27, 25, 20, 0.08);
  transform: translateY(-1px);
}

.device-inner {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 12px 12px;
  background: linear-gradient(180deg, #fff 0%, #faf6ef 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: inherit;
}

.device-card.me .device-inner {
  border-color: #9fd4c4;
  background: linear-gradient(180deg, #f8fffb 0%, #eef8f3 100%);
}

.phone-icon {
  width: 34px;
  height: 52px;
  color: #8f8679;
  flex-shrink: 0;
}

.device-card.me .phone-icon {
  color: var(--accent);
}

.token-chip {
  display: block;
  width: 100%;
  border-radius: 14px;
  padding: 7px 8px;
  background: #ebe4d8;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  direction: ltr;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.3;
  word-break: break-all;
}

.device-card.me .token-chip {
  background: #d6ece4;
  color: #0a5440;
}

.device-status {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.device-time {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted-soft);
  line-height: 1.35;
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.02em;
}

.status-label {
  font-size: 11px;
  color: var(--muted-soft);
  font-weight: 450;
}

.status-value {
  font-size: 13px;
  color: var(--ink);
  font-weight: 700;
}

.device-card.me .status-value {
  color: var(--accent);
}

.log {
  display: grid;
  gap: 8px;
}

.log li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  display: grid;
  gap: 4px;
}

.log time {
  color: var(--muted-soft);
  font-size: 12px;
}

.log strong.route {
  display: inline-flex;
  gap: 0.35em;
  flex-wrap: wrap;
  align-items: baseline;
}

.token {
  font-family: Consolas, "Cascadia Mono", monospace;
  letter-spacing: 0.06em;
  direction: ltr;
}

.log .body {
  white-space: pre-wrap;
  word-break: break-word;
}

.incoming li { border-inline-start: 3px solid var(--in); }
.outgoing li { border-inline-start: 3px solid var(--out); }

.empty {
  color: var(--muted);
  border: 1px dashed var(--line) !important;
  border-radius: 16px;
  padding: 16px;
  background: #fff !important;
  width: 100%;
  text-align: center;
}

.users-panel .empty {
  max-width: none;
}

@media (max-width: 860px) {
  .grid, .streams { grid-template-columns: 1fr; }
  #my-token { font-size: 22px; }
  .device-card { max-width: none; flex: 1 1 calc(50% - 6px); }
  .send-form {
    flex-wrap: wrap;
  }
  .send-form .field-token,
  .send-form .field-text {
    flex: 1 1 100%;
  }
  .send-form #send-button {
    width: 100%;
  }
}