/* Pixel Office — cozy pixel-styled layout (ARCHITECTURE.md §6.5) */

:root {
  color-scheme: dark;
  --bg: #1e1e2a;
  --bg-2: #262636;
  --panel: #2a2a3c;
  --panel-2: #33334a;
  --line: #44445e;
  --text: #ece8dc;
  --muted: #a3a0b8;
  --accent: #ffd84a;
  --wood: #a0703c;
  --wood-dark: #5e3d22;
  --ok: #4caf50;
  --warn: #ffb74d;
  --bad: #ef5350;
  --px: 3px; /* pixel border unit */
  --font: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.015) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.015) 75%),
    linear-gradient(45deg, rgba(255,255,255,.015) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.015) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  color: var(--text);
  font: 13px/1.45 var(--font);
}

/* ---------- layout ---------- */
#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "stage panel";
  height: 100vh;
  height: 100dvh;
}
#topbar { grid-area: top; }
#stage { grid-area: stage; }
#panel { grid-area: panel; }

/* ---------- header ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: var(--px) solid #12121a;
  box-shadow: 0 var(--px) 0 var(--line);
}
.logo {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-shadow: 2px 2px 0 #000;
  margin-right: auto;
}
.logo-icon {
  width: 24px; height: 24px;
  background:
    linear-gradient(#d6fff4, #d6fff4) 6px 6px / 9px 3px no-repeat,
    linear-gradient(#3f9a8f, #3f9a8f) 3px 3px / 18px 12px no-repeat,
    linear-gradient(#6b7180, #6b7180) 9px 15px / 6px 3px no-repeat,
    linear-gradient(var(--wood), var(--wood)) 0 18px / 24px 4px no-repeat;
  image-rendering: pixelated;
}
.mode-badge {
  font-weight: bold;
  padding: 3px 8px;
  border: 2px solid currentColor;
  box-shadow: 2px 2px 0 #000;
  font-size: 11px;
  letter-spacing: 1px;
}
.mode-badge[data-mode="live"] { color: var(--ok); }
.mode-badge[data-mode="demo"] { color: var(--accent); }
.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.conn-status::before {
  content: "";
  width: 9px; height: 9px;
  background: var(--warn);
  box-shadow: 0 0 0 2px #000;
}
.conn-status[data-status="live"]::before { background: var(--ok); animation: pulse 2s steps(2) infinite; }
.conn-status[data-status="reconnecting"]::before { background: var(--bad); animation: pulse .8s steps(2) infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- stage / canvas ---------- */
#stage {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.frame {
  position: relative;
  line-height: 0;
  padding: 6px;
  background: var(--wood-dark);
  box-shadow:
    0 0 0 var(--px) #000,
    inset 0 0 0 var(--px) var(--wood),
    6px 6px 0 var(--px) rgba(0,0,0,.45);
}
#office {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100%;
  height: auto;
  background: #000;
}
#conn-banner {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%) translateY(-6px);
  padding: 6px 14px;
  background: #3a1f24;
  color: #ffd7d7;
  border: 2px solid var(--bad);
  box-shadow: 3px 3px 0 #000;
  font: bold 13px/1.3 var(--font);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
#conn-banner.show { opacity: 1; transform: translateX(-50%); }

