/* AssistantAgent — Tokyonight theme (matching AgentGroup hedgehog.html) */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1a1b26;
  --bg2: #1f2335;
  --bg3: #24283b;
  --bg4: #292e42;
  --border: #3b4261;
  --text: #c0caf5;
  --text2: #565f89;
  --text3: #737aa2;
  --green: #9ece6a;
  --blue: #7aa2f7;
  --purple: #bb9af7;
  --yellow: #e0af68;
  --red: #f7768e;
  --cyan: #7dcfff;
  --orange: #ff9e64;
  --accent: #7aa2f7;
}

body {
  font-family: -apple-system, 'SF Pro', 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100vh;
}

/* ── Chat Panel (left) ── */
.chat-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;       /* constrain children so flex:1 + overflow-y works */
  min-height: 0;          /* fix flex shrink for scrollable child */
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.agent-info h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.agent-info .subtitle {
  font-size: 12px;
  color: var(--text3);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg3);
  color: var(--green);
  border: 1px solid rgba(158, 206, 106, 0.3);
}

.status-chip.busy {
  color: var(--yellow);
  border-color: rgba(224, 175, 104, 0.3);
}

/* Messages area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  min-height: 0;          /* critical: allow flex child to shrink and scroll */
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Message bubbles — hedgehog style */
.msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  max-width: 88%;
}

.msg.user {
  flex-direction: row-reverse;
  margin-left: auto;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.msg.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--blue), var(--purple));
}

