/* ================================================================
   BBGTK SULSEL CHATBOT — Main Stylesheet
   Tema: Formal tapi Modern (Pemerintahan + Teknologi)
   ================================================================ */

:root {
  --primary:       #1B4F8A;
  --primary-light: #2563AA;
  --primary-dark:  #163E6E;
  --accent:        #E8A020;
  --accent-light:  #F5C060;
  --bg:            #ffffff;
  --surface:       #F5F7FB;
  --surface2:      #EEF2F8;
  --border:        rgba(27,79,138,0.12);
  --border-strong: rgba(27,79,138,0.22);
  --text:          #1a2535;
  --text2:         #4A5568;
  --muted:         #8A95A8;
  --success:       #10B981;
  --error:         #EF4444;
  --warning:       #F59E0B;
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --sidebar-w:     260px;
}

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

html, body {
  height: 100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-body {
  background: linear-gradient(150deg, #EEF4FC 0%, #F5F7FB 60%, #EDF5FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  flex-direction: column;
  gap: 20px;
}

.login-wrapper { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }

.login-card {
  background: var(--bg);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 40px rgba(27,79,138,0.10);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}


.login-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 26px; font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13px; color: var(--text2);
  line-height: 1.6; margin-bottom: 24px;
}

.login-features {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 24px;
}

.feature-item {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text2);
}

.feature-icon { font-size: 16px; flex-shrink: 0; }

.btn-google {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; width: 100%;
  padding: 12px 20px;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500; color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: all 0.18s;
}

.btn-google:hover {
  background: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
  box-shadow: 0 2px 12px rgba(27,79,138,0.12);
}

.login-note {
  margin-top: 16px;
  font-size: 11.5px; color: var(--muted);
  text-align: center; line-height: 1.6;
}

.login-footer {
  font-size: 12px; color: var(--muted); text-align: center;
}

/* ================================================================
   MAIN APP LAYOUT (Chat)
   ================================================================ */
body:not(.login-body):not(.admin-body) {
  display: flex; overflow: hidden; height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--primary-dark);
  display: flex; flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-icon {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.15);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.brand-name { font-size: 14px; font-weight: 600; color: #fff; }
.brand-sub  { font-size: 10px; color: rgba(255,255,255,0.55); margin-top: 1px; }

.sidebar-body { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 10px; }
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.btn-new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: #fff;
  text-decoration: none; cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-new-chat:hover { background: rgba(255,255,255,0.18); text-decoration: none; color: #fff; }

.history-section { flex: 1; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.history-label { font-size: 10.5px; color: rgba(255,255,255,0.45); text-transform: uppercase; letter-spacing: 0.8px; padding: 4px 6px; }

.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.12s;
  cursor: pointer;
}

.history-item:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.history-item.active { background: rgba(255,255,255,0.14); }

.history-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.history-title { font-size: 12.5px; color: rgba(255,255,255,0.8); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-time { font-size: 10px; color: #93c5fd; }

.history-delete {
  flex-shrink: 0; opacity: 0;
  background: none; border: none;
  color: rgba(255,255,255,0.5);
  padding: 2px 4px; border-radius: 4px;
  transition: opacity 0.12s, color 0.12s;
}

.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: #fff; }

.history-empty { font-size: 12px; color: rgba(255,255,255,0.3); padding: 8px 6px; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  display: flex; flex-direction: column; gap: 6px;
}

.sidebar-menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px; color: rgba(255,255,255,0.7);
  text-decoration: none;
  transition: background 0.12s;
}

.sidebar-menu-item:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }

.user-info { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%; object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-placeholder {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.user-detail { flex: 1; min-width: 0; }
.user-name  { font-size: 12.5px; color: #fff; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 10.5px; color: rgba(255,255,255,0.45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.logout-btn { color: rgba(255,255,255,0.45); flex-shrink: 0; transition: color 0.12s; }
.logout-btn:hover { color: #fff; text-decoration: none; }

/* MAIN CONTENT */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; height: 100vh; overflow: hidden;
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  background: none; border: none;
  color: var(--text2); padding: 4px;
  border-radius: 6px;
}

.sidebar-toggle:hover { background: var(--surface); }

.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }

/* ================================================================
   CHAT LAYOUT
   ================================================================ */
.chat-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.messages-area {
  flex: 1; overflow-y: auto;
  padding: 24px 20px;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }

.messages-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

/* WELCOME STATE */
.welcome-screen { text-align: center; padding: 40px 20px; }
.welcome-icon {
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}

.welcome-title { font-family: 'Lora', Georgia, serif; font-size: 22px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.welcome-sub { font-size: 14px; color: var(--text2); margin-bottom: 28px; line-height: 1.6; }

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px; max-width: 680px; margin: 0 auto;
}

.suggestion-btn {
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px; color: var(--text2);
  text-align: left; cursor: pointer;
  transition: all 0.15s; line-height: 1.4;
}

.suggestion-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #EEF4FC;
}

/* MESSAGE ROWS */
.msg-row { display: flex; gap: 10px; align-items: flex-end; animation: msg-in 0.2s ease; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar-bot {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.msg-avatar-user {
  width: 30px; height: 30px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
}

.msg-avatar-user img { width: 100%; height: 100%; object-fit: cover; }

.msg-bubble { max-width: min(72%, 560px); }

.msg-row.user .msg-bubble { align-items: flex-end; }

.msg-content {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px; line-height: 1.65; color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg-row.bot .msg-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

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

.msg-row.user .msg-content strong { color: rgba(255,255,255,0.9); }
.msg-row.bot .msg-content strong { color: var(--text); font-weight: 600; }

.msg-content ul, .msg-content ol { padding-left: 20px; margin: 6px 0 4px; }
.msg-content li { margin: 3px 0; line-height: 1.6; }
.msg-content p { margin: 4px 0; }

.msg-link { color: #2563AA; text-decoration: underline; word-break: break-all; }
.msg-link:hover { color: #1B4F8A; }
.msg-row.user .msg-content .msg-link { color: rgba(255,255,255,0.9); }
.msg-row.user .msg-content .msg-link:hover { color: #fff; }

.msg-table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.msg-table th, .msg-table td { border: 1px solid var(--border-strong); padding: 6px 10px; text-align: left; }
.msg-table th { background: var(--surface2); font-weight: 600; color: var(--primary); }
.msg-table tr:nth-child(even) td { background: var(--surface); }

.msg-meta { display: flex; align-items: center; gap: 8px; padding: 4px 4px 0; }
.msg-row.user .msg-meta { justify-content: flex-end; }

.date-separator {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 8px;
  color: var(--muted); font-size: 11px;
}
.date-separator::before, .date-separator::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.date-separator span { white-space: nowrap; }

.msg-time { font-size: 10.5px; color: var(--muted); }

.feedback-btns { display: flex; gap: 4px; }

.fb-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px;
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center;
  transition: all 0.12s;
}

.fb-btn:hover { border-color: var(--primary); color: var(--primary); }
.fb-btn.active { border-color: var(--primary); color: var(--primary); background: #EEF4FC; }

/* TYPING INDICATOR */
.typing-bubble {
  padding: 14px 16px !important;
  display: flex !important;
  gap: 4px;
  align-items: center;
}

.typing-bubble span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* INPUT AREA */
.input-area {
  padding: 16px 20px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 780px; margin: 0 auto;
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within { border-color: var(--primary); background: var(--bg); }

#msg-input {
  flex: 1; background: none; border: none; outline: none;
  font-family: inherit; font-size: 14px; color: var(--text);
  resize: none; line-height: 1.5; max-height: 160px;
}

#msg-input::placeholder { color: var(--muted); }

#send-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--primary); border: none;
  border-radius: 10px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}

#send-btn:hover:not(:disabled) { background: var(--primary-light); transform: scale(1.05); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-footer {
  max-width: 780px; margin: 8px auto 0;
  font-size: 11px; color: var(--muted); text-align: center;
}

/* ================================================================
   ALERTS
   ================================================================ */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.5; margin: 12px 16px;
}

.alert-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-error   { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }

/* ================================================================
   ADMIN LAYOUT
   ================================================================ */
.admin-body { background: #F0F2F7; min-height: 100vh; }

.admin-layout { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--primary-dark);
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.admin-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.admin-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; }

.admin-nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px; color: rgba(255,255,255,0.7);
  text-decoration: none; transition: all 0.12s;
}

.admin-nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.admin-nav-item.active { background: rgba(255,255,255,0.15); color: #fff; }

.admin-sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); }

.admin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.admin-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-page-title { font-size: 18px; font-weight: 600; color: var(--text); }

.admin-user { display: flex; align-items: center; gap: 10px; }

.admin-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }

.admin-content { padding: 24px; flex: 1; overflow-y: auto; }

/* STATS GRID */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }

.stat-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 600; color: var(--primary); line-height: 1; }

/* ADMIN SECTIONS */
.admin-section { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-md); overflow: hidden; margin-bottom: 20px; }

