/* Brand palette from the logo: navy #12324F + orange #F47A20 (design: "صفحه‌ی اتصال وب").
   Orange is the action colour in both themes; navy carries text, the dark header and the dark surfaces. */
:root {
  --bg: #f3f5f8; --card: #fff; --field: #f7f9fb; --line: #e1e6ed; --text: #12324f; --muted: #5b6b7d;
  --brand: #f47a20; --brand-hover: #e46a10; --brand-text: #fff; --eyebrow: #f47a20; --link: #c2510c;
  --warn-bg: #fff5ec; --warn-line: #f8d3b2; --warn-text: #8a4710;
  --tab: #eef1f5; --err-bg: #fdecec; --err-text: #b42318; --danger: #c62828; --stage: #0b1420;
  --header-bg: #fff;
  --shadow: 0 1px 2px rgba(18, 50, 79, .05), 0 12px 32px rgba(18, 50, 79, .07);
  --btn-shadow: 0 8px 20px rgba(244, 122, 32, .28); --ring: rgba(244, 122, 32, .18);
  --font: Vazirmatn, Tahoma, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1826; --card: #11253a; --field: #0c1b2b; --line: #1e3750; --text: #e8eef4; --muted: #93a5b8;
    --brand-hover: #ff8a33; --eyebrow: #f8944a; --link: #ff8a47;
    --warn-bg: #2a1c10; --warn-line: #5b3a1a; --warn-text: #f7cda6;
    --tab: #0c1b2b; --err-bg: rgba(240, 80, 70, .14); --err-text: #ff8a80; --danger: #ff6b6b; --stage: #000;
    --header-bg: #12324f;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 16px 40px rgba(0, 0, 0, .35);
    --btn-shadow: 0 8px 24px rgba(244, 122, 32, .22); --ring: rgba(244, 122, 32, .25);
  }
}
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
[hidden] { display: none !important; }
button, input, select { font-family: inherit; }
button { font: inherit; cursor: pointer; }

/* ---- Connect page ---- */
.page { display: flex; flex-direction: column; min-height: 100%; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 8px 40px; background: var(--header-bg); border-bottom: 1px solid var(--line); }
h1.brand { margin: 0; line-height: 0; }
h1.brand img { display: block; height: 40px; width: auto; max-width: 100%; }
.header-end { display: flex; align-items: center; gap: 20px; }
.help-link { color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none; }
.help-link:hover { color: var(--brand); }

