/* AI Yordamchi - ko'p terminalli veb-agent */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --border: #d9dee6;
  --text: #1f2328;
  --text-dim: #5f6b7a;
  --accent: #0969da;
  --accent-2: #8250df;
  --accent-soft: rgba(9, 105, 218, 0.12);
  --ok: #1a7f37;
  --warn: #bf8700;
  --err: #cf222e;
  --term-bg: #fbfcfe;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(20, 30, 50, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #06090d; --surface: #0f151c; --surface-2: #151c25; --border: #242e3a;
    --text: #e6edf3; --text-dim: #8b98a8; --accent: #58a6ff; --accent-2: #bc8cff;
    --accent-soft: rgba(88, 166, 255, 0.14); --ok: #3fb950; --warn: #d29922; --err: #f85149;
    --term-bg: #0b1016; --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #06090d; --surface: #0f151c; --surface-2: #151c25; --border: #242e3a;
  --text: #e6edf3; --text-dim: #8b98a8; --accent: #58a6ff; --accent-2: #bc8cff;
  --accent-soft: rgba(88, 166, 255, 0.14); --ok: #3fb950; --warn: #d29922; --err: #f85149;
  --term-bg: #0b1016; --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
code { font-family: Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--text-dim); }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.flip { transform: rotate(180deg); }
.show-dark { display: none; }
:root[data-theme="dark"] .show-dark { display: inline; }
:root[data-theme="dark"] .show-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .show-dark { display: inline; }
  :root:not([data-theme="light"]) .show-light { display: none; }
}

/* ---------- tugmalar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn.danger { background: var(--err); color: #fff; border-color: transparent; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.accent { background: var(--accent-soft); color: var(--accent); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }

.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.brand-mark .i { width: 17px; height: 17px; stroke-width: 2.5; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; }
.brand-mark.big .i { width: 30px; height: 30px; }

/* ---------- login ---------- */
.login-body { display: grid; min-height: 100%; padding: 16px; }
.login-wrap { display: grid; place-items: center; }
.login-theme { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 14px; justify-items: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0 0 6px; text-align: center; }
.login-card label, .modal label { display: grid; gap: 6px; width: 100%; font-size: 13px; font-weight: 600; color: var(--text-dim); }
input[type=text], input[type=password] {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.error, .form-error {
  display: flex; gap: 8px; align-items: center; width: 100%; padding: 10px 12px; border-radius: 10px;
  background: rgba(207, 34, 46, 0.1); color: var(--err); font-size: 13px;
}

/* ---------- asosiy ilova ---------- */
.app-body { overflow: hidden; }
.app {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; flex: none; margin-right: 6px; }
.top-actions { display: flex; gap: 2px; margin-left: auto; flex: none; }
.top-actions form { margin: 0; }

.tabs {
  display: flex; gap: 6px; overflow-x: auto; min-width: 0; flex: 0 1 auto;
  scrollbar-width: none; padding: 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 7px; height: 34px; padding: 0 6px 0 11px; flex: none;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); cursor: pointer; user-select: none; max-width: 200px; position: relative;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 13px; }
.tab-x {
  display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 6px;
  background: transparent; color: inherit; cursor: pointer; padding: 0; opacity: .6;
}
.tab-x:hover { background: rgba(207, 34, 46, 0.15); color: var(--err); opacity: 1; }
.tab-x .i { width: 14px; height: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
[data-conn="connecting"] > .dot, [data-conn="connecting"] .pane-head .dot { background: var(--warn); }
[data-conn="offline"] > .dot, [data-conn="offline"] .pane-head .dot { background: var(--err); }
.exited > .dot, .exited .pane-head .dot { background: var(--text-dim); }
.tab.exited .tab-name { text-decoration: line-through; opacity: .7; }
.tab.unread::after {
  content: ""; position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-2); border: 2px solid var(--surface);
}

