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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2d3148;
  --accent: #5b7cf6;
  --text: #e2e6f0;
  --muted: #7b82a0;
  --error: #e05260;
  --user-bg: #232740;
  --assistant-bg: #1a1d27;
  --radius: 8px;
}

html, body { height: 100%; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* --- Login --- */
#login-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100;
}
#login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; width: 340px; display: flex; flex-direction: column; gap: .8rem;
}
#login-box h2 { font-size: 1.2rem; }
#login-box p { color: var(--muted); font-size: .9rem; }
#login-box input {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: .55rem .75rem; font-size: .95rem; outline: none;
}
#login-box input:focus { border-color: var(--accent); }
#login-btn {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .6rem; font-size: .95rem; cursor: pointer;
}
#login-btn:hover { filter: brightness(1.1); }
.error { color: var(--error); font-size: .85rem; }

/* --- App layout --- */
#app { display: flex; height: 100vh; }

#sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
#sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: .95rem; }
#new-chat-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 50%;
  width: 26px; height: 26px; font-size: 1.1rem; cursor: pointer; line-height: 1;
}
#session-list { list-style: none; overflow-y: auto; flex: 1; padding: .4rem 0; }
/* --- Session list items with delete button --- */
#session-list li {
  padding: .6rem 1rem; font-size: .88rem; cursor: pointer; color: var(--muted);
  border-radius: var(--radius); margin: 0 .4rem;
  display: flex; align-items: center; gap: .3rem;
}
#session-list li:hover, #session-list li.active { background: var(--border); color: var(--text); }
.session-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.session-delete {
  flex-shrink: 0; background: none; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 0 .2rem; line-height: 1;
  opacity: 0; transition: opacity .15s;
}
#session-list li:hover .session-delete { opacity: .7; }
.session-delete:hover { color: var(--error) !important; opacity: 1 !important; }

/* --- Token/cost badge on messages --- */
.token-badge {
  display: block; margin-top: .4rem; font-size: .72rem; color: var(--muted);
  font-family: monospace;
}
#sidebar-footer { padding: .7rem 1rem; border-top: 1px solid var(--border); }
#logout-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius); padding: .4rem .8rem; font-size: .85rem; cursor: pointer; width: 100%;
}
#logout-btn:hover { border-color: var(--error); color: var(--error); }

/* --- Chat area --- */
#chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }

.msg { max-width: 820px; width: 100%; padding: .9rem 1.1rem; border-radius: var(--radius); font-size: .93rem; line-height: 1.55; }
.msg.user { background: var(--user-bg); align-self: flex-end; }
.msg.assistant { background: var(--assistant-bg); border: 1px solid var(--border); align-self: flex-start; }
.msg.thinking { color: var(--muted); font-style: italic; border: 1px dashed var(--border); }
.msg a { color: var(--accent); }
.msg pre { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: .6rem; overflow-x: auto; font-size: .85rem; margin: .4rem 0; }
.msg code { font-family: monospace; font-size: .88em; background: var(--bg); padding: 1px 4px; border-radius: 3px; }

/* --- Input form --- */
#input-form {
  display: flex; gap: .6rem; padding: .9rem 1.2rem;
  border-top: 1px solid var(--border); background: var(--surface);
}
#user-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: .6rem .85rem; font-size: .93rem; resize: none; outline: none;
  font-family: inherit;
}
#user-input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .6rem 1.2rem; font-size: .93rem; cursor: pointer; align-self: flex-end;
}
#send-btn:disabled { opacity: .5; cursor: default; }
#send-btn:not(:disabled):hover { filter: brightness(1.1); }

.hidden { display: none !important; }
