:root {
  color-scheme: dark;
  --bg: #0d1519;
  --panel: #152025;
  --panel-raised: #19272d;
  --input: #121c21;
  --border: #2b3c42;
  --text: #f1f6f4;
  --muted: #a7bab9;
  --accent: #aef2ca;
  --accent-hover: #c6f8db;
  --dark: #172d25;
  --error: #ffb8ad;
  --radius: 16px;
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 1rem/1.5 var(--font); }
button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
input, textarea, select {
  width: 100%; padding: .72rem .9rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--input);
}
input::placeholder, textarea::placeholder { color: #8ea29f; }
textarea { display: block; min-height: 8rem; resize: vertical; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
.icons, .visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
.icon { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.small { width: 1.05rem; height: 1.05rem; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem;
  padding: 0; background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: 9px;
}
.icon-button:hover { color: var(--text); background: #ffffff0a; }
.primary-button, .secondary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.75rem;
  padding: .65rem .96rem; background: var(--accent); color: var(--dark); border: 1px solid transparent;
  border-radius: 10px; font-size: .92rem; font-weight: 720; white-space: nowrap; text-decoration: none;
}
.primary-button:hover:not(:disabled) { background: var(--accent-hover); }
.secondary-button { color: var(--text); background: transparent; border-color: var(--border); }
.secondary-button:hover { background: #ffffff09; }
.secondary-button.danger-button { color: var(--error); border-color: #795154; }
.secondary-button.danger-button:hover:not(:disabled) { background: #ffb8ad12; }
.primary-button.danger-button { background: var(--error); color: #371e20; }
.primary-button.danger-button:hover:not(:disabled) { background: #ffcbc4; }
.text-button { color: var(--accent); padding: .2rem 0; border: 0; background: none; font-size: .9rem; font-weight: 650; }
.text-button:hover { text-decoration: underline; }
.form-error { color: var(--error); font-size: .92rem; overflow-wrap: anywhere; }
.loading-view { padding: 10vh 7vw; color: var(--muted); }

.brand { display: flex; align-items: center; gap: .7rem; width: max-content; font-size: 1.04rem; font-weight: 760; line-height: 1.1; letter-spacing: -.02em; }
.brand-mark {
  display: grid; flex: none; place-items: center; width: 2.5rem; height: 2.5rem; color: var(--accent);
  background: #203630; border: 1px solid #345448; border-radius: 10px;
}
.brand-mark svg { width: 1.5rem; height: 1.5rem; }
.brand-owner { display: block; margin-top: .26rem; color: var(--muted); font-size: .69rem; font-weight: 570; letter-spacing: .045em; }

.login-view { display: grid; min-height: 100svh; grid-template-columns: minmax(25rem, 44%) minmax(0, 1fr); }
.login-content { display: grid; grid-template-rows: auto 1fr auto; min-height: 100svh; padding: clamp(1.6rem, 4.2vw, 4.25rem); }
.login-panel { width: min(100%, 26rem); margin: auto 0; padding: 2.8rem 0 3.8rem; }
.access-label { display: flex; align-items: center; gap: .48rem; color: var(--accent); font-size: .85rem; font-weight: 630; }
.login-panel h1 { margin: .9rem 0 .86rem; font-size: clamp(2.4rem, 4.5vw, 4.8rem); line-height: 1.02; letter-spacing: -.065em; font-weight: 745; }
.login-panel h1 span { color: var(--accent); }
.login-panel > p { max-width: 22rem; color: var(--muted); font-size: 1.05rem; line-height: 1.6; }
.login-form { display: grid; gap: .44rem; margin-top: 1.85rem; }
.login-form label { font-size: .93rem; font-weight: 650; }
.login-form label:not(:first-child) { margin-top: .48rem; }
.login-form input { height: 3rem; }
.password-field { position: relative; }
.password-field input { padding-right: 3.2rem; }
.password-field button { position: absolute; top: .25rem; right: .28rem; }
.login-submit { margin-top: .74rem; min-height: 3rem; }
.login-form .form-error { margin-top: .45rem; }
.login-footer { display: flex; align-items: center; gap: .7rem; color: #a7bab9; font-size: .78rem; }
.login-footer span { width: .22rem; height: .22rem; border-radius: 50%; background: #77a193; }
.login-art {
  position: relative; min-height: 27rem; margin: 1.15rem 1.15rem 1.15rem 0; border: 1px solid #304248;
  isolation: isolate; overflow: hidden; border-radius: 22px;
  background: #1a3034 url('/assets/office-hero.webp') center center / cover no-repeat;
}
.login-art::after { position: absolute; z-index: -1; inset: 45% 0 0; content: ''; background: linear-gradient(transparent, #071315be); }
.login-art-caption {
  position: absolute; bottom: clamp(1.05rem, 3.3vw, 3rem); left: clamp(1.05rem, 3.3vw, 3rem);
  display: flex; align-items: center; gap: .72rem; min-height: 3.25rem; padding: .45rem .9rem;
  background: #111e22e8; border: 1px solid #a5e4c647; border-radius: 11px; font-weight: 690;
}
.login-art-caption > svg { color: var(--accent); }
.login-art-caption span { display: block; color: var(--muted); font-size: .78rem; font-weight: 480; }

.app-bar {
  position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: .9rem; min-height: 4.45rem; padding: .65rem clamp(1rem, 3vw, 3rem); border-bottom: 1px solid #26363b; background: #121c21;
}
.app-identity { display: flex; align-items: center; gap: .86rem; }
.menu-toggle { border-color: #304247; }
.signed-user { display: flex; align-items: center; gap: .44rem; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.main-menu {
  position: absolute; top: 4.15rem; left: clamp(1rem, 3vw, 3rem); display: grid; gap: .15rem;
  width: max-content; min-width: 13rem; padding: .39rem; background: var(--panel-raised);
  border: 1px solid #3b5256; border-radius: 12px; box-shadow: 0 16px 35px #0007;
}
.main-menu button {
  display: flex; align-items: center; gap: .64rem; min-height: 2.6rem; padding: .4rem .68rem;
  color: var(--text); text-align: left; background: transparent; border: 0; border-radius: 7px;
}
.main-menu button:hover { background: #ffffff0b; }
.main-menu button:first-child { color: var(--accent); }
.main-menu button:last-child { border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; }
.office-content { max-width: 105rem; padding: clamp(1.3rem, 3vw, 2.8rem); margin-inline: auto; }
.office-heading { display: flex; align-items: end; justify-content: space-between; gap: .9rem; margin-bottom: 1.4rem; }
.office-heading h1 { font-size: clamp(2rem, 3.7vw, 3.75rem); line-height: 1.03; letter-spacing: -.061em; }
.office-heading p { margin-top: .47rem; color: var(--muted); }
.office-content > .form-error { margin-bottom: 1rem; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem); align-items: start; gap: 1rem; }
.map-panel, .activity-panel { min-width: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; min-height: 3.2rem; padding: .65rem 1rem; border-bottom: 1px solid var(--border); }
.panel-header h2 { display: flex; align-items: center; gap: .55rem; color: var(--text); font-size: 1rem; font-weight: 690; }
.panel-header h2 .icon { color: var(--accent); }
.office-count, .running-count { color: var(--muted); font-size: .82rem; }
.office-map {
  position: relative; isolation: isolate; height: clamp(25rem, 68vh, 52rem); overflow: auto;
  contain: layout inline-size; overscroll-behavior-inline: contain;
  background: #0b1924; scrollbar-color: #405c64 #101e2a;
}
.map-scene { position: relative; min-width: 100%; min-height: 100%; }
#map-canvas { display: block; width: 100%; height: 100%; }
.desk-buttons { position: absolute; inset: 0; pointer-events: none; }
.desk-button {
  position: absolute; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; width: 5.75rem; min-height: 3rem;
  padding: 0; transform: translate(-50%, -58%); background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 8px;
  outline-offset: 2px; pointer-events: auto;
}
.desk-button span {
  display: flex; align-items: center; gap: .3rem; max-width: 100%; padding: .05rem .31rem;
  background: #102029f2; border: 1px solid #627e7a; border-radius: 6px;
  box-shadow: 0 2px 6px #0006; font-size: .72rem; font-weight: 665;
}
.desk-button .desk-name { display: block; width: min-content; max-width: 4.6rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.desk-button:hover, .desk-button[aria-pressed='true'] { background: #aef2ca17; border-color: #aef2ca3d; }
.status-dot { display: inline-block; width: .48rem; height: .48rem; flex: none; border-radius: 50%; background: #9aabb1; }
.status-dot.running, .status-dot.active { background: var(--accent); box-shadow: 0 0 8px #aef2ca60; }
.status-dot.queued { background: #f9d894; }
.status-dot.failed { background: var(--error); }
.desk-tooltip {
  position: absolute; z-index: 3; width: min(15rem, calc(100% - 1rem)); padding: .68rem .78rem; pointer-events: none;
  border: 1px solid #466a61; background: #192a2dee; color: var(--text); border-radius: 10px; box-shadow: 0 10px 20px #0007;
  font-size: .86rem; overflow-wrap: anywhere;
}
.desk-tooltip b { display: block; margin-bottom: .18rem; }
.desk-tooltip div + div { margin-top: .22rem; }
.desk-tooltip .tooltip-role { color: var(--muted); }
.office-empty {
  position: absolute; bottom: 1rem; left: 1rem; max-width: calc(100% - 2rem); padding: .45rem .66rem;
  background: #102025ec; border: 1px solid #354a51; border-radius: 8px; color: #c2d3d0; font-size: .85rem;
}
.activity-panel { min-height: 16rem; }
.activity-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 14rem; padding: 1rem; color: var(--muted); text-align: center; }
.activity-empty > .icon { box-sizing: content-box; margin-bottom: .58rem; padding: .62rem; border: 1px solid #355247; border-radius: 11px; color: var(--accent); background: #213830; }
.activity-empty .text-button { margin-top: .32rem; }
.activity-list { display: grid; gap: .45rem; padding: .65rem; }
.activity-list:empty { display: none; }
.activity-item {
  display: grid; grid-template-columns: 2.35rem 1fr auto; align-items: center; gap: .55rem;
  padding: .52rem; color: var(--text); text-align: left; border: 1px solid #2c4045; border-radius: 10px; background: #19272c;
}
.activity-item:hover, .activity-item[aria-pressed='true'] { border-color: #598a74; background: #1c302e; }
.activity-avatar, .detail-avatar { display: block; width: 100%; border-radius: 8px; background: #213837; }
.activity-item b, .activity-item small { display: block; overflow-wrap: anywhere; }
.activity-item b { font-size: .89rem; }
.activity-item small { color: var(--muted); font-size: .79rem; }
.agent-detail { padding: .8rem 1rem; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.agent-detail h3 { margin-top: 0; font-size: 1.02rem; }
.detail-header { display: grid; grid-template-columns: 2.7rem 1fr auto; align-items: center; gap: .57rem; }
.detail-header .icon-button { width: 2rem; height: 2rem; }
.detail-role, .detail-meta, .detail-time { color: var(--muted); font-size: .84rem; }
.detail-status { display: flex; align-items: center; gap: .43rem; margin-top: .6rem; font-size: .84rem; font-weight: 650; }
.detail-body { display: grid; gap: .45rem; margin-top: .44rem; font-size: .9rem; white-space: pre-wrap; }
.detail-body .detail-personality { color: var(--muted); }
.detail-body code { font-family: ui-monospace, monospace; color: var(--accent); font-size: .8rem; }
.detail-file, .detail-link { display: flex; align-items: flex-start; gap: .34rem; }
.detail-action { width: max-content; margin-top: .3rem; }
.detail-time { margin-top: .55rem; }

.dialog {
  width: min(36rem, calc(100% - 1.5rem)); max-height: calc(100svh - 2rem); padding: 0; color: var(--text);
  background: #18262b; border: 1px solid #41595d; border-radius: 17px; box-shadow: 0 20px 75px #0009;
}
.dialog::backdrop { background: #050d11bd; backdrop-filter: blur(4px); }
.delete-dialog { max-width: 27rem; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .65rem; padding: 1.1rem 1.2rem .9rem; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: clamp(1.3rem, 3vw, 1.7rem); letter-spacing: -.032em; }
.dialog-step { color: var(--accent); font-size: .82rem; font-weight: 620; }
.avatar-step { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 1rem; align-items: start; padding: 1.15rem 1.2rem; }
.avatar-preview { display: grid; justify-items: center; align-self: stretch; align-content: center; min-height: 9rem; background: #112126; padding: .6rem; border: 1px solid #36554f; border-radius: 12px; }
.avatar-preview canvas { display: block; width: min(100%, 11.5rem); height: auto; aspect-ratio: 1; }
.avatar-preview span { color: var(--muted); font-size: .82rem; }
.avatar-options { display: grid; gap: .59rem; }
.avatar-options label, .settings-fields label { display: block; font-size: .92rem; font-weight: 660; }
select {
  display: block; margin-top: .26rem; padding-right: 2rem; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #a7bab9 50%), linear-gradient(135deg, #a7bab9 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.swatch-group { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: 0; padding: 0; border: 0; }
.swatch-group legend { margin-bottom: .32rem; padding: 0; font-size: .92rem; font-weight: 660; }
.swatch { display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 8px; }
.swatch::before { width: 1.45rem; height: 1.45rem; border: 1px solid #ffffff40; border-radius: 6px; background: var(--swatch-color); content: ''; }
.swatch:hover, .swatch[aria-pressed='true'] { border-color: var(--accent); }
.swatch[aria-pressed='true'] { background: #aef2ca29; }
.prompt-step, .settings-fields, .delete-description { padding: 1rem 1.2rem 1.2rem; }
.delete-description { color: var(--muted); overflow-wrap: anywhere; }
.delete-description strong { color: var(--text); }
.prompt-intro { display: flex; align-items: center; gap: .65rem; margin-bottom: .85rem; }
.prompt-intro h3 { font-size: 1rem; }
.prompt-intro p, .settings-fields p { color: var(--muted); font-size: .9rem; }
.settings-fields p { margin: .27rem 0 .85rem; }
.dialog-error { margin: 0 1.2rem .82rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .65rem; padding: .85rem 1.2rem; border-top: 1px solid var(--border); }

@media (max-width: 830px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .activity-panel { min-height: auto; }
  .activity-empty { min-height: 9rem; }
  .login-view { grid-template-columns: minmax(19rem, 49%) minmax(0, 1fr); }
  .login-content { padding: 1.6rem; }
  .login-art { margin: .75rem .75rem .75rem 0; }
}
@media (max-width: 590px) {
  .login-view { display: flex; flex-direction: column; }
  .login-content { display: flex; flex-direction: column; min-height: auto; padding: 1.2rem 1.25rem; }
  .login-panel { margin: 0; padding: clamp(1.65rem, 5vw, 3rem) 0 1.5rem; }
  .login-panel h1 { font-size: clamp(2.35rem, 10.5vw, 3.18rem); }
  .login-panel > p { font-size: 1rem; }
  .wide-only, .login-footer { display: none; }
  .login-art { order: 2; min-height: 16rem; margin: 0 .75rem .75rem; border-radius: 15px; background-position: center 69%; }
  .login-art-caption { padding: .35rem .55rem; min-height: 2.55rem; font-size: .82rem; }
  .login-art-caption span { display: none; }
  .app-bar { padding: .55rem .75rem; min-height: 3.7rem; }
  .app-identity { gap: .48rem; }
  .app-bar .brand-mark { width: 2.1rem; height: 2.1rem; }
  .app-bar .brand-mark svg { width: 1.28rem; height: 1.28rem; }
  .main-menu { left: .75rem; top: 3.6rem; }
  .office-content { padding: 1rem .75rem; }
  .office-heading { align-items: center; }
  .office-heading h1 { font-size: clamp(1.55rem, 6vw, 2.2rem); }
  .office-heading p { display: none; }
  .office-heading .primary-button { padding: .55rem .65rem; font-size: .82rem; }
  .signed-user .icon { display: none; }
  .office-map { height: clamp(23rem, 58vh, 33rem); }
  .dialog-header, .avatar-step, .prompt-step, .settings-fields, .delete-description, .dialog-actions { padding-right: .88rem; padding-left: .88rem; }
  .avatar-step { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: .65rem; }
  .avatar-preview { padding: .28rem; }
  .avatar-preview span { text-align: center; }
}
@media (prefers-reduced-motion: no-preference) {
  button, a { transition: background-color .12s ease, color .12s ease, border-color .12s ease; }
}
