/* ============================================================
   GotoAI 2.0 — "Daily Desk"
   Tokens
   ============================================================ */
:root {
  /* Palette — nền tối dịu (gần đen, không phải #000 để tránh lóa chữ) */
  --paper: #0E1513;        /* nền chính — đen ánh teal */
  --card: #171F1D;         /* thẻ / sidebar */
  --ink: #ECF2F0;          /* chữ chính — trắng ngà */
  --ink-soft: #9AAFA9;     /* chữ phụ */
  --line: #27332F;
  --brand: #2BB3A3;        /* teal sáng — nổi trên nền tối */
  --brand-strong: #6FD9CB; /* teal nhạt hơn — dùng cho chữ/hover */
  --brand-tint: #16302C;   /* nền teal mờ */
  --on-brand: #04201C;     /* chữ tối đặt TRÊN nền teal sáng */
  --warm: #F2A03D;         /* amber — dành riêng cho donate */
  --warm-tint: #2A2115;
  --on-warm: #331F04;      /* chữ tối đặt trên nền amber */
  --danger: #E06A60;

  /* Type */
  --font-display: "Be Vietnam Pro", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* Shape */
  --r-card: 16px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .45), 0 12px 32px rgba(0, 0, 0, .40);

  --sidebar-w: 288px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* Thanh cuộn đồng bộ giao diện tối */
* { scrollbar-width: thin; scrollbar-color: #33413D transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #33413D;
  border-radius: 999px;
  border: 2px solid var(--paper);
}
::-webkit-scrollbar-thumb:hover { background: #47605A; }

/* ============================================================
   Layout
   ============================================================ */
.app { display: flex; height: 100dvh; }
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.scroll-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--line);
  transition: margin-left .22s ease;
}
.sidebar.collapsed { margin-left: calc(0px - var(--sidebar-w)); }
.brand-actions { display: flex; gap: 2px; }
.fab-expand {
  position: absolute; top: 14px; left: 14px; z-index: 10;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}
.main { position: relative; }
.sidebar-top { padding: 18px 16px 10px; display: grid; gap: 12px; }
.brand-row { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: var(--on-brand);
  font-family: var(--font-display);
  font-weight: 800; font-size: 18px;
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 19px; letter-spacing: -.02em; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  color: var(--ink-soft);
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--brand-tint); color: var(--brand-strong); }

.lang-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.lang-btn {
  padding: 6px 0;
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600;
  color: var(--ink-soft);
  transition: background .15s ease, color .15s ease;
}
.lang-btn.active { background: var(--brand); color: var(--on-brand); }

.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-soft);
}
.search-box input { flex: 1; border: 0; background: none; outline: none; font-size: 13.5px; }

/* History */
.history { flex: 1; overflow-y: auto; padding: 6px 10px; }
.history-day {
  font-family: var(--font-mono);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-soft);
  padding: 12px 8px 4px;
}
.history-item {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  border-radius: 10px;
}
.history-item > .h-open {
  flex: 1; min-width: 0;
  text-align: left;
  padding: 8px 6px 8px 10px;
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 10px;
}
.history-item:hover, .history-item.active { background: var(--brand-tint); }
.history-item.active > .h-open { font-weight: 600; color: var(--brand-strong); }
.history-item > .h-del {
  flex-shrink: 0;
  width: 26px; height: 26px; margin-right: 4px;
  display: none; place-items: center;
  border-radius: 8px; color: var(--ink-soft);
}
.history-item:hover > .h-del { display: grid; }
.history-item > .h-del:hover { color: var(--danger); background: var(--paper); }
.history-empty { padding: 16px 10px; font-size: 13px; color: var(--ink-soft); font-style: italic; }

/* Sidebar bottom */
.sidebar-bottom { padding: 10px 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 2px; }
.side-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--ink-soft);
  text-decoration: none;
  text-align: left;
  transition: background .15s ease, color .15s ease;
}
.side-link:hover { background: var(--paper); color: var(--ink); }
.side-link.danger:hover { color: var(--danger); }
.support-link { color: var(--warm); font-weight: 600; }
.support-link:hover { background: var(--warm-tint); color: var(--warm); }
.side-foot { padding: 10px 10px 0; display: grid; }
.side-foot strong { font-family: var(--font-display); font-size: 13px; }
.side-foot span {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--brand);
}

/* ============================================================
   Topbar (mobile)
   ============================================================ */
.topbar {
  display: none;
  align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-family: var(--font-display); font-weight: 800; font-size: 17px; }

/* ============================================================
   Welcome — "Daily Desk"
   ============================================================ */
.welcome {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(32px, 8vh, 88px) 20px 24px;
}
.eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11.5px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--brand);
}
.greeting {
  margin: 0 0 22px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(26px, 4.5vw, 38px);
  letter-spacing: -.025em;
  line-height: 1.2;
}

.resume-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%;
  margin: 0 0 26px;
  padding: 14px 18px;
  background: var(--brand-tint);
  border: 1px solid transparent;
  border-radius: var(--r-card);
  color: var(--brand-strong);
  text-align: left;
  transition: border-color .15s ease, transform .15s ease;
}
.resume-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.resume-text { display: grid; min-width: 0; }
.resume-label { font-size: 12px; font-weight: 600; letter-spacing: .02em; opacity: .8; }
.resume-title {
  font-family: var(--font-display); font-weight: 700; font-size: 15.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.task-card {
  display: grid; gap: 4px;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  text-align: left;
  box-shadow: var(--shadow-1);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.task-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--brand); }
