:root {
  --bg: #020617;
  --panel: #0f172a;
  --panel-2: #111827;
  --line: rgba(148, 163, 184, .22);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0369a1;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --user: #075985;
  --assistant: #1e293b;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, #1e293b 0, #0f172a 44%, #020617 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
textarea,
input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell {
  width: min(980px, 100vw);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: rgba(2, 6, 23, .45);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.topbar {
  flex: 0 0 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, .92);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: linear-gradient(135deg, #0284c7, #075985);
  color: white;
  box-shadow: 0 10px 28px rgba(2, 132, 199, .22);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 58vw;
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(17, 24, 39, .78);
  border-radius: 12px;
  padding: 9px 11px;
  white-space: nowrap;
}

.ghost-button:hover { border-color: rgba(56, 189, 248, .6); }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: min(820px, 86%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px 13px;
  line-height: 1.46;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
  border-bottom-right-radius: 5px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border-bottom-left-radius: 5px;
}

.bubble.system {
  align-self: center;
  max-width: min(780px, 96%);
  background: rgba(245, 158, 11, .10);
  color: #fde68a;
  font-size: 13px;
}

.bubble.security {
  align-self: center;
  max-width: min(780px, 96%);
  background: rgba(239, 68, 68, .12);
  color: #fecaca;
  border-color: rgba(248, 113, 113, .38);
  font-size: 13px;
}

.render-image {
  display: block;
  max-width: min(100%, 760px);
  max-height: 72vh;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: 8px 0;
  background: #020617;
}

.file-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.file-chip,
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid rgba(148, 163, 184, .24);
  background: rgba(15, 23, 42, .74);
  border-radius: 12px;
  padding: 8px 10px;
  color: #cbd5e1;
  font-size: 12px;
}

.file-row button {
  border: 0;
  border-radius: 999px;
  background: rgba(239, 68, 68, .18);
  color: #fecaca;
  padding: 2px 8px;
}

.file-preview {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.file-preview img,
.file-preview video {
  display: block;
  max-width: min(420px, 86vw);
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #000;
}

.interaction-host {
  flex: 0 0 auto;
  padding: 0 12px;
}

.interaction-card {
  margin: 6px auto 8px;
  width: min(720px, 100%);
  border: 1px solid rgba(250, 204, 21, .55);
  background: rgba(17, 24, 39, .96);
  color: var(--text);
  border-radius: 16px;
  padding: 13px;
  box-shadow: 0 18px 55px rgba(0, 0, 0, .38);
}

.interaction-card h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #fde68a;
}

.interaction-card p {
  margin: 0 0 10px;
  font-size: 13px;
  color: #d1d5db;
  white-space: pre-wrap;
}

.interaction-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.interaction-actions button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #1f2937;
  color: var(--text);
}