/* ---------- side panel ---------- */
#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: var(--px) solid #12121a;
  box-shadow: inset var(--px) 0 0 var(--line);
}
.panel-head { padding: 12px 14px 8px; border-bottom: 2px solid var(--line); }
.panel-head h2 { margin: 0 0 6px; font-size: 14px; color: var(--accent); text-shadow: 2px 2px 0 #000; }
.summary { display: flex; flex-wrap: wrap; gap: 6px; min-height: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.chip i { width: 8px; height: 8px; background: var(--c); box-shadow: 0 0 0 1px #000; }

.agent-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 120px;
}
.agent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 2px solid #1a1a26;
  box-shadow: 2px 2px 0 #15151f;
  cursor: pointer;
  transition: transform .08s;
}
.agent:hover { border-color: var(--line); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 #15151f; }
.agent:focus-visible { outline: 2px dashed var(--accent); outline-offset: 1px; }
.agent.selected { border-color: var(--accent); background: #3d3a4a; }
.agent.sub { margin-left: 18px; }
.swatch {
  flex: none;
  width: 14px; height: 14px;
  margin-top: 2px;
  box-shadow: 0 0 0 2px #000, inset -3px -3px 0 rgba(0,0,0,.25);
}
.swatch.big { width: 22px; height: 22px; }
.agent-main { min-width: 0; flex: 1; }
.agent-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.agent-name { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  flex: none;
  font-size: 10px;
  font-weight: bold;
  padding: 1px 6px;
  color: #111;
  background: var(--c);
  box-shadow: 1px 1px 0 #000;
  white-space: nowrap;
}
.agent-sub { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; margin-top: 2px; }
.project { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.elapsed { flex: none; font-variant-numeric: tabular-nums; }
.agent-tool { font-size: 11px; margin-top: 3px; color: #cfe8d0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; padding: 28px 12px; color: var(--text); cursor: default; }
.empty-icon { font-size: 30px; margin-bottom: 8px; filter: drop-shadow(2px 2px 0 #000); }
.empty .muted { margin-top: 6px; }
.muted { color: var(--muted); }
code { background: #1c1c28; padding: 0 4px; color: #b9e3ff; }
.empty code { white-space: nowrap; }

/* ---------- details ---------- */
.details {
  flex: 0 1 auto;
  max-height: 55%;
  overflow-y: auto;
  padding: 12px 14px 16px;
  background: #24243a;
  border-top: var(--px) solid #12121a;
  box-shadow: inset 0 var(--px) 0 var(--line);
}
.details.placeholder { flex: none; }
.details.placeholder:empty { display: none; }
.det-head { display: flex; gap: 10px; align-items: center; }
.det-head > div { min-width: 0; flex: 1; }
.det-name { font-size: 15px; font-weight: bold; color: var(--accent); text-shadow: 2px 2px 0 #000; }
.path { opacity: .7; font-size: 11px; word-break: break-all; }
.close {
  flex: none;
  background: var(--panel-2); color: var(--text);
  border: 2px solid #000; box-shadow: 2px 2px 0 #000;
  font: bold 12px var(--font);
  width: 26px; height: 26px; cursor: pointer;
}
.close:hover { background: var(--bad); }
.det-title { margin: 10px 0 4px; padding: 6px 8px; background: #1c1c2a; border-left: 3px solid var(--accent); }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: 5px 10px; margin: 10px 0 0; }
.details dt { color: var(--muted); font-size: 11px; padding-top: 1px; }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.details dd.quote { font-style: italic; color: #d9d4c4; }
.details a { color: #8fd3ff; }
.id { font-size: 10px; }

/* ---------- debug overlay (?debug) ---------- */
#debug {
  position: fixed; left: 8px; bottom: 8px; z-index: 10;
  margin: 0; padding: 6px 8px;
  background: rgba(0,0,0,.75); color: #9f9;
  font: 11px/1.3 var(--font);
  pointer-events: none;
  max-width: 70vw;
  white-space: pre;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "top" "stage" "panel";
    height: auto;
  }
  #stage { padding: 12px; }
  #panel { border-left: 0; border-top: var(--px) solid #12121a; box-shadow: none; }
  .agent-list { max-height: none; overflow: visible; }
  .details { max-height: none; }
}
@media (max-width: 560px) {
  #topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .logo { font-size: 15px; }
  #stage { padding: 8px; }
  .frame { padding: 3px; }
}

/* =====================================================================
   v2 — cloud room UI, dialogs, rename, toast, mini window (CLOUD.md §9–§11, §15.1)
   ===================================================================== */
[hidden] { display: none !important; }
.mode-badge[data-mode="cloud"] { color: #8fd3ff; }
.room-name {
  font-weight: bold;
  color: var(--accent);
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 2px 2px 0 #000;
}

/* ---------- buttons / toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 5px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid #000;
  box-shadow: 2px 2px 0 #000, inset -2px -2px 0 rgba(0,0,0,.25);
  font: bold 12px/1.2 var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #45456a; }
.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #000; }
.btn:focus-visible { outline: 2px dashed var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.accent { background: #b8862b; color: #111; }
.btn.accent:hover { background: var(--accent); }
.btn.ghost { background: transparent; border-color: var(--line); box-shadow: none; }
.btn.small { padding: 2px 8px; font-size: 11px; }

/* ---------- landing ---------- */
.landing {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 24px;
  overflow-y: auto;
  background: rgba(14, 14, 22, .82);
}
.landing-card {
  width: min(760px, 100%);
  padding: 18px 20px 20px;
  background: var(--panel);
  border: var(--px) solid #000;
  box-shadow: 6px 6px 0 rgba(0,0,0,.55), inset 0 0 0 var(--px) var(--line);
}
.landing-card h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 20px; color: var(--accent); text-shadow: 2px 2px 0 #000; }
.landing-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.card-block { display: flex; flex-direction: column; gap: 8px; padding: 12px; background: #24243a; border: 2px solid #1a1a26; box-shadow: 2px 2px 0 #15151f; }
.card-block h3, .dlg h3 { margin: 0 0 2px; font-size: 13px; color: var(--accent); }
#recent-block { margin-top: 14px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input[type="text"], input:not([type]), input[type="password"], .landing input, .dlg input:not([type="checkbox"]) {
  font: 13px var(--font);
  padding: 6px 8px;
  color: var(--text);
  background: #16161f;
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.4);
  min-width: 0;
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.form-error { margin: 8px 0 0; padding: 6px 10px; color: #ffd7d7; background: #3a1f24; border: 2px solid var(--bad); }
.small { font-size: 11px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.recent-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border: 2px solid #1a1a26; }
.recent-name { flex: 1; min-width: 0; color: #8fd3ff; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10px; padding: 1px 6px; border: 1px solid currentColor; }
.tag-key { color: var(--ok); }
.tag-view { color: var(--muted); }
body.landing-open #panel, body.landing-open #stage { filter: blur(1px) brightness(.7); }

/* ---------- dialogs ---------- */
.dlg {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 14px 16px 16px;
  color: var(--text);
  background: var(--panel);
  border: var(--px) solid #000;
  box-shadow: 6px 6px 0 rgba(0,0,0,.55), inset 0 0 0 var(--px) var(--line);
  font: 13px/1.45 var(--font);
}
.dlg.wide { width: min(820px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 10, 16, .7); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 8px; }
.dlg-head h2 { margin: 0; font-size: 16px; color: var(--accent); text-shadow: 2px 2px 0 #000; }
.dlg h3 { margin-top: 12px; }
.dlg h4 { margin: 14px 0 4px; font-size: 12px; color: #cfe8d0; }
.dlg p { margin: 6px 0; }
.dlg a { color: #8fd3ff; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }
.setup-name { max-width: 320px; margin-bottom: 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 2px solid var(--line); }
.tab {
  padding: 6px 12px;
  font: bold 12px var(--font);
  color: var(--muted);
  background: transparent;
  border: 2px solid transparent;
  border-bottom: 0;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--accent); background: #24243a; border-color: var(--line); }
.tab-pane { padding: 10px 2px 2px; }
.cmd { position: relative; margin: 6px 0; }
.cmd pre {
  margin: 0;
  padding: 10px 84px 10px 10px;
  background: #121219;
  border: 2px solid #000;
  color: #b9e3ff;
  font: 12px/1.45 var(--font);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow: auto;
}
.cmd pre code { background: none; padding: 0; color: inherit; }
.cmd .copy-btn { position: absolute; top: 6px; right: 6px; }
.note { color: var(--warn); font-weight: bold; }
.danger { padding: 8px 10px; margin: 6px 0; color: #ffd7d7; background: #3a1f24; border: 2px solid var(--bad); }
.danger b { color: #ff8a80; }
.check { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); margin-top: 6px; cursor: pointer; }
.check input { margin-top: 2px; }
details summary { cursor: pointer; color: var(--muted); margin-top: 8px; }

/* ---------- list: owner groups (cloud) ---------- */
.owner-head {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 2px 6px;
  font-size: 12px;
  cursor: default;
}
.owner-head:first-child { margin-top: 2px; }
.owner-head .owner-name { font-weight: bold; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.owner-head .swatch { width: 10px; height: 10px; margin: 0; }
.owner-dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; vertical-align: 0; box-shadow: 0 0 0 1px #000; }
.owner-tag { white-space: nowrap; }

/* ---------- rename (§15.1) ---------- */
.det-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.det-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-name {
  flex: none;
  padding: 0 5px;
  font: bold 13px/18px var(--font);
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid #000;
  box-shadow: 1px 1px 0 #000;
  cursor: pointer;
  text-shadow: none;
}
.edit-name:hover { background: var(--accent); color: #111; }
.rename-box { display: flex; flex-direction: column; gap: 4px; }
.rename-input { font-weight: bold; color: var(--accent) !important; width: 100%; }
.rename-future { flex-direction: row; align-items: flex-start; gap: 6px; color: var(--text); font-size: 11px; cursor: pointer; }
.rename-future input { margin: 1px 0 0; }
.rename-hint { font-size: 10px; }
.rename-meta { margin-top: 6px; font-size: 11px; }
.default-name { color: #8a879c; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 18px; z-index: 40;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 10px);
  padding: 8px 14px;
  color: var(--text);
  background: #2f3f2f;
  border: 2px solid var(--ok);
  box-shadow: 3px 3px 0 #000;
  font: bold 12px/1.3 var(--font);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #3a1f24; border-color: var(--bad); color: #ffd7d7; }

/* ---------- mini window: ?view=mini popup and Document PiP (§11) ---------- */
.mini-strip { display: none; }
body.mini { overflow: hidden; background-size: 12px 12px; }
body.mini #app {
  height: 100vh;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "stage" "strip";
}
body.mini #topbar, body.mini #panel { display: none; }
body.mini #stage { padding: 4px; }
body.mini .frame { padding: 3px; }
body.mini .mini-strip, body.pip .mini-strip {
  display: block;
  grid-area: strip;
  padding: 3px 8px;
  background: var(--bg-2);
  border-top: 2px solid #12121a;
  color: var(--text);
  font: bold 11px/1.4 var(--font);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
body.mini #conn-banner { top: 6px; font-size: 11px; padding: 3px 8px; }
body.pip { margin: 0; height: 100vh; display: flex; flex-direction: column; }
body.pip .pip-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px; overflow: hidden; }
body.pip-open #stage::after {
  content: "Ofis mini pencerede açık";
  color: var(--muted);
  font-size: 13px;
}

/* ---------- responsive (v2 parts) ---------- */
@media (max-width: 1100px) {
  #topbar { flex-wrap: wrap; }
}
@media (max-width: 700px) {
  .landing-cols { grid-template-columns: 1fr; }
  .landing { padding-top: 16px; }
  .toolbar { width: 100%; }
  .cmd pre { padding-right: 10px; padding-top: 34px; }
}

.landing-guide { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.landing-guide a { color: var(--accent); }