.task-card .t-head { display: flex; align-items: center; gap: 10px; }
.task-card .t-emoji { font-size: 19px; }
.task-card .t-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.task-card .t-hint { font-size: 12.5px; color: var(--ink-soft); }

.welcome-hint {
  margin: 22px 4px 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}

/* ============================================================
   Chat thread
   ============================================================ */
.chat { max-width: 760px; margin: 0 auto; padding: 24px 20px 36px; }
.messages { display: grid; gap: 18px; }

.msg { display: grid; gap: 6px; }
.msg-role {
  font-family: var(--font-mono);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft);
}
.msg.user .msg-role { text-align: right; }
.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--r-card);
  overflow-wrap: break-word;
}
.msg.user .msg-bubble {
  justify-self: end;
  max-width: 85%;
  background: var(--brand);
  color: var(--on-brand);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.msg.ai .msg-bubble {
  justify-self: start;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-1);
}
.msg.ai .msg-bubble.error { border-color: var(--danger); color: var(--danger); }

/* Markdown-lite inside AI bubbles */
.msg-bubble p { margin: 0 0 10px; } .msg-bubble p:last-child { margin: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: var(--font-display); letter-spacing: -.01em;
  margin: 14px 0 6px; line-height: 1.3;
}
.msg-bubble h1 { font-size: 18px; } .msg-bubble h2 { font-size: 16.5px; } .msg-bubble h3 { font-size: 15.5px; }
.msg-bubble ul, .msg-bubble ol { margin: 0 0 10px; padding-left: 22px; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble code {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 5px;
}
.msg-bubble pre {
  background: #0A100F; color: #DFF2EE;
  border: 1px solid var(--line);
  border-radius: 12px; padding: 14px;
  overflow-x: auto; margin: 0 0 10px;
}
.msg-bubble pre code { background: none; border: 0; padding: 0; color: inherit; }
.msg-bubble a { color: var(--brand-strong); }

/* Attachments shown in a user message */
.msg-files { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.msg-files img {
  max-width: 160px; max-height: 120px;
  border-radius: 10px; border: 1px solid var(--line);
  object-fit: cover;
}
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: 12.5px; color: var(--ink);
}

/* Message actions */
.msg-actions { display: flex; gap: 4px; }
.msg.ai .msg-actions { justify-self: start; }
.act-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 12px; color: var(--ink-soft);
  transition: background .15s ease, color .15s ease;
}
.act-btn:hover { background: var(--brand-tint); color: var(--brand-strong); }

/* Typing dots */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* Donate card — amber only lives here + support link */
.donate-card {
  margin-top: 6px;
  padding: 14px 18px;
  background: var(--warm-tint);
  border: 1px solid #4A3A1C;
  border-radius: var(--r-card);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.donate-card .d-text { flex: 1; min-width: 200px; font-size: 13.5px; }
.donate-card .d-text strong { font-family: var(--font-display); }
.donate-btn {
  padding: 8px 16px;
  background: var(--warm); color: var(--on-warm);
  border-radius: var(--r-pill);
  font-weight: 600; font-size: 13.5px;
  text-decoration: none;
  transition: filter .15s ease;
}
.donate-btn:hover { filter: brightness(1.07); }
.donate-later { font-size: 12.5px; color: var(--ink-soft); text-decoration: underline; }

/* ============================================================
   Composer
   ============================================================ */
.composer-wrap {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}
.attach-previews {
  max-width: 760px; margin: 0 auto 8px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.preview-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 6px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; font-size: 12.5px;
  box-shadow: var(--shadow-1);
}
.preview-chip img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.preview-chip .p-x {
  width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 50%; color: var(--ink-soft);
}
.preview-chip .p-x:hover { background: var(--paper); color: var(--danger); }

.composer {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-2);
}
.attach-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 13px;
  border-radius: var(--r-pill);
  background: var(--brand-tint);
  color: var(--brand-strong);
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
  transition: background .15s ease;
}
.attach-btn:hover { background: #1E3B36; }
.composer textarea {
  flex: 1;
  border: 0; outline: none; resize: none; background: none;
  padding: 9px 4px;
  max-height: 160px;
  line-height: 1.5;
}
.send-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--brand); color: var(--on-brand);
  flex-shrink: 0;
  transition: background .15s ease, opacity .15s ease;
}
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn:not(:disabled):hover { background: var(--brand-strong); }
.send-btn .ico-stop { display: none; }
.send-btn.streaming .ico-send { display: none; }
.send-btn.streaming .ico-stop { display: block; }
.send-btn.streaming { background: #3B4A46; color: var(--ink); }

.composer-note {
  max-width: 760px; margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px; color: var(--ink-soft);
}

/* ============================================================
   Responsive
   ============================================================ */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 40;
}
@media (max-width: 860px) {
  .topbar { display: flex; }
  .fab-expand { display: none; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-2);
    margin-left: 0 !important;
  }
  .sidebar.open { transform: translateX(0); }
  .cards { grid-template-columns: 1fr; }
  .attach-label { display: none; }
  .attach-btn { padding: 9px 11px; }
  .msg.user .msg-bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .scroll-area { scroll-behavior: auto; }
}