/* ---------- terminal maydoni ---------- */
.stage { position: relative; flex: 1 1 auto; min-height: 0; padding: 10px 10px 0; }
.panes { height: 100%; display: flex; }
.pane {
  display: none; flex-direction: column; flex: 1; min-width: 0; min-height: 0;
  background: var(--term-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.pane.active { display: flex; }
.pane-head {
  display: none; align-items: center; gap: 8px; padding: 6px 12px; font-size: 12.5px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.pane-name { font-weight: 700; white-space: nowrap; }
.pane-cwd { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Menlo, Consolas, monospace; font-size: 11.5px; }
.pane-body { flex: 1; min-height: 0; padding: 6px 4px 4px 8px; }
.pane-body .xterm { height: 100%; }
.pane-body .xterm-viewport { background: transparent !important; }
.pane-body { padding-right: 30px; }
/* xterm'ning ingichka scrollbar'i o'rniga o'zimizniki (.sbar) */
.pane-body .xterm-viewport { scrollbar-width: none; }
.pane-body .xterm-viewport::-webkit-scrollbar { display: none; }

/* ---------- o'z scrollbar ---------- */
.pane { position: relative; }
.sbar {
  position: absolute; right: 3px; bottom: 6px; top: 6px; width: 24px; z-index: 4;
  display: flex; flex-direction: column; gap: 4px; user-select: none; touch-action: none;
}
.panes.grid .sbar { top: 40px; }
.sbar.off { opacity: .35; pointer-events: none; }
.sbar.off .sbar-thumb { display: none; }
.sbar-btn {
  flex: none; height: 24px; display: grid; place-items: center; padding: 0;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2);
  color: var(--text-dim); cursor: pointer;
}
.sbar-btn:hover { color: var(--accent); border-color: var(--accent); }
.sbar-btn .i { width: 14px; height: 14px; }
.sbar-track {
  position: relative; flex: 1; min-height: 0; border-radius: 8px; cursor: pointer;
  background: rgba(127, 127, 127, 0.12);
}
.sbar-thumb {
  position: absolute; left: 3px; right: 3px; top: 0; min-height: 36px; border-radius: 6px;
  background: rgba(127, 127, 127, 0.45); cursor: grab; touch-action: none;
}
.sbar-thumb:hover, .sbar.dragging .sbar-thumb { background: var(--accent); }
.sbar.dragging .sbar-thumb { cursor: grabbing; }
/* fullscreen (claude tui) rejimi: yo'lak - surish joyi, belgi o'rtada */
.sbar.alt .sbar-thumb { display: none; }
.sbar.alt .sbar-track {
  background: repeating-linear-gradient(to bottom, rgba(127,127,127,.18) 0 2px, transparent 2px 10px), rgba(127,127,127,.1);
}
.sbar.alt.dragging .sbar-track { background-color: var(--accent-soft); }
.sbar.alt [data-sb] { color: var(--accent); }
.sbar:not(.at-bottom):not(.off) [data-sb="bottom"] { color: var(--accent); border-color: var(--accent); }
.pane.detached .sbar { display: none; }

.panes.grid { display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); }
.panes.grid .pane { display: flex; }
.panes.grid .pane-head { display: flex; }
.panes.grid .pane.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.empty {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 12px; text-align: center; padding: 24px;
}
.empty h2 { margin: 6px 0 0; }
.empty p { max-width: 420px; margin: 0 0 8px; }

.float-btns { position: absolute; right: 50px; bottom: 12px; display: grid; gap: 8px; z-index: 5; }
.float-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  box-shadow: var(--shadow); cursor: pointer; opacity: .85;
}
.float-btn:hover { opacity: 1; color: var(--text); }

/* To'liq ekran (fokus) rejimi */
.app.focus-mode .topbar, .app.focus-mode .keys { display: none; }
.app.focus-mode .stage { padding: 6px 6px 0; }

