/* ================================================================
   AI Assistant — Modern ChatGPT-style Theme
   ================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --font-sans: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;

  --bg-body: #212121;
  --bg-sidebar: #171717;
  --bg-input: #2f2f2f;
  --bg-hover: #2a2a2a;
  --bg-active: #3a3a3a;
  --bg-elevated: #1e1e1e;
  --bg-user-bubble: #2f2f2f;
  --bg-code: #1a1a1a;

  --border: rgba(255,255,255,0.08);
  --border-input: rgba(255,255,255,0.12);
  --border-focus: rgba(255,255,255,0.28);

  --text-primary: #ececec;
  --text-secondary: #a0a0a0;
  --text-muted: #606060;

  --accent: #10a37f;      /* ChatGPT green */
  --accent-hover: #0d9070;
  --accent-soft: rgba(16,163,127,0.15);
  --accent-glow: rgba(16,163,127,0.25);

  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,0.12);
  --success: #22c55e;
  --success-soft: rgba(34,197,94,0.12);

  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 6px rgba(0,0,0,0.3);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --sidebar-width: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
::-webkit-scrollbar-track { background: transparent; }

button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ===================== LAYOUT ===================== */
.app-container { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  padding-top: var(--safe-top);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-chat-btn {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
}
.new-chat-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-input);
}
.new-chat-btn .new-chat-icon {
  width: 28px; height: 28px;
  background: var(--bg-active);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-hover);
  border-radius: var(--radius);
  padding: 8px 12px;
  border: 1px solid transparent;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.search-box:focus-within {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  width: 100%;
  font-size: 13px;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }

.session-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 12px 4px;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  -webkit-overflow-scrolling: touch;
}

.session-item {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 1px;
  transition: background 0.12s, color 0.12s;
  min-width: 0;
}
.session-item span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.session-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.session-item.active { background: var(--bg-active); color: var(--text-primary); }
.session-item .delete-icon {
  opacity: 0;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  padding: 4px 6px;
  border-radius: 6px;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.session-item:hover .delete-icon { opacity: 1; }
.session-item .delete-icon:hover { color: var(--danger); background: var(--danger-soft); }

.sidebar-footer {
  padding: 8px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-footer a,
.sidebar-footer .user-info {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  transition: background 0.12s, color 0.12s;
}
.sidebar-footer .user-info { color: var(--text-primary); font-weight: 500; }
.sidebar-footer a:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-avatar-mini {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* ---------- Main chat area ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
  position: relative;
  min-width: 0;
}

.topbar {
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-body);
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.model-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.menu-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Modern toggle switch */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-sidebar);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
  user-select: none;
}
.toggle-group:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text-primary);
}
.toggle-group input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 30px; height: 17px;
  background: var(--bg-active);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-group input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 13px; height: 13px;
  background: #fff;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left 0.2s, background 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-group input[type="checkbox"]:checked {
  background: var(--accent);
}
.toggle-group input[type="checkbox"]:checked::after {
  left: 15px;
}

/* ---------- Chat area ---------- */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 24px 20px;
}

/* ---------- Empty / Welcome state ---------- */
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 48px 24px;
}
.empty-logo {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--accent), #0d7a60);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  margin-bottom: 4px;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.empty-state h1 {
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  margin-top: 4px;
}
.empty-state p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.65;
  margin-bottom: 16px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 8px;
  width: 100%;
  max-width: 520px;
}
.suggestion-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-primary);
}
@media (max-width: 500px) { .suggestion-grid { grid-template-columns: 1fr; } }

/* ---------- Messages ---------- */
.msg-row {
  display: flex;
  gap: 14px;
  padding: 12px 0;
  align-items: flex-start;
  animation: msgIn 0.2s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-row.user .msg-avatar {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}
.msg-row.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--accent), #0a8060);
  color: #fff;
  font-size: 16px;
}

.msg-content { flex: 1; min-width: 0; }

