/* =========================================================
   AXON AI — base.css
   Design tokens, layout shell, sidebar, topbar, buttons
   ========================================================= */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1b26;
  --muted: #6f6b7d;
  --border: #ececf1;
  --border-strong: #dedbe8;
  --user: #edf3ff;
  --purple: #2585ed;
  --purple-strong: #1769c2;
  --pink: #8bd5ff;
  --hover: #edf6ff;
  --shadow: 0 8px 30px rgba(30, 20, 60, .08);
  --shadow-lg: 0 18px 50px rgba(30, 20, 60, .16);
  --danger: #e5484d;
  --ok: #2fa36b;
  --warn: #d99022;
  --radius: 14px;
  --chat-font: 16px;
  --chat-line: 1.72;
  --topbar-h: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html.dark-preload,
body.dark {
  --bg: #14121b;
  --surface: #1d1a26;
  --surface-2: #1a1722;
  --text: #f3f0f8;
  --muted: #a9a3b8;
  --border: #322d3d;
  --border-strong: #443c55;
  --user: #2f2942;
  --purple: #65baff;
  --purple-strong: #91d0ff;
  --pink: #54c5ed;
  --hover: #202f40;
  --shadow: 0 8px 30px rgba(0, 0, 0, .3);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .45);
  --danger: #ff6b70;
  --ok: #4ecf8d;
  --warn: #e6b45c;
}

/* Text size preference */
body[data-text-size="sm"] { --chat-font: 14.5px; }
body[data-text-size="md"] { --chat-font: 16px; }
body[data-text-size="lg"] { --chat-font: 17.5px; }
body[data-text-size="xl"] { --chat-font: 19px; }

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

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

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.hidden { display: none !important; }

.app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ================= SIDEBAR ================= */

.sidebar {
  width: 288px;
  height: 100%;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 40;
  transform: translateX(-102%);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  padding-top: calc(16px + var(--safe-top));
}

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

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.sidebar-top-actions { display: flex; gap: 2px; }

.brand-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px 4px 2px;
  border-radius: 12px;
}

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

.brand-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  border-radius: 9px;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1.6px;
  background: linear-gradient(100deg, #2585ed, #8bd5ff);
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
}

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  cursor: pointer;
}

.sidebar-account:hover { border-color: var(--border-strong); }

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--hover);
}

.sidebar-account-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.sidebar-account-text span {
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-account-text small {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, transform .18s, color .18s;
}

.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.new-chat {
  width: 100%;
  height: 46px;
  border: 1px solid #cfe8ff;
  border-radius: 13px;
  background: linear-gradient(110deg, #eaf5ff, #f5fbff);
  color: var(--purple-strong);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  font-weight: 650;
  font-size: 14.5px;
  transition: transform .18s, box-shadow .18s;
}

body.dark .new-chat {
  background: linear-gradient(110deg, #12345a, #17466b);
  border-color: #28618e;
  color: #d5edff;
}

.new-chat:active { transform: scale(.98); }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 0 6px 0 10px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.sidebar-search:focus-within { border-color: var(--purple); }

.sidebar-search .search-icon {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.sidebar-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13.5px;
}

.history-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 0 8px;
  -webkit-overflow-scrolling: touch;
}

.history-empty {
  padding: 18px 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 750;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 14px 8px 7px;
}

.section-label svg { width: 13px; height: 13px; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  transition: background .18s;
  touch-action: pan-y;
}

.history-item:hover,
.history-item.active { background: var(--hover); }

.history-item.active { font-weight: 650; }

.history-item .hi-icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex-shrink: 0;
}

.history-item .hi-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .hi-more {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--muted);
  opacity: .75;
}

.history-item .hi-more:hover { background: var(--border); }
.history-item .hi-more svg { width: 15px; height: 15px; }

.history-item mark {
  background: rgba(118, 85, 232, .22);
  color: inherit;
  border-radius: 3px;
}

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 10px;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  transition: background .18s;
}

.nav-item:hover { background: var(--hover); }
.nav-item svg { width: 19px; height: 19px; color: var(--muted); }

/* ================= MAIN ================= */

.main {
  width: 100%;
  height: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) 12px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 5;
  gap: 8px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-title {
  font-size: 14.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

.topbar-tag {
  font-size: 10px;
  letter-spacing: 1px;
  font-weight: 700;
  color: var(--purple-strong);
  background: rgba(118, 85, 232, .12);
  padding: 5px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ================= OVERLAYS ================= */

.sidebar-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(16, 12, 28, .38);
  backdrop-filter: blur(1px);
  animation: fadeIn .2s ease both;
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(16, 12, 28, .42);
  animation: fadeIn .18s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.action-menu {
  position: fixed;
  z-index: 100002;
  min-width: 200px;
  max-width: min(280px, 92vw);
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: menuIn .16s ease both;
}

@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.action-menu button {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 9px;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}

.action-menu button:hover { background: var(--hover); }
.action-menu button svg { width: 17px; height: 17px; color: var(--muted); }
.action-menu button.danger { color: var(--danger); }
.action-menu button.danger svg { color: var(--danger); }
.action-menu .menu-sep {
  height: 1px;
  background: var(--border);
  margin: 5px 6px;
}

@keyframes confirmDialogIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(.98);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.confirm-card {
  position: fixed;
  z-index: 100001;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100vw - 40px));
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 13px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: confirmDialogIn .18s ease both;
}

.confirm-card h3 {
  font-size: 15.5px;
  margin-bottom: 7px;
}

.confirm-card p {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 11px 17px;
  border-radius: 22px;
  background: #f1f1f1;
  color: #111111;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease both;
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ================= BUTTONS ================= */

.btn {
  min-height: 42px;
  padding: 0 15px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  font-size: 14px;
  transition: transform .16s, filter .16s, background .16s, opacity .16s;
}

.btn:active { transform: scale(.98); }
.btn svg { width: 17px; height: 17px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(110deg, #2585ed, #8bd5ff);
  color: #fff;
}

.btn.primary:hover { filter: brightness(1.05); }

.btn.ghost {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

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

.btn.danger {
  background: rgba(229, 72, 77, .1);
  color: var(--danger);
  border: 1px solid rgba(229, 72, 77, .3);
}

.btn.danger:hover { background: rgba(229, 72, 77, .16); }

.link-btn {
  color: var(--purple-strong);
  font-size: 13.5px;
  font-weight: 650;
  padding: 4px 2px;
  border-radius: 6px;
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}



/* Sidebar-local Rename/Delete confirmations above Recent Chats. */
.history-dialog-slot { padding: 8px 0 12px; }
.confirm-card.sidebar-inline {
  position: relative;
  z-index: 1;
  left: auto;
  top: auto;
  transform: none;
  width: 100%;
  max-width: none;
  padding: 14px 12px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: menuIn .18s ease both;
}
.confirm-card.sidebar-inline h3 { font-size: 14.5px; }
.confirm-card.sidebar-inline p { font-size: 12.5px; overflow-wrap: anywhere; }
.confirm-card.sidebar-inline .confirm-actions { gap: 7px; margin-top: 12px; }
.confirm-card.sidebar-inline .confirm-actions .btn { min-height: 36px; padding: 7px 11px; }
