:root {
  --bg: #0b0d12;
  --surface: #12151d;
  --surface-2: #1a1e29;
  --border: #2a3040;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #d97757;
  --accent-strong: #e8896a;
  --on-accent: #1a0f0a;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f05252;
  --ring: #f4b8a3;
  --radius: 12px;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans: Vazirmatn, "IRANSans", -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --vh: 100dvh;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; }
.sprite { position: absolute; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.app { display: flex; flex-direction: column; height: var(--vh); padding-bottom: env(safe-area-inset-bottom); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 26px; height: 26px; color: var(--accent); }
.titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.titles strong { font-size: 15px; letter-spacing: .2px; }
.where { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.bar-actions { display: flex; align-items: center; gap: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.wait i { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.pill.bad i { background: var(--danger); }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 1px; min-width: 40px; height: 40px;
  padding: 0 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
.icon-btn small { font-size: 13px; font-weight: 700; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: #3a4256; background: #212634; }
.icon-btn:active { transform: scale(.96); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.big { min-width: 44px; height: 44px; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.stage { position: relative; flex: 1; min-height: 0; background: var(--bg); }
.term { position: absolute; inset: 0; padding: 6px 4px 6px 8px; }
.term .xterm { height: 100%; }
.term .xterm-viewport { scrollbar-width: thin; scrollbar-color: #343b4d transparent; }

.idle, .gate { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.idle { position: absolute; inset: 0; padding: 20px 16px 28px; overflow-y: auto; justify-content: flex-start;
  background: radial-gradient(ellipse at top, #1b1512 0%, var(--bg) 60%); }
.idle-inner { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 14px; text-align: start; }
.idle-head { display: flex; align-items: center; gap: 14px; }
.idle-head .idle-logo { width: 40px; height: 40px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.section-head h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; }
.link-btn { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.link-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tile { position: relative; aspect-ratio: 1 / 1; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 14px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); text-align: start;
  transition: border-color .15s var(--ease), transform .12s var(--ease), background .15s var(--ease); min-width: 0; }
.tile:hover { border-color: var(--accent); background: #161a24; }
.tile:active { transform: scale(.97); }
.tile:disabled { opacity: .6; cursor: progress; }
.mono { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 17px; color: #0b0d12; }
.tile-name { font-weight: 700; font-size: 15px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-path { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile.add { align-items: center; justify-content: center; border-style: dashed; color: var(--muted); background: transparent; text-align: center; }
.tile.add svg { width: 28px; height: 28px; }
.tile-tools { position: absolute; top: 8px; inset-inline-end: 8px; display: flex; gap: 6px; }
.tile-tools span { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); }
.tile-tools span.del { color: var(--danger); }
.tile-tools svg { width: 16px; height: 16px; }
.tiles.editing .tile:not(.add) { border-style: dashed; }
.empty { grid-column: 1 / -1; color: var(--muted); font-size: 14px; padding: 8px 0; }

.other { border: 1px solid var(--border); border-radius: 14px; padding: 4px 14px 14px; background: var(--surface); }
.other summary { cursor: pointer; padding: 10px 0 6px; color: var(--muted); font-size: 14px; }
.other[open] summary { color: var(--text); }
.other .label, .other select, .other .primary { max-width: none; }
.idle h1, .gate h1 { margin: 4px 0 0; font-size: 20px; }
.idle p, .gate p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.idle-logo { width: 48px; height: 48px; color: var(--accent); filter: drop-shadow(0 0 14px rgba(217,119,87,.35)); }
.label { align-self: stretch; text-align: start; font-size: 13px; color: var(--muted); margin-top: 8px; max-width: 360px; width: 100%; margin-inline: auto; }
select, input[type=password] { width: 100%; max-width: 360px; height: 46px; padding: 0 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 15px; }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; max-width: 360px; height: 48px;
  margin-top: 6px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--on-accent); font-weight: 700;
  transition: background .15s var(--ease), transform .1s var(--ease); }
.primary:hover { background: var(--accent-strong); }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .6; cursor: progress; }

.drop { position: absolute; inset: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--accent); border-radius: 16px; background: rgba(11,13,18,.88); color: var(--text); z-index: 5; pointer-events: none; }
.drop svg { width: 44px; height: 44px; color: var(--accent); }
.drop span { color: var(--muted); font-size: 13px; }

.chips { display: flex; gap: 8px; padding: 8px 10px; overflow-x: auto; background: var(--surface); border-top: 1px solid var(--border);
  scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 36px; min-width: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-family: var(--mono); font-size: 13px; color: var(--text); scroll-snap-align: start;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
.chip.cmd { color: var(--accent-strong); }
.chip.warn { color: var(--danger); }
.chip:hover { border-color: #3a4256; }
.chip:active { transform: scale(.95); background: #262b38; }
.sep { flex: none; width: 1px; background: var(--border); margin: 4px 2px; }

.composer { padding: 8px 10px 10px; background: var(--surface); }
.row { display: flex; align-items: flex-end; gap: 8px; }
textarea { flex: 1; min-height: 44px; max-height: 38vh; padding: 11px 14px; resize: none; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--border); line-height: 1.45; font-size: 16px; font-family: var(--sans); }
textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(217,119,87,.18); }
textarea::placeholder { color: #6f7889; }
.send { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent); transition: background .15s var(--ease), transform .1s var(--ease); }
.esc { flex: none; height: 44px; min-width: 52px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-family: var(--mono); font-size: 14px; font-weight: 700;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
.esc:hover { border-color: #3a4256; background: #212634; }
.esc:active { transform: scale(.94); background: #262b38; }
.send:hover { background: var(--accent-strong); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .5; cursor: not-allowed; }

.tray { display: flex; gap: 8px; padding-bottom: 8px; overflow-x: auto; }
.thumb { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.busy::after { content: ""; position: absolute; inset: 0; background: rgba(11,13,18,.55); }
.thumb.busy::before { content: ""; position: absolute; z-index: 1; inset: 22px; border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
.thumb.bad { border-color: var(--danger); }
.thumb.bad img { opacity: .35; }
.thumb button { position: absolute; top: 2px; right: 2px; z-index: 2; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.7); color: #fff; padding: 0; }
.thumb button svg { width: 14px; height: 14px; }

.gate { position: fixed; inset: 0; padding: 24px; background: radial-gradient(ellipse at top, #1b1512 0%, var(--bg) 60%); }
.card { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 380px; padding: 28px 20px;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--border); }
.err { min-height: 20px; color: var(--danger) !important; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  max-width: min(92vw, 460px); padding: 10px 16px; border-radius: 12px; background: #2a1517; border: 1px solid var(--danger);
  color: #ffd7d7; font-size: 14px; line-height: 1.5; box-shadow: 0 8px 30px rgba(0,0,0,.45); animation: rise .2s var(--ease); }
.toast.info { background: #13202a; border-color: #2f6f9f; color: #d6ecff; }

.sheet { position: fixed; inset: 0; z-index: 15; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.6); animation: fade .15s var(--ease); }
.sheet-card { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 900px; height: min(82vh, 760px);
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px 18px 0 0; animation: rise-up .2s var(--ease); }
.sheet-head { display: flex; flex-direction: column; gap: 2px; }
.sheet-head span { color: var(--muted); font-size: 13px; }
.sheet-card textarea { flex: 1; max-height: none; font-family: var(--mono); font-size: 13px; line-height: 1.4; white-space: pre;
  overflow: auto; user-select: text; -webkit-user-select: text; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-card.small { height: auto; max-width: 520px; }
.sheet-card.small .label, .sheet-card.small select, .sheet-card.small input { max-width: none; }
.sheet-card.small input[type=text] { width: 100%; height: 46px; padding: 0 12px; border-radius: var(--radius); background: var(--surface-2);
  border: 1px solid var(--border); font-size: 16px; }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-card.small { border-radius: 18px; } }
.sheet-actions .primary { margin: 0; max-width: none; flex: 1; }
.ghost { height: 48px; padding: 0 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
.ghost:hover { background: #212634; }
.toast.ok { background: #12241a; border-color: var(--ok); color: #d3f5dc; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (min-width: 900px) {
  .chips { justify-content: center; }
  .composer { padding-inline: 16px; }
  .where { max-width: 50vw; }
}

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