/* User: bubble kanan */
.msg-row.user { flex-direction: row-reverse; }
.msg-row.user .msg-content { display: flex; flex-direction: column; align-items: flex-end; }
.msg-row.user .msg-role { display: none; }
.msg-row.user .msg-text {
  background: var(--bg-user-bubble);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
  padding: 10px 16px;
  max-width: 85%;
  display: inline-block;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* AI: teks penuh lebar */
.msg-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.msg-text {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-primary);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Markdown rendering */
.msg-text p { margin-bottom: 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text h1,.msg-text h2,.msg-text h3,.msg-text h4 {
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--text-primary);
  line-height: 1.3;
}
.msg-text h1 { font-size: 20px; }
.msg-text h2 { font-size: 17px; }
.msg-text h3 { font-size: 15px; }
.msg-text ul, .msg-text ol {
  padding-left: 20px;
  margin-bottom: 10px;
}
.msg-text li { margin-bottom: 4px; }
.msg-text blockquote {
  border-left: 3px solid var(--accent);
  margin: 10px 0;
  padding: 8px 14px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.msg-text strong { font-weight: 600; color: var(--text-primary); }
.msg-text em { font-style: italic; color: var(--text-secondary); }
.msg-text a { color: var(--accent); text-decoration: underline; text-decoration-color: transparent; }
.msg-text a:hover { text-decoration-color: var(--accent); }
.msg-text hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.msg-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13.5px;
}
.msg-text th, .msg-text td {
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  text-align: left;
}
.msg-text th {
  background: var(--bg-elevated);
  font-weight: 600;
}

/* Inline code */
.msg-text code {
  background: var(--bg-code);
  padding: 2px 7px;
  border-radius: 5px;
  font-family: "SF Mono", "JetBrains Mono", "Consolas", monospace;
  font-size: 13px;
  color: #e5c07b;
  border: 1px solid var(--border);
}

/* Code block */
.msg-text pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  overflow: hidden;
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  font-family: "SF Mono", monospace;
}
.code-block-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.code-block-copy:hover { background: var(--bg-hover); color: var(--text-primary); }
.msg-text pre code {
  display: block;
  background: transparent;
  border: none;
  padding: 14px;
  font-size: 13px;
  color: #abb2bf;
  overflow-x: auto;
  line-height: 1.6;
}

/* Typewriter cursor */
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s step-end infinite;
  border-radius: 1px;
}
@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Action buttons */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-row:hover .msg-actions,
.msg-row:focus-within .msg-actions { opacity: 1; }
.msg-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.msg-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-input);
}
.msg-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Sources */
.sources-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
}
.sources-box .sources-title {
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sources-box .source-item {
  color: var(--text-secondary);
  padding: 3px 0;
  overflow-wrap: anywhere;
}
.sources-box .source-item a { color: var(--accent); }
.sources-box .source-item a:hover { text-decoration: underline; }

/* Typing / thinking indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 6px 0;
  align-items: center;
}
.typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Input area ---------- */
.input-area {
  padding: 12px 20px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: var(--bg-body);
}
.input-inner { max-width: 720px; margin: 0 auto; }

.drop-zone {
  border: 2px dashed transparent;
  border-radius: var(--radius-xl);
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-xl);
  padding: 12px 12px 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-box:focus-within {
  border-color: rgba(255,255,255,0.22);
  box-shadow: 0 0 0 3px rgba(16,163,127,0.1), var(--shadow-sm);
}
.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  resize: none;
  font-size: 15px;
  line-height: 1.55;
  max-height: 200px;
  font-family: inherit;
  padding: 4px 0;
}
.input-box textarea::placeholder { color: var(--text-muted); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-active); color: var(--text-primary); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 2px 12px var(--accent-glow);
}
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled {
  background: var(--bg-active);
  color: var(--text-muted);
  cursor: not-allowed;
}

.attached-files { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.attached-file-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  display: flex; align-items: center; gap: 6px;
  color: var(--text-secondary);
  max-width: 220px;
}
.attached-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.input-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.5;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-input);
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn 0.22s ease;
  max-width: 320px;
  pointer-events: auto;
  line-height: 1.45;
}
.toast.error   { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
@keyframes toastIn {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-width: 220px; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    width: 80vw;
    max-width: 280px;
    min-width: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .chat-inner, .input-inner { max-width: 100%; padding: 16px 16px 16px; }
  .topbar { padding: 8px 12px; padding-top: calc(8px + var(--safe-top)); }
  .model-badge { font-size: 12px; }
  .input-area { padding: 8px 12px; padding-bottom: calc(10px + var(--safe-bottom)); }
  .msg-actions { opacity: 1; }
  .suggestion-grid { max-width: 100%; }
  .toggle-group span { display: none; }
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  backdrop-filter: blur(3px);
}
@media (max-width: 768px) {
  .sidebar-backdrop.show { display: block; }
}

@media (max-width: 420px) {
  .icon-btn { width: 32px; height: 32px; }
  .msg-row.user .msg-text { max-width: 92%; }
}