/* Server link status pill: green = main server, orange = another (test) server, grey = connecting, red = down */
.server-status { display: flex; align-items: center; gap: 8px; width: fit-content; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 999px; }
.server-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.server-status[data-state="online"] { color: #1d7a46; background: #e8f6ee; border-color: transparent; }
.server-status[data-state="online"] .dot { background: #22a05b; box-shadow: 0 0 0 3px rgba(34, 160, 91, .2); }
.server-status[data-state="foreign"] .dot { background: var(--brand); }
.server-status[data-state="connecting"] .dot { background: var(--muted); animation: pulse 1s ease-in-out infinite; }
.bar .server-status { margin: 0; padding: 4px 12px; font-size: 12.5px; }
@media (prefers-color-scheme: dark) {
  .server-status[data-state="online"] { color: #6fd59c; background: rgba(34, 160, 91, .14); }
}
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .server-status[data-state="connecting"] .dot { animation: none; } }

.main { flex: 1; display: grid; grid-template-columns: minmax(0, 460px) minmax(0, 1fr); gap: 56px; align-items: start; width: 100%; max-width: 1280px; margin: 0 auto; padding: 48px 64px; }
.card { display: flex; flex-direction: column; gap: 22px; padding: 32px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.card-head h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }
.card-head p { margin: 0; color: var(--muted); font-size: 14px; }


.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
label { display: flex; flex-direction: column; gap: 8px; min-width: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
label input:not([type=checkbox]) { width: 100%; min-width: 0; height: 50px; padding: 0 14px; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 11px; font-size: 16px; font-weight: 500; outline: none; }
label input.num { font-size: 19px; font-weight: 700; letter-spacing: 3px; text-align: left; }
label input[type=password].num { letter-spacing: 0; }
label input::placeholder { color: #8a99aa; font-weight: 400; letter-spacing: 0; }
label input:not([type=checkbox]):focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; font-weight: 400; cursor: pointer; }
label.check b { color: var(--text); font-weight: 600; }
label.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }

.primary { width: 100%; height: 54px; color: var(--brand-text); background: var(--brand); border: 0; border-radius: 12px; box-shadow: var(--btn-shadow); font-size: 17px; font-weight: 800; }
.primary:hover:not(:disabled) { background: var(--brand-hover); }
.primary:disabled { opacity: .6; cursor: default; }
.status { margin: -8px 0 0; color: var(--muted); font-size: 14px; }
.status:empty { display: none; }
.status.error { display: flex; align-items: center; gap: 10px; margin-top: 0; padding: 12px 14px; color: var(--err-text); background: var(--err-bg); border-radius: 10px; font-weight: 600; }
.status.error::before { content: "!"; display: grid; place-items: center; width: 22px; height: 22px; flex: none; color: var(--err-bg); background: var(--err-text); border-radius: 50%; font-size: 13px; font-weight: 800; }

.info { display: flex; flex-direction: column; gap: 28px; padding-top: 8px; }
.hero { display: flex; flex-direction: column; gap: 12px; }
.eyebrow { color: var(--eyebrow); font-size: 13px; font-weight: 700; letter-spacing: .5px; }
.hero h2 { margin: 0; font-size: 38px; font-weight: 800; line-height: 1.35; text-wrap: pretty; }
.hero p { max-width: 560px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.9; text-wrap: pretty; }
.hero p b { color: var(--text); }

.notice { display: flex; gap: 16px; max-width: 620px; padding: 20px 22px; color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 16px; }
.notice-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; color: #fff; background: var(--brand); border-radius: 10px; font-size: 18px; font-weight: 800; }
.notice > div { display: flex; flex-direction: column; gap: 6px; }
.notice strong { font-size: 16px; font-weight: 800; }
.notice span { font-size: 14px; line-height: 1.9; text-wrap: pretty; }

.download { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; max-width: 620px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; line-height: 1.8; }
.download a { display: flex; align-items: center; height: 42px; padding: 0 18px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.download a:hover { color: var(--brand); border-color: var(--brand); }
.download-hint { flex-basis: 100%; margin: 0; padding: 10px 14px; color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; font-size: 13px; line-height: 1.9; }
#downloadMeta { margin-inline-start: 6px; color: var(--muted); font-size: 12px; font-weight: 400; }

.guide { max-width: 620px; padding-top: 4px; color: var(--text); font-size: 14px; line-height: 1.9; }
.guide summary { cursor: pointer; color: var(--link); font-size: 15px; font-weight: 700; }
.guide h3 { margin: 18px 0 4px; font-size: 15px; font-weight: 700; }
.guide ol, .guide ul { margin: 4px 0; padding-inline-start: 22px; }
.guide li { margin-bottom: 6px; }
.guide p { margin: 4px 0; }

.site-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 24px; min-height: 48px; padding: 8px 40px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }
.site-footer a { color: var(--link); font-weight: 700; text-decoration: none; }
.site-footer a:hover { color: var(--brand); text-decoration: underline; }

@media (max-width: 960px) {
  .main { grid-template-columns: minmax(0, 1fr); gap: 32px; max-width: 560px; padding: 28px 20px; }
  .site-header { padding: 8px 20px; }
  .site-footer { padding: 8px 20px; }
  .hero h2 { font-size: 28px; }
}
@media (max-width: 520px) {
  .card { padding: 22px 18px; }
  .site-header { flex-wrap: wrap; justify-content: center; padding: 12px 16px; }
  .download { flex-direction: column; align-items: flex-start; }
}

/* ---- Session view ---- */
.session { display: flex; flex-direction: column; height: 100vh; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.bar .peer { margin-inline-end: auto; }
.bar button, .bar select { padding: 6px 12px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.bar button:disabled { opacity: .5; cursor: default; }
.bar .danger { color: #fff; background: var(--danger); border-color: var(--danger); }
/* File / folder transfer list (filetransfer.js) */
.files { max-height: 168px; overflow-y: auto; padding: 4px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.file-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.file-row:last-child { border-bottom: 0; }
.file-main { flex: 1; min-width: 0; }
.file-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-status { color: var(--muted); font-size: 12px; line-height: 1.7; }
.file-row[data-state="failed"] .file-status, .file-row[data-state="rejected"] .file-status { color: var(--danger); }
.file-row[data-state="done"] .file-status { color: #2e7d32; }
.file-row progress { width: 100%; height: 5px; margin-top: 3px; accent-color: var(--brand); }
.file-actions { display: flex; gap: 6px; flex: none; }
.file-actions button { padding: 5px 12px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.file-actions .primary { color: var(--brand-text); background: var(--brand); border-color: var(--brand); width: auto; height: auto; margin: 0; box-shadow: none; font-size: 13px; font-weight: 700; }
.file-actions .danger { color: var(--danger); }
.stage.drop-active { outline: 3px dashed var(--brand); outline-offset: -8px; }
.bar button:disabled { cursor: not-allowed; }
.body { display: flex; flex: 1; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; background: var(--stage); outline: none; cursor: default; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #cbd2e3; background: rgba(0, 0, 0, .55); pointer-events: none; }
.chat { display: flex; flex-direction: column; width: 260px; background: var(--card); border-inline-start: 1px solid var(--line); }
.chat-log { flex: 1; padding: 10px; overflow-y: auto; font-size: 13px; }
.chat-line { margin-bottom: 6px; }
.chat form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat input { flex: 1; min-width: 0; padding: 7px 9px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.chat button { padding: 7px 12px; color: var(--brand-text); background: var(--brand); border: 0; border-radius: 8px; }
@media (max-width: 760px) { .chat { display: none; } }

/* Connection quality badge (viewer.js: pollQuality) */
.netq { display: inline-flex; align-items: center; gap: 7px; padding: 4px 12px; font-size: 12.5px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.netq-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa7b5; }
.netq[data-level="good"] .netq-dot { background: #2e9e5b; }
.netq[data-level="medium"] .netq-dot { background: #e0a100; }
.netq[data-level="bad"] .netq-dot { background: #d93025; }
.netq bdi { direction: ltr; unicode-bidi: isolate; }

/* Connection history (viewer.js: history*) */
.history { display: flex; flex-direction: column; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.history-clear { padding: 4px 8px; color: var(--link); background: none; border: 0; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.history-clear:hover { text-decoration: underline; }
.history-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; list-style: none; }
.history-item { display: flex; align-items: center; gap: 6px; background: var(--field); border: 1px solid var(--line); border-radius: 11px; }
.history-pick { flex: 1; min-width: 0; padding: 10px 14px; color: var(--text); background: none; border: 0; border-radius: 11px; font: inherit; text-align: start; cursor: pointer; }
.history-pick:hover { background: var(--ring); }
.history-name { display: block; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.history-id { direction: ltr; unicode-bidi: isolate; letter-spacing: 1px; }
.history-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.history-del { flex: none; width: 34px; height: 34px; margin-inline-end: 6px; color: var(--muted); background: none; border: 0; border-radius: 8px; font-size: 18px; line-height: 1; cursor: pointer; }
.history-del:hover { color: var(--danger); }
.history-note { margin: 0; color: var(--muted); font-size: 12px; }
