* { box-sizing: border-box; }

.hidden { display: none !important; }

.auth-gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-box {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-box h1 {
  margin: 0;
  font-size: 20px;
  text-align: center;
}

.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--text);
}

.auth-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-panel input {
  width: 100%;
}

.auth-actions {
  display: flex;
  gap: 10px;
}

.auth-actions button {
  flex: 1;
}

.small {
  font-size: 11px;
  margin: 0;
}

.error-text {
  color: var(--danger);
  min-height: 16px;
  margin: 0;
  font-size: 13px;
}

:root {
  color-scheme: dark;
  --bg: #0e0f13;
  --panel: #161821;
  --border: #2a2d3a;
  --text: #e6e6ef;
  --muted: #8b8fa3;
  --accent: #6c7bff;
  --danger: #e5566a;
  --user: #232640;
  --assistant: #1a1c26;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
}

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 15px;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.sidebar-header button {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
}

.agent-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.agent-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}

.agent-item:hover {
  background: var(--panel);
}

.agent-item.active {
  background: var(--user);
  border: 1px solid var(--accent);
}

.agent-item .kind {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sites-btn {
  margin: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  text-align: left;
  font-size: 13.5px;
}

.admin-link {
  display: block;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  box-sizing: border-box;
}

.sites-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 12px 0;
}

.site-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.site-row a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13.5px;
  word-break: break-all;
}

.site-row a:hover {
  text-decoration: underline;
}

.active-site-bar {
  padding: 8px 20px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.active-site-bar a {
  color: var(--accent);
  text-decoration: none;
}

.active-site-bar a:hover {
  text-decoration: underline;
}

.deploy-wrap {
  margin-top: 10px;
}

.deploy-btn {
  border-color: var(--accent);
  color: var(--accent);
}

.deploy-link {
  display: inline-block;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 12px;
}

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

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

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

header h2 {
  font-size: 16px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: none;
  padding: 0 10px;
  height: 34px;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
}

.muted {
  color: var(--muted);
  font-size: 12.5px;
  margin: 2px 0 0;
}

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

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--border);
}

.msg.error {
  align-self: flex-start;
  background: #3a1c22;
  border: 1px solid #6b2733;
  color: #ffb4bd;
}

.msg pre {
  background: #090a0d;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}

.msg code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }

.msg-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.msg-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
}

.msg pre {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg pre:hover .copy-btn {
  opacity: 1;
}

form#form {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}

input, select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

textarea:focus, input:focus, select:focus {
  outline: 2px solid var(--accent);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 20px;
  font-size: 14px;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  font-size: 13px;
}

button.ghost.danger {
  color: var(--danger);
  border-color: #4a2530;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.typing {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

/* Dialog */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: 480px;
  max-width: 90vw;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

#agentForm {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#agentForm h3 {
  margin: 0 0 4px;
}

#agentForm label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* --- Mobile (iOS/Android) --- */
@media (max-width: 768px) {
  .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 320px;
    background: var(--bg);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    padding-top: env(safe-area-inset-top);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.open {
    display: block;
  }

  header {
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  header h2 {
    font-size: 15px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions button.ghost {
    padding: 6px 10px;
    font-size: 12px;
  }

  #chat {
    padding: 14px;
  }

  .msg {
    max-width: 92%;
    font-size: 15px;
  }

  form#form {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  textarea {
    font-size: 16px; /* evite le zoom auto au focus sur iOS Safari */
  }

  button[type="submit"] {
    padding: 0 16px;
  }

  dialog {
    width: 92vw;
  }
}
