:root {
  --navy: #1b2a4a;
  --navy-light: #2c3e63;
  --accent: #2f6fed;
  --accent-dark: #2459c4;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e2e7f0;
  --text: #1f2937;
  --text-light: #6b7280;
  --bubble-user: #2f6fed;
  --bubble-jackson: #ffffff;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 4px 12px rgba(16, 24, 40, 0.06);
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Lock screen ---------- */

#lock-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-light) 100%);
  z-index: 100;
}

.lock-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 44px 48px 28px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  width: min(380px, 90vw);
}

.lock-avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 14px;
  background: var(--navy);
  color: white;
  font-size: 30px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-card h1 {
  font-size: 26px;
  color: var(--navy);
  margin: 16px 0 2px;
  letter-spacing: -0.02em;
}

.lock-subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 26px;
}

#lock-form input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#lock-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

#lock-form button {
  margin-top: 12px;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#lock-form button:hover { background: var(--accent-dark); }

.lock-error {
  color: #d92d20;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

.lock-gift {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-light);
  font-size: 12.5px;
  font-style: italic;
}

/* ---------- Layout ---------- */

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

/* ---------- Sidebar ---------- */

#sidebar {
  width: 270px;
  background: var(--navy);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 18px;
}

.sidebar-logo {
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

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

#lock-btn,
#password-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  border-radius: 7px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s;
}

#lock-btn:hover,
#password-btn:hover { background: rgba(255, 255, 255, 0.1); }

#new-chat-btn {
  border: none;
  border-radius: 8px;
  padding: 11px;
  background: var(--accent);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  transition: background 0.15s;
}

#new-chat-btn:hover { background: var(--accent-dark); }

#chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.15s;
}

.chat-item:hover { background: rgba(255, 255, 255, 0.08); }

.chat-item.active {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}

.chat-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item .delete {
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-item:hover .delete { opacity: 0.7; }
.chat-item .delete:hover { opacity: 1; }

.chat-item .rename {
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
  margin-right: 4px;
}

.chat-item:hover .rename { opacity: 0.7; }
.chat-item .rename:hover { opacity: 1; }

.chat-item .title-edit {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  color: white;
  font: inherit;
  padding: 2px 6px;
  outline: none;
}

/* ---------- Chat area ---------- */

#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 10% 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#reminder-banner {
  margin: 14px 10% 0;
  padding: 12px 16px;
  background: #fff8e6;
  border: 1px solid #f0d692;
  border-left: 4px solid #d9a514;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #6b5510;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

#reminder-banner .dismiss {
  border: none;
  background: none;
  color: #b08c1a;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px;
}

.welcome {
  margin: auto;
  text-align: center;
  color: var(--text-light);
  max-width: 420px;
}

.welcome-avatar {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 12px;
  background: var(--navy);
  color: white;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome h2 {
  color: var(--navy);
  margin: 14px 0 6px;
  font-size: 20px;
}

.welcome p { font-size: 14px; line-height: 1.5; }

.msg {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rise 0.2s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-jackson);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  white-space: normal; /* structure comes from rendered markdown */
}

.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }

.msg.assistant h3,
.msg.assistant h4,
.msg.assistant h5 {
  color: var(--navy);
  margin: 12px 0 6px;
  font-size: 15px;
}

.msg.assistant h3:first-child,
.msg.assistant h4:first-child,
.msg.assistant h5:first-child { margin-top: 0; }

.msg.assistant ul,
.msg.assistant ol {
  margin: 4px 0 10px;
  padding-left: 22px;
}

.msg.assistant li { margin-bottom: 4px; }

.msg.assistant code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: Consolas, monospace;
}

.msg.assistant pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0 10px;
  overflow-x: auto;
}

.msg.assistant pre code {
  border: none;
  background: none;
  padding: 0;
}

.msg.assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.msg.assistant a { color: var(--accent); }

.msg.typing {
  color: var(--text-light);
  font-style: italic;
}

/* ---------- Input ---------- */

#chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 10% 22px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  padding: 13px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14.5px;
  outline: none;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

#send-btn {
  border: none;
  border-radius: 10px;
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: white;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s;
}

#send-btn:hover { background: var(--accent-dark); }

#send-btn:disabled { opacity: 0.5; cursor: wait; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 28px 32px;
  width: min(360px, 90vw);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  animation: rise 0.2s ease-out;
}

.modal-card h2 {
  color: var(--navy);
  font-size: 18px;
  margin-bottom: 18px;
}

.modal-card input {
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-buttons button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-soft {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border) !important;
}

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

.modal-message {
  text-align: center;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
  color: #d92d20;
}

.modal-message.success { color: #079455; }