.interaction-actions .approve { border-color: rgba(34, 197, 94, .55); color: #bbf7d0; }
.interaction-actions .deny { border-color: rgba(248, 113, 113, .60); color: #fecaca; }

.clarify-input-row {
  display: flex;
  gap: 8px;
}

.clarify-input-row input {
  min-width: 0;
  flex: 1;
  border: 1px solid rgba(147, 197, 253, .45);
  background: #020617;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}

.file-tray {
  flex: 0 0 auto;
  margin: 0 12px 8px;
  padding: 8px;
  border: 1px solid rgba(56, 189, 248, .25);
  background: rgba(56, 189, 248, .11);
  border-radius: 14px;
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(15, 23, 42, .98);
}

.attach-button,
.send-button {
  height: 46px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  color: white;
}

.attach-button {
  background: #334155;
  font-size: 22px;
}

.send-button {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  font-size: 13px;
}

#messageInput {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  max-height: 130px;
  resize: none;
  border: 1px solid rgba(125, 211, 252, .55);
  background: #020617;
  color: #f8fafc;
  border-radius: 14px;
  padding: 12px;
  line-height: 20px;
  outline: none;
}

#messageInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .16);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .app-shell { width: 100vw; border: 0; }
  .topbar { flex-basis: 58px; padding: 8px 10px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 12px; }
  .brand h1 { font-size: 16px; }
  .ghost-button { padding: 8px 9px; font-size: 12px; }
  .messages { padding: 10px; }
  .bubble { max-width: 94%; font-size: 14px; }
  .composer { grid-template-columns: 44px minmax(0, 1fr) 74px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .send-button { font-size: 12px; }
}

/* === Dijimek Field UI V2: safe render cards === */
.render-card {
  margin: 10px 0;
  display: grid;
  gap: 6px;
}

.render-image {
  display: block;
  max-width: min(100%, 860px);
  max-height: 72vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, .28);
  background: #020617;
}

.render-link {
  color: #93c5fd;
  font-size: 12px;
  text-decoration: none;
  word-break: break-word;
}

.render-link:hover {
  text-decoration: underline;
}

/* === Dijimek Field UI V2: activity / waiting bubble === */
.activity-bubble {
  opacity: .92;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border-color: rgba(56, 189, 248, .28);
  background: rgba(15, 23, 42, .88);
}

.activity-text {
  color: #cbd5e1;
}

.activity-dots {
  color: #38bdf8;
  display: inline-block;
  animation: dfuiPulseDot 1.1s ease-in-out infinite;
  font-size: 10px;
}

@keyframes dfuiPulseDot {
  0%, 100% {
    transform: scale(.85);
    opacity: .45;
  }
  50% {
    transform: scale(1.25);
    opacity: 1;
  }
}

/* === Dijimek Field UI V2: audio upload preview === */
.file-preview.audio-preview {
  width: min(100%, 520px);
}

.file-preview.audio-preview audio {
  width: 100%;
  display: block;
}

/* === Dijimek Field UI V2: push-to-talk voice button === */
.voice-record-button {
  min-width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, .32);
  background: rgba(15, 23, 42, .92);
  color: #e5e7eb;
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.voice-record-button.recording {
  background: rgba(220, 38, 38, .95);
  border-color: rgba(252, 165, 165, .7);
  color: #fff;
  animation: dfuiVoicePulse 1s ease-in-out infinite;
}

.voice-status {
  min-height: 18px;
  margin: 0 12px 6px;
  color: #94a3b8;
  font-size: 12px;
}

.voice-status.recording {
  color: #fecaca;
}

.voice-status.ok {
  color: #bbf7d0;
}

.voice-status.warn {
  color: #fde68a;
}

.voice-status.error {
  color: #fecaca;
}

@keyframes dfuiVoicePulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(248, 113, 113, .55);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 8px rgba(248, 113, 113, 0);
  }
}

@media (max-width: 800px) {
  .voice-record-button {
    min-width: 46px;
    height: 46px;
    font-size: 20px;
  }
}

/* === Dijimek Field UI V2: compact + action menu === */
.legacy-attach-hidden {
  display: none !important;
}

.composer {
  grid-template-columns: 44px minmax(0, 1fr) 76px !important;
  align-items: end;
}

.composer-action-menu {
  position: relative;
  width: 44px;
  min-width: 44px;
}

.composer-action-button {
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, .32);
  background: #334155;
  color: #f8fafc;
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
}

.composer-action-button.recording {
  background: rgba(220, 38, 38, .95);
  border-color: rgba(252, 165, 165, .75);
  color: #fff;
  font-size: 18px;
  animation: dfuiVoicePulse 1s ease-in-out infinite;
}

.composer-action-panel {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: 190px;
  padding: 7px;
  border-radius: 14px;
  background: #111827;
  border: 1px solid rgba(148, 163, 184, .30);
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
  z-index: 100;
}

.composer-action-menu.open .composer-action-panel {
  display: grid;
  gap: 7px;
}

.composer-action-item {
  width: 100%;
  min-height: 42px;
  border-radius: 11px;
  border: 1px solid rgba(148, 163, 184, .22);
  background: rgba(15, 23, 42, .95);
  color: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.composer-action-item:hover {
  border-color: rgba(56,189,248,.6);
  color: #fff;
}

.voice-hold-button.recording {
  background: rgba(127, 29, 29, .9);
  border-color: rgba(252, 165, 165, .75);
  color: #fff;
}

@media (max-width: 800px) {
  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 72px !important;
    gap: 7px;
  }

  .composer-action-menu,
  .composer-action-button {
    width: 42px;
    min-width: 42px;
  }

  .composer-action-button {
    height: 46px;
    min-height: 46px;
    font-size: 25px;
  }

  .composer-action-panel {
    width: min(220px, 78vw);
    bottom: calc(100% + 9px);
  }
}

