:root {
  --bg: #0f1419;
  --panel: #1a2029;
  --panel-2: #232b36;
  --border: #2d3744;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #1a7f5a;
  --accent-2: #22a06b;
  --user-bubble: #1f6feb;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: auto;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Layout: sidebar + area chat */
.layout {
  display: block;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  margin-left: 280px;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  flex-shrink: 0;
  background: #0c1116;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.sidebar-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.new-chat-full {
  margin: 12px 12px 8px;
  padding: 11px 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}

.new-chat-full:hover {
  filter: brightness(1.1);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}

.conv-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.conv-item.active {
  background: var(--panel-2);
  color: var(--text);
}

.conv-item .conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-title-input {
  flex: 1;
  background: #000;
  border: 1px solid var(--accent-2);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

.conv-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}

.conv-item:hover .conv-actions,
.conv-item.active .conv-actions {
  opacity: 1;
}

.conv-actions button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 5px;
  display: grid;
  place-items: center;
}

.conv-actions button:hover {
  color: var(--text);
  background: var(--border);
}

.conv-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.sidebar-foot {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clear-all {
  width: 100%;
  padding: 9px 12px;
  background: var(--panel-2);
  color: #e6a5a5;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.clear-all:hover {
  background: #3a1f1f;
  border-color: #7a3b3b;
  color: #ff9b9b;
}

.clear-all:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  flex-shrink: 0;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--accent-2);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.icon-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
}

.icon-btn:hover {
  background: var(--panel-2);
}

.topbar-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo,
.welcome-logo {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 10px;
}

.logo {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
}

.brand-text p {
  font-size: 12px;
  color: var(--muted);
}

.new-chat {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.new-chat:hover {
  background: var(--border);
}

/* Messages */
.messages {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg .avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.msg.user {
  flex-direction: row-reverse;
}

.msg.user .avatar {
  background: var(--user-bubble);
}

.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
  font-family: 'Consolas', monospace;
}

.bubble pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.bubble pre code {
  background: none;
  padding: 0;
}

/* Elemen Markdown kaya di dalam bubble */
.bubble > *:first-child {
  margin-top: 0;
}
.bubble > *:last-child {
  margin-bottom: 0;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4 {
  line-height: 1.3;
  margin: 12px 0 6px;
  font-weight: 700;
}
.bubble h1 {
  font-size: 18px;
}
.bubble h2 {
  font-size: 16px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.bubble h3 {
  font-size: 15px;
}
.bubble h4 {
  font-size: 14px;
}

.bubble p {
  margin: 6px 0;
}

.bubble ul,
.bubble ol {
  margin: 6px 0;
  padding-left: 22px;
}
.bubble li {
  margin: 2px 0;
}

.bubble blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--accent-2);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 0 8px 8px 0;
  color: #cdd6e0;
}

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.bubble a {
  color: #6cb2ff;
  text-decoration: underline;
}

.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}
.bubble th,
.bubble td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}
.bubble th {
  background: var(--panel);
  font-weight: 600;
}
.bubble tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.bubble .katex-display {
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Typing indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

/* Welcome */
.welcome {
  margin: auto;
  text-align: center;
  max-width: 560px;
  padding: 20px;
}

.welcome-logo {
  width: 56px;
  height: 56px;
  font-size: 20px;
  margin: 0 auto 16px;
}

.welcome h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--muted);
  margin-bottom: 20px;
}

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.chip:hover {
  border-color: var(--accent-2);
  background: var(--panel);
}

/* Config warning */
.config-warning {
  margin: 0 18px;
  padding: 10px 14px;
  background: #3a2a12;
  border: 1px solid #6b4a1f;
  border-radius: 10px;
  font-size: 13px;
  color: #f0c674;
}

.config-warning code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Composer */
.composer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

#chatForm {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 860px;
  margin: 0 auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
}

#chatForm:focus-within {
  border-color: var(--accent-2);
}

#input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  max-height: 160px;
  outline: none;
  padding: 6px 0;
}

#sendBtn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

#sendBtn:hover:not(:disabled) {
  background: var(--accent-2);
}

#sendBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}

@media (max-width: 760px) {
  .app {
    margin-left: 0;
  }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .icon-btn {
    display: grid;
    place-items: center;
  }
}

@media (max-width: 560px) {
  .suggestions {
    grid-template-columns: 1fr;
  }
}

/* Halaman login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #17303f 0%, var(--bg) 55%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 14px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
}

.login-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 22px;
}

.login-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 6px;
}

.login-card input {
  width: 100%;
  padding: 11px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent-2);
}

.login-error {
  margin-top: 14px;
  padding: 9px 12px;
  background: #3a1f1f;
  border: 1px solid #7a3b3b;
  border-radius: 9px;
  color: #ff9b9b;
  font-size: 13px;
}

.login-card button {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}

.login-card button:hover:not(:disabled) {
  filter: brightness(1.1);
}

.login-card button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
