*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Auth */
.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--dialog);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.auth-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted-foreground);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12px;
  color: var(--muted-foreground);
}

.input,
.textarea,
.select {
  width: 100%;
  background: var(--secondary);
  border: 1px solid var(--input);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 500;
  font-size: 13px;
  transition: background 120ms ease, opacity 120ms ease;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--foreground);
}

.btn-ghost:hover {
  background: var(--accent);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
}

.btn-icon:hover {
  background: var(--sidebar-accent);
}

.btn-danger {
  background: var(--destructive-fill);
  color: var(--destructive-foreground);
}

/* 3-pane Rakazo shell */
.shell {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--background);
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  transition: width 160ms ease;
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
  border-right: 0;
}

.sidebar-top {
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.space-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.space-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.space-btn:hover {
  background: var(--sidebar-accent);
}

.space-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-box {
  width: 100%;
  background: var(--secondary);
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  outline: none;
}

.search-box::placeholder {
  color: var(--faint-foreground);
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  padding: 4px 12px 8px;
}

.sidebar-actions .btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
}

.roster {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.roster-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint-foreground);
  padding: 10px 8px 4px;
}

.roster-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  text-align: left;
}

.roster-item:hover {
  background: var(--sidebar-accent);
}

.roster-item.active {
  background: var(--accent);
}

.roster-meta {
  flex: 1;
  min-width: 0;
}

.roster-name {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-sub {
  font-size: 11.5px;
  color: var(--faint-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--unread);
  flex-shrink: 0;
}

.sidebar-foot {
  padding: 8px 10px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

/* Square Bot Avatar matching Rakazo */
.avatar {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar.lg {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.working-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--working-dot);
  border: 2px solid var(--background);
  animation: rkPulse 1.3s ease-in-out infinite;
}

@keyframes rkPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Center chat */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--background);
}

.chat-topbar {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px 4px 6px;
}

.chat-pill-title {
  font-weight: 600;
  font-size: 13.5px;
}

.chat-pill-model {
  font-size: 11.5px;
  color: var(--faint-foreground);
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.transcript-inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-row.user {
  align-items: flex-end;
}

.msg-user-bubble {
  max-width: min(82%, 580px);
  background: var(--chat-user);
  color: var(--chat-user-foreground);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-assistant {
  max-width: 100%;
  color: var(--foreground);
  line-height: 1.55;
  word-break: break-word;
}

.msg-assistant pre {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12.5px;
}

.msg-assistant code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.thinking-box {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted-foreground);
}

.thinking-box summary {
  cursor: pointer;
  font-weight: 500;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  color: var(--muted-foreground);
  margin: 2px 4px 2px 0;
}

.composer-wrap {
  padding: 10px 16px 16px;
}

.composer {
  max-width: 760px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.composer textarea {
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 180px;
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.composer-hint {
  font-size: 11.5px;
  color: var(--faint-foreground);
}

/* Right SidePanel */
.sidepanel {
  width: 380px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--background);
  display: flex;
  flex-direction: column;
}

.sidepanel.hidden {
  display: none;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--foreground);
  border-bottom-color: var(--foreground);
}

.sidepanel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  margin-bottom: 8px;
}

.terminal-out {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 40;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--dialog);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 20px;
  max-height: 86vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.muted {
  color: var(--muted-foreground);
  font-size: 12.5px;
}

.err-text {
  color: var(--destructive);
  font-size: 12.5px;
}

.badge-ok {
  color: var(--success);
  font-size: 11.5px;
  font-weight: 600;
}

@media (max-width: 960px) {
  .sidepanel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: min(92vw, 380px);
  }
}