.msg.user .msg-avatar {
  background: var(--bg4);
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-name {
  font-size: 11px;
  color: var(--text3);
  padding: 0 4px;
}

.msg.user .msg-name { text-align: right; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant .bubble {
  background: var(--bg3);
  border-radius: 4px 14px 14px 14px;
  color: var(--text);
}

.msg.user .bubble {
  background: var(--accent);
  border-radius: 14px 4px 14px 14px;
  color: #fff;
}

/* Tool events */
.tool-event {
  font-size: 12px;
  padding: 6px 10px;
  margin: 4px 0;
  border-radius: 8px;
  background: var(--bg2);
  border-left: 3px solid var(--cyan);
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-event.success { border-left-color: var(--green); color: var(--green); }
.tool-event.error { border-left-color: var(--red); color: var(--red); }

/* Screenshot preview */
.screenshot-wrap {
  margin: 6px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 400px;
}

.screenshot-wrap img { width: 100%; display: block; }

/* Typing indicator */
.typing {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text3);
  animation: typing 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Chat input */
.chat-input {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input input:focus { border-color: var(--accent); }
.chat-input input::placeholder { color: var(--text2); }

.chat-input button {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-input button:hover { opacity: 0.9; }
.chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Side Panel (right) ── */
.side-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  overflow-y: auto;
}

.side-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.side-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-bottom: 10px;
}

/* System status */
.sys-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
}

.sys-name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.green { background: var(--green); box-shadow: 0 0 4px var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }
.dot.gray { background: var(--text2); }

.sys-latency {
  font-size: 11px;
  color: var(--text2);
}

/* Current task */
.current-task-card {
  background: var(--bg3);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.current-task-card .label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text2);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.current-task-card .content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Task history */
.task-list {
  flex: 1;
  overflow-y: auto;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(59, 66, 97, 0.5);
  font-size: 13px;
}

.task-item:last-child { border-bottom: none; }

.task-icon { font-size: 13px; flex-shrink: 0; margin-top: 1px; }
.task-info { flex: 1; min-width: 0; }
.task-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.task-time { font-size: 11px; color: var(--text2); margin-top: 1px; }
.task-tools { font-size: 11px; color: var(--cyan); margin-top: 1px; }

.empty {
  color: var(--text2);
  font-size: 12px;
  text-align: center;
  padding: 16px 0;
}

/* ── Header buttons ── */
.header-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.header-btn:hover { color: var(--text); border-color: var(--text3); }
.logout-btn:hover { color: var(--red); border-color: var(--red); }

/* ── Login Screen ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
}

.login-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 600;
  color: #fff;
  margin: 0 auto 16px;
}

.login-card h2 {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.login-card input:focus { border-color: var(--accent); }
.login-card input::placeholder { color: var(--text2); }

.login-card button[type="submit"], #login-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}

.login-card button:hover { opacity: 0.9; }

.login-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  width: 320px;
}

.modal-card h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 16px;
}

.modal-card input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
}

.modal-card input:focus { border-color: var(--accent); }
.modal-card input::placeholder { color: var(--text2); }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-secondary {
  flex: 1;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Calendar Widget (monthly grid) ── */
.cal-section {
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.cal-header h3 { margin-bottom: 0; }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-nav-btn:hover { color: var(--text); border-color: var(--text3); }

.cal-today-btn {
  width: auto;
  padding: 0 8px;
  font-size: 11px;
}

.cal-nav-label {
  font-size: 11px;
  color: var(--text2);
  min-width: 70px;
  text-align: center;
}

/* Month grid */
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 10px;
  color: var(--text2);
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.cal-cell {
  text-align: center;
  padding: 5px 0;
  font-size: 12px;
  color: var(--text3);
  cursor: pointer;
  border-radius: 6px;
  position: relative;
  transition: all 0.15s;
}

.cal-cell:hover { background: var(--bg3); color: var(--text); }
.cal-empty { cursor: default; }
.cal-empty:hover { background: none; }

.cal-cell-today {
  color: var(--blue);
  font-weight: 700;
}

.cal-cell-selected {
  background: var(--blue) !important;
  color: #fff !important;
  font-weight: 600;
}

.cal-cell-has-event { color: var(--text); }

.cal-dot {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--purple);
}

.cal-cell-today .cal-dot { background: var(--blue); }
.cal-cell-selected .cal-dot { background: #fff; }

/* Day events below grid */
.cal-day-events {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  flex: 1;
  overflow-y: auto;
}

.cal-day-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 4px;
}

.cal-event {
  padding: 5px 8px;
  margin: 3px 0;
  border-radius: 6px;
  background: var(--bg3);
  border-left: 3px solid var(--purple);
  font-size: 12px;
}

.cal-event-time {
  font-size: 11px;
  color: var(--text3);
}

.cal-event-title {
  color: var(--text);
  font-weight: 500;
  margin-top: 1px;
}

.cal-event-loc {
  font-size: 10px;
  color: var(--text2);
  margin-top: 1px;
}

/* ── Todo Widget ── */
.todo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.todo-header h3 { margin-bottom: 0; }

.todo-list {
  flex: 1;
  overflow-y: auto;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(59, 66, 97, 0.4);
  font-size: 13px;
}

.todo-item:last-child { border-bottom: none; }

.todo-check {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.todo-check:checked {
  background: var(--green);
  border-color: var(--green);
}

.todo-check:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.todo-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  line-height: 1.3;
}

.todo-done .todo-text {
  text-decoration: line-through;
  color: var(--text2);
}

.todo-del {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.todo-item:hover .todo-del { opacity: 1; }
.todo-del:hover { color: var(--red); }

/* ── Mobile bottom tab bar (hidden on desktop) ── */
.mobile-tabs {
  display: none;
}

/* ── Responsive ── */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr 260px; }
}

@media (max-width: 768px) {
  /* Full-screen tabs layout */
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    grid-template-columns: unset;
  }

  /* Chat = full screen by default */
  .chat-panel {
    flex: 1;
    border-right: none;
    min-height: 0;
  }

  /* Side panel = full screen, hidden by default (tab switches) */
  .side-panel {
    display: none;
    flex: 1;
    border-right: none;
    overflow-y: auto;
  }

  .side-panel.mobile-visible {
    display: flex;
    flex-direction: column;
  }

  /* When side panel visible, hide chat */
  .chat-panel.mobile-hidden {
    display: none;
  }

  /* Calendar section: show specific one based on tab */
  .cal-section { display: none; }
  .todo-section { display: none; }
  .side-panel.show-calendar .cal-section { display: flex; flex: 1; max-height: none; }
  .side-panel.show-todo .todo-section { display: flex; flex: 1; }

  .cal-section { max-height: none; }

  /* Bottom tab bar */
  .mobile-tabs {
    display: flex;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  .mobile-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text2);
    font-size: 12px;
    padding: 6px 0;
    cursor: pointer;
    text-align: center;
  }

  .mobile-tab.active {
    color: var(--blue);
    font-weight: 600;
  }

  /* Header compact on mobile */
  .chat-header { padding: 8px 12px; }
  .agent-info h2 { font-size: 14px; }
  .avatar { width: 32px; height: 32px; font-size: 16px; }
  .chat-input { padding: 8px 10px; }
  .chat-input input { padding: 8px 12px; font-size: 13px; }
  .chat-input button { padding: 8px 14px; font-size: 13px; }

  /* Login card responsive */
  .login-card { width: 90vw; max-width: 340px; padding: 30px 24px; }
}
