* { box-sizing: border-box; }

/* The HTML `hidden` attribute's default (display: none) lives in the
   user-agent stylesheet, the LOWEST-priority origin tier - ANY author
   rule that sets `display` on the same element overrides it, no
   matter how low that rule's specificity is (origin tier beats
   specificity). Several selectors below set `display` unconditionally
   (.chat-container, .coding-panel, .coding-approvals, ...), so without
   this rule `el.hidden = true` does not actually hide them. This one
   rule guarantees `hidden` always wins, for every element, present and
   future - see the M3 manual-test bug report this fixed. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1115;
  color: #e6e6e6;
  height: 100vh;
  height: 100dvh; /* follows the address bar and keyboard: the same unit as the phone chat box below */
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-container {
  width: 100%;
  max-width: 640px;
  height: 90vh;
  background: #161922;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

header {
  padding: 16px 20px;
  border-bottom: 1px solid #262a36;
  display: flex;
  align-items: center;
  gap: 8px;
}

header h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0.5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  margin-left: auto;
}

.status-dot.ok { background: #3ddc84; }
.status-dot.error { background: #ff5c5c; }

.username-display {
  font-size: 13px;
  opacity: 0.75;
}

.logout-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #262a36;
  background: transparent;
  color: #e6e6e6;
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover { background: #262a36; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: #2f6fed;
  color: white;
  border-bottom-right-radius: 2px;
}

.msg.assistant {
  align-self: flex-start;
  background: #262a36;
  border-bottom-left-radius: 2px;
}

.msg.failed {
  align-self: flex-start;
  background: #3a1e1e;
  border: 1px solid #ff5c5c;
  color: #ffb3b3;
}

.msg.assistant.pending {
  opacity: 0.65;
  font-style: italic;
}

.msg .meta {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
}

/* Rendered Markdown inside AI answers (static/markdown.js). Scoped to .md so
   plain-text bubbles keep their original pre-wrap look. */
.msg .md { white-space: normal; }
.msg .md > :first-child { margin-top: 0; }
.msg .md > :last-child { margin-bottom: 0; }
.msg .md p { margin: 0 0 8px; }
.msg .md ul, .msg .md ol { margin: 0 0 8px; padding-left: 22px; }
.msg .md li { margin: 2px 0; }
.msg .md li > ul, .msg .md li > ol { margin: 2px 0 0; }
.msg .md h1, .msg .md h2, .msg .md h3,
.msg .md h4, .msg .md h5, .msg .md h6 { font-size: 1.05em; margin: 10px 0 6px; }
.msg .md code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
}
.msg .md pre {
  margin: 0 0 8px;
  padding: 8px 10px;
  background: #0f1115;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
.msg .md pre code { background: none; padding: 0; }
.msg .md a { color: #7fb0ff; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid #262a36;
}

.chat-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #262a36;
  background: #0f1115;
  color: #e6e6e6;
  font-size: 14px;
}

.chat-form button {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: #2f6fed;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.chat-form button:hover { background: #245bc9; }

.login-container {
  width: 100%;
  max-width: 360px;
  background: #161922;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  padding: 28px 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form h1 {
  margin: 0 0 4px;
  font-size: 18px;
  text-align: center;
}

.login-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #262a36;
  background: #0f1115;
  color: #e6e6e6;
  font-size: 14px;
}

.login-form button {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: #2f6fed;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.login-form button:hover { background: #245bc9; }

.login-form button.login-secondary {
  background: #262a36;
  font-weight: 500;
}

.login-form button.login-secondary:hover { background: #30364a; }

/* 2FA field: "Joylash" sits inside the input's right edge (text only). */
.totp-field { position: relative; }
.totp-field:has(#login-totp[hidden]) { display: none; }
.totp-field input { width: 100%; box-sizing: border-box; padding-right: 96px; min-height: 44px; }
.totp-paste { position: absolute; top: 0; right: 0; }
.login-form button.totp-paste {
  background: transparent;
  color: #6ea0ff;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  font-weight: 600;
}
.login-form button.totp-paste:hover { background: transparent; color: #9bbcff; }
.totp-hint { margin: 6px 2px 0; font-size: 12px; color: #9aa0b0; }

.login-error {
  color: #ffb3b3;
  background: #3a1e1e;
  border: 1px solid #ff5c5c;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

/* Coding Agent session panel + approval cards (M3 Batch 4). */

.coding-approvals {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 20px;
}

.approval-card {
  background: #262a36;
  border: 1px solid #3a3f4f;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.approval-card-title {
  font-weight: 600;
  font-size: 13px;
}

.approval-card-id {
  font-size: 12px;
  opacity: 0.7;
}

.approval-card-status {
  font-size: 12px;
  min-height: 14px;
  color: #ffb3b3;
}

.approval-card-approve,
.approval-card-deny {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.approval-card-approve {
  background: #3ddc84;
  color: #0f1115;
}

.approval-card-approve:hover { background: #30c26f; }

.approval-card-deny {
  background: transparent;
  border: 1px solid #3a3f4f;
  color: #e6e6e6;
}

.approval-card-deny:hover { background: #3a3f4f; }

.approval-card-approve:disabled,
.approval-card-deny:disabled {
  opacity: 0.5;
  cursor: default;
}

.coding-panel {
  margin: 0 20px 12px;
  border: 1px solid #3a3f4f;
  border-radius: 10px;
  background: #11141b;
  display: flex;
  flex-direction: column;
  max-height: 220px;
}

.coding-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #262a36;
}

.coding-panel-title {
  font-weight: 600;
  font-size: 13px;
}

.coding-session-id {
  font-size: 11px;
  opacity: 0.6;
  margin-right: auto;
}

.coding-stop-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: none;
  background: #ff5c5c;
  color: white;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}

.coding-stop-btn:hover { background: #e14d4d; }

.coding-stream {
  overflow-y: auto;
  padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.coding-stream-line {
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: 4px 0;
  border-bottom: 1px solid #1c2029;
}

.coding-stream-line.coding-ended {
  color: #3ddc84;
  font-weight: 600;
}

.coding-stream-line.coding-error,
.coding-stream-line.coding-stopped {
  color: #ffb3b3;
}

/* Computer Agent approval view (M3 Computer Agent Batch 2) - used from
   the owner's phone, so it sits at the top and has large buttons. */

.computer-approval {
  margin: 12px 20px 0;
  padding: 12px 14px;
  border: 2px solid #f0b429;
  border-radius: 10px;
  background: #1d1a10;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.computer-approval-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.computer-approval-title {
  font-weight: 700;
  font-size: 14px;
  margin-right: auto;
}

/* STOP is the one control that must always be easy to hit: full width, tall. */
.computer-stop-btn {
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: #ff5c5c;
  color: white;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

.computer-task {
  font-size: 13px;
  word-break: break-word;
}

.computer-task:empty { display: none; }

/* Safe auto mode: a calm note, not an alarm - STOP below it stays the big button. */
.computer-auto-line {
  font-size: 13px;
  color: #9fd8b0;
  border-left: 3px solid #3ddc84;
  padding-left: 8px;
}

.computer-summary-counts { font-size: 13px; opacity: 0.85; }
.computer-summary-counts:empty { display: none; }

/* The thumbnail: the marker is positioned in percent of the picture. */
.computer-shot-frame {
  position: relative;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3a3f4f;
}

.computer-shot-img {
  width: 100%;
  height: auto;
  display: block;
  min-height: 60px;
  background: #11131a;
}

/* No picture yet: no broken-image box. */
.computer-shot-img:not([src]),
.computer-shot-img[src=""] { display: none; }

.computer-marker {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 3px solid #ff3b3b;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff, 0 0 8px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.computer-warning {
  font-size: 13px;
  color: #ffd27a;
  border-left: 3px solid #f0b429;
  padding-left: 8px;
}

/* The step text already starts with its number. */
.computer-steps {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 12px;
  max-height: 160px;
  overflow-y: auto;
  word-break: break-word;
}

.computer-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid #3a3f4f;
  border-radius: 8px;
}

.computer-summary-headline { font-weight: 700; }

/* The model's own words: clearly marked, never styled like a success. */
.computer-unverified {
  font-size: 13px;
  font-weight: 700;
  color: #ffd27a;
  border: 1px dashed #f0b429;
  border-radius: 6px;
  padding: 4px 8px;
}

.computer-summary-claim { font-style: italic; word-break: break-word; }
.computer-summary-claim:empty { display: none; }

.computer-summary-shot {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #3a3f4f;
}

.computer-summary-shot:not([src]),
.computer-summary-shot[src=""] { display: none; }

.computer-dismiss-btn {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid #3a3f4f;
  background: transparent;
  color: #e6e6e6;
  font-weight: 700;
  cursor: pointer;
}

.computer-action {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* A caption line under the thumbnail ("rasm yuklanmadi", "rasm mavjud emas"). */
.computer-screenshot {
  font-size: 12px;
  opacity: 0.75;
  text-align: center;
}

.computer-screenshot:empty { display: none; }

.computer-action-text {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.computer-countdown {
  font-size: 12px;
  opacity: 0.75;
}

.computer-buttons {
  display: flex;
  gap: 10px;
}

.computer-approve-btn,
.computer-deny-btn {
  flex: 1;
  min-height: 48px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.computer-approve-btn {
  border: none;
  background: #3ddc84;
  color: #0f1115;
}

.computer-deny-btn {
  border: 1px solid #3a3f4f;
  background: transparent;
  color: #e6e6e6;
}

.computer-approve-btn:disabled,
.computer-deny-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.computer-status {
  font-size: 13px;
  color: #ffd27a;
}

.computer-status:empty { display: none; }

/* Phone width: use the whole screen. */
@media (max-width: 640px) {
  body { align-items: stretch; }
  .chat-container {
    height: 100vh;
    height: 100dvh;
    max-width: none;
    border-radius: 0;
  }
  .computer-approval { margin: 8px 10px 0; }
}
