@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg:           #080c14;
  --surface:      #0f1623;
  --surface-2:    #151e30;
  --border:       #1e2d47;
  --border-hover: #2e4270;
  --text:         #e2e8f8;
  --text-2:       #8a9bbf;
  --accent:       #5b8dee;
  --accent-dim:   rgba(91,141,238,.15);
  --accent-hover: #4a7de0;
  --green:        #34d399;
  --green-dim:    rgba(52,211,153,.12);
  --red:          #f87171;
  --red-dim:      rgba(248,113,113,.12);
  --radius-sm:    10px;
  --radius:       16px;
  --radius-lg:    22px;
  --shadow:       0 8px 40px rgba(0,0,0,.55);
}

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

body {
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* ── Login screen ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(91,141,238,.18) 0%, transparent 70%),
    var(--bg);
}

.login-box {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 38px;
  height: 38px;
  background: var(--accent-dim);
  border: 1px solid rgba(91,141,238,.3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.login-logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

.login-logo-text span { color: var(--accent); }

.login-box h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-box p.sub {
  color: var(--text-2);
  margin-bottom: 28px;
  font-size: .875rem;
}

.field { display: grid; gap: 6px; margin-bottom: 14px; }

.field label { font-weight: 600; font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }

.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 14px;
  font: inherit;
  font-size: .9rem;
  transition: border-color .15s;
  outline: none;
}

.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,238,.18); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: .875rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 8px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }

.btn-icon {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
  padding: 6px 8px;
  border-radius: 8px;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

.btn-danger-icon {
  background: transparent;
  border: none;
  color: var(--text-2);
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  transition: color .12s, background .12s;
  flex-shrink: 0;
}
.btn-danger-icon:hover { color: var(--red); background: var(--red-dim); }

.error-msg { color: var(--red); font-size: .825rem; margin-top: 10px; min-height: 1.2em; }

/* ── App layout ── */
.hidden { display: none !important; }

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 30px;
  height: 30px;
  background: var(--accent-dim);
  border: 1px solid rgba(91,141,238,.25);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: .95rem;
}
.sidebar-logo-text span { color: var(--accent); }

.sidebar-user {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(91,141,238,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  text-transform: uppercase;
}

.sidebar-user-name { font-weight: 600; font-size: .85rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 20px; }

.sidebar-section-title {
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 6px;
  margin-bottom: 6px;
}

/* Task list */
.task-add-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.task-add-row input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  font: inherit;
  font-size: .825rem;
  outline: none;
  min-width: 0;
}
.task-add-row input:focus { border-color: var(--accent); }
.task-add-row input::placeholder { color: var(--text-2); }

.task-add-btn {
  background: var(--accent-dim);
  border: 1px solid rgba(91,141,238,.25);
  color: var(--accent);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: background .12s;
}
.task-add-btn:hover { background: rgba(91,141,238,.28); }

.task-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.task-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border-radius: 8px;
  background: transparent;
  transition: background .12s;
}
.task-item:hover { background: var(--surface-2); }
.task-item:hover .btn-danger-icon { opacity: 1; }
.task-item .btn-danger-icon { opacity: 0; transition: opacity .12s; }

.task-check {
  appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--border-hover);
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
  background: transparent;
  position: relative;
  transition: background .12s, border-color .12s;
}
.task-check:checked {
  background: var(--green);
  border-color: var(--green);
}
.task-check:checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 0px;
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.task-text {
  flex: 1;
  font-size: .825rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-item.done .task-text { color: var(--text-2); text-decoration: line-through; }

/* History list */
.history-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background .12s;
}
.history-item:hover { background: var(--surface-2); }
.history-item:hover .btn-danger-icon { opacity: 1; }
.history-item .btn-danger-icon { opacity: 0; transition: opacity .12s; }

.history-load-btn {
  background: none;
  border: none;
  color: var(--text-2);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  text-align: left;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.history-load-btn:hover { color: var(--text); }
.history-load-btn::before { content: '💬'; font-size: 11px; flex-shrink: 0; }

.history-empty { font-size: .8rem; color: var(--text-2); padding: 6px 8px; }

/* ── Main chat area ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.main-topbar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
}

.topbar-title { font-weight: 700; font-size: .95rem; }
.topbar-sub { font-size: .78rem; color: var(--text-2); margin-top: 1px; }

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

/* Messages */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-2);
  text-align: center;
}

.msg-empty-icon {
  font-size: 40px;
  opacity: .4;
}

.msg-empty-title { font-weight: 600; font-size: 1rem; color: var(--text); }
.msg-empty-sub { font-size: .85rem; }

.bubble {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 78%;
}

.bubble.user { align-self: flex-end; align-items: flex-end; }
.bubble.assistant { align-self: flex-start; }

.bubble-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  padding: 0 4px;
}

.bubble-content {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .9rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.bubble.assistant .bubble-content {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.bubble.typing .bubble-content { display: flex; gap: 5px; align-items: center; padding: 14px 18px; }

.dot {
  width: 6px; height: 6px;
  background: var(--text-2);
  border-radius: 50%;
  animation: bounce .9s infinite;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Input area */
.input-area {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  transition: border-color .15s;
}
.input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,238,.12); }

.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: .9rem;
  resize: none;
  outline: none;
  max-height: 160px;
  line-height: 1.5;
}
.input-box textarea::placeholder { color: var(--text-2); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
  font-size: 16px;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Image support ── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  flex-shrink: 0;
  transition: color .15s, background .15s;
  align-self: flex-end;
  margin-bottom: 2px;
}
.attach-btn:hover { color: var(--accent); background: var(--accent-dim); }

.image-preview-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.preview-thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-remove {
  position: absolute;
  top: 3px; right: 3px;
  background: rgba(0,0,0,.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px; height: 18px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}
.preview-remove:hover { background: var(--red); }

.input-box.drag-over {
  border-color: var(--accent);
  background: rgba(91,141,238,.08);
}

.bubble-img {
  max-width: 320px;
  max-height: 260px;
  border-radius: 12px;
  display: block;
  object-fit: contain;
  border: 1px solid var(--border);
  margin-bottom: 4px;
}

.bubble.user .bubble-img { border-color: rgba(255,255,255,.2); }

/* ── Responsive ── */
@media (max-width: 680px) {
  .sidebar { display: none; }
  .bubble { max-width: 92%; }
  .bubble-img { max-width: 100%; }
}