@media (max-width: 380px) {
  .composer {
    grid-template-columns: 40px minmax(0, 1fr) 64px !important;
    gap: 6px;
  }

  .composer-action-menu,
  .composer-action-button {
    width: 40px;
    min-width: 40px;
  }
}

/* === Safety guard: composer must never be hidden === */
.composer.legacy-attach-hidden {
  display: grid !important;
}

/* === Final composer layout guard: only + / input / send === */
.composer {
  display: grid !important;
  grid-template-columns: 44px minmax(0, 1fr) 76px !important;
  gap: 8px !important;
  align-items: end !important;
  width: 100% !important;
}

.composer > label {
  display: none !important;
}

.composer.legacy-attach-hidden {
  display: grid !important;
}

#messageInput {
  min-width: 0 !important;
  width: 100% !important;
}

#sendButton {
  width: 76px !important;
  min-width: 0 !important;
}

#composerActionMenuWrap {
  grid-column: 1 !important;
}

#messageInput {
  grid-column: 2 !important;
}

#sendButton {
  grid-column: 3 !important;
}

@media (max-width: 800px) {
  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 72px !important;
    gap: 7px !important;
  }

  #sendButton {
    width: 72px !important;
  }
}

@media (max-width: 380px) {
  .composer {
    grid-template-columns: 40px minmax(0, 1fr) 64px !important;
    gap: 6px !important;
  }

  #sendButton {
    width: 64px !important;
  }
}

/* === Clean composer final guard === */
.composer {
  display: grid !important;
  grid-template-columns: 44px minmax(0, 1fr) 76px !important;
  gap: 8px !important;
  align-items: end !important;
  width: 100% !important;
}

.composer > label {
  display: none !important;
}

#composerActionMenuWrap {
  grid-column: 1 !important;
}

#messageInput {
  grid-column: 2 !important;
  min-width: 0 !important;
  width: 100% !important;
}

#sendButton {
  grid-column: 3 !important;
  width: 76px !important;
  min-width: 0 !important;
}

@media (max-width: 800px) {
  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 72px !important;
    gap: 7px !important;
  }

  #sendButton {
    width: 72px !important;
  }
}

@media (max-width: 380px) {
  .composer {
    grid-template-columns: 40px minmax(0, 1fr) 64px !important;
    gap: 6px !important;
  }

  #sendButton {
    width: 64px !important;
  }
}

/* === Send button must stay usable in field UI === */
#sendButton,
#sendButton:disabled {
  pointer-events: auto !important;
  cursor: pointer !important;
  opacity: 1 !important;
}

#messageInput,
#messageInput:disabled {
  pointer-events: auto !important;
  cursor: text !important;
  opacity: 1 !important;
}


/* Web AL UI Login / Actor */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, rgba(30, 41, 59, .98), rgba(2, 6, 23, .98));
}

.auth-card {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid rgba(148, 163, 184, .28);
  border-radius: 22px;
  background: rgba(15, 23, 42, .96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}

.auth-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  font-weight: 900;
  background: linear-gradient(135deg, #0284c7, #075985);
  color: white;
}

.auth-card h2 {
  margin: 0;
  font-size: 20px;
}

.auth-note {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.auth-card input {
  width: 100%;
  border: 1px solid rgba(125, 211, 252, .45);
  background: #020617;
  color: var(--text);
  border-radius: 13px;
  padding: 12px;
  outline: none;
}

.auth-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .16);
}

.auth-submit {
  height: 44px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  font-weight: 800;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: #fecaca;
  font-size: 13px;
}

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.auth-user {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cbd5e1;
  font-size: 12px;
}

.auth-logout {
  border: 1px solid rgba(148, 163, 184, .28);
  color: #e5e7eb;
  background: rgba(17, 24, 39, .78);
  border-radius: 10px;
  padding: 7px 9px;
  white-space: nowrap;
  font-size: 12px;
}

@media (max-width: 640px) {
  .auth-box {
    gap: 5px;
  }

  .auth-user {
    max-width: 118px;
    font-size: 11px;
  }

  .auth-logout {
    padding: 6px 7px;
    font-size: 11px;
  }
}