.section-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.section-title { font-size: 15px; font-weight: 500; color: var(--text); }
.section-link { font-size: 13px; color: var(--primary); }

/* DATA TABLE */
.data-table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-weight: 500; font-size: 12px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface); }

/* BADGES */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge-admin    { background: #EEF4FC; color: var(--primary); }
.badge-user     { background: var(--surface); color: var(--text2); }
.badge-active   { background: #ECFDF5; color: #065F46; }
.badge-inactive { background: #FEF2F2; color: #991B1B; }

/* BUTTONS */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; background: var(--primary);
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-light); color: #fff; text-decoration: none; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; background: var(--bg);
  color: var(--text2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

.btn-sm {
  padding: 5px 12px; background: var(--surface);
  color: var(--text2); border: 1px solid var(--border);
  border-radius: 6px; font-size: 12px; cursor: pointer;
  text-decoration: none; transition: all 0.12s;
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

.btn-danger { background: #FEF2F2; color: #B91C1C; border-color: #FECACA; }
.btn-danger:hover { background: #B91C1C; color: #fff; border-color: #B91C1C; }

/* FORMS */
.form-card {
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius-md); padding: 28px 32px; max-width: 840px;
}

.form-group { margin-bottom: 20px; }

.form-label {
  display: block; font-size: 13.5px; font-weight: 500;
  color: var(--text); margin-bottom: 6px;
}

.form-hint { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.required { color: var(--error); }

.form-input {
  width: 100%; padding: 10px 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--bg); outline: none;
  transition: border-color 0.18s;
}

.form-input:focus { border-color: var(--primary); }

.form-textarea {
  width: 100%; padding: 12px 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--bg); outline: none; resize: vertical; line-height: 1.6;
  transition: border-color 0.18s;
}

.form-textarea:focus { border-color: var(--primary); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; z-index: 100; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .main-content { width: 100%; }
  .messages-area { padding: 16px 12px; }
  .input-area { padding: 12px; }
  .suggestions-grid { grid-template-columns: 1fr; }
  .admin-sidebar { display: none; }
  .stat-value { font-size: 22px; }
  .msg-bubble { max-width: 92%; }
  .msg-row.bot .msg-bubble { max-width: 92%; }
}