/* ---------- pastki panel: tugmalar + yozish ---------- */
.dock { flex: none; padding: 8px 10px 10px; display: grid; gap: 8px; }
.keys { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.keys::-webkit-scrollbar { display: none; }
.key {
  flex: none; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 600 12.5px Menlo, Consolas, monospace; cursor: pointer;
}
.key:active { background: var(--accent-soft); border-color: var(--accent); }
.key.danger { color: var(--err); border-color: rgba(207, 34, 46, 0.4); }

.compose { display: flex; align-items: flex-end; gap: 8px; }
.mic-lang {
  height: 44px; padding: 0 6px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 600 12.5px inherit; flex: none;
}
.compose-field {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 8px; padding: 5px 6px 5px 6px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
}
.compose-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.target-chip {
  flex: none; max-width: 30%; height: 32px; line-height: 32px; padding: 0 10px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.target-chip::before { content: "→ "; }
.compose-field textarea {
  flex: 1; min-width: 0; border: 0; resize: none; background: transparent; color: var(--text);
  font: 15px/1.4 inherit; padding: 6px 2px; max-height: 140px; outline: none !important;
}
.compose-field textarea::placeholder { color: var(--text-dim); opacity: .8; }
.round-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.round-btn .i { width: 20px; height: 20px; }
.round-btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.round-btn.recording { background: var(--err); color: #fff; border-color: transparent; animation: pulse 1.1s ease-in-out infinite; }
.round-btn.busy { cursor: progress; animation: spin-glow 1s linear infinite; }
.round-btn:disabled:not(.busy) { opacity: .35; cursor: not-allowed; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.55); } 50% { box-shadow: 0 0 0 9px rgba(248, 81, 73, 0); } }
@keyframes spin-glow { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 7px var(--accent-soft); } }
.hint { font-size: 12.5px; color: var(--text-dim); padding: 0 4px; }
.hint.err { color: var(--err); }

/* ---------- modal oynalar ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(5, 10, 18, 0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.modal h3 { margin: 0; }
.modal p { margin: 0; }
.modal-ico { color: var(--warn); }
.modal-ico .i { width: 30px; height: 30px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.proj-wrap { display: grid; gap: 8px; }
.proj-head { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--text-dim); }
.proj-head input { flex: 1; min-width: 0; height: 34px; font-size: 14px; }
.proj-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 200px; overflow-y: auto; padding: 2px; }
.proj-chip {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.proj-chip:hover { border-color: var(--accent); }
.proj-chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.proj-chip.other { border-style: dashed; color: var(--text-dim); }
.proj-chip.other.active { color: var(--accent); }
.quick-cmds { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; }
.modal label.chk { display: inline-flex; align-items: center; gap: 6px; width: auto; font-weight: 500; color: var(--text); cursor: pointer; }

/* ---------- mobil ---------- */
@media (max-width: 760px) {
  .brand-name { display: none; }
  .brand { margin-right: 0; }
  .topbar { padding: 6px 8px; gap: 6px; }
  .tab { max-width: 150px; height: 32px; }
  .stage { padding: 6px 6px 0; }
  .panes.grid { grid-template-columns: minmax(0, 1fr); }
  .dock { padding: 6px 6px 8px; gap: 6px; }
  .mic-lang { width: 50px; font-size: 11px; }
  .round-btn { width: 42px; height: 42px; }
  .target-chip { display: none; }
  .float-btns { right: 42px; }
  .compose-field textarea { font-size: 16px; } /* iOS avto-zoom qilmasin */
}

/* ---------- alohida oynalar ---------- */
.pane-btn {
  display: grid; place-items: center; width: 24px; height: 24px; flex: none; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-dim); cursor: pointer;
}
.pane-btn:first-of-type { margin-left: auto; }
.pane-btn:hover { background: var(--accent-soft); color: var(--accent); }
.pane-btn .i { width: 14px; height: 14px; }
.pane-detached {
  display: none; flex: 1; place-content: center; justify-items: center; gap: 12px;
  padding: 24px; text-align: center; color: var(--text-dim);
}
.pane-detached > .i { width: 34px; height: 34px; color: var(--accent); }
.pane-detached p { margin: 0; max-width: 360px; }
.pane-detached .modal-actions { justify-content: center; }
.pane.detached .pane-body { display: none; }
.pane.detached .pane-detached { display: grid; }
.panes.grid .pane.detached { display: none; }
.tab.detached { border-style: dashed; }
.tab.detached .tab-name::after { content: " ↗"; color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; border-color: transparent; }

/* Yakka oyna (/?t=<id>): faqat bitta terminal */
body.solo #layout-btn { display: none; }
body.solo .tab-name::after { content: none; }
