/* ==========================================================================
   Bengkel Mozaik Motor - Chatbot Styles
   Responsive, High-Performance, Automotive Dark Theme
   Favicon Robot & Clean Initial State
   ========================================================================== */

:root {
  --bg-primary: #0b1120;       /* Deep Slate/Dark Navy */
  --bg-secondary: #1e293b;     /* Slate 800 */
  --bg-tertiary: #334155;      /* Slate 700 */
  --bg-card: rgba(30, 41, 59, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #f59e0b;     /* Amber 500 */
  
  --text-main: #f8fafc;        /* Slate 50 */
  --text-muted: #94a3b8;       /* Slate 400 */
  --text-dim: #64748b;         /* Slate 500 */

  --accent-amber: #f59e0b;     /* Amber Racing */
  --accent-orange: #ea580c;    /* Racing Orange */
  --accent-blue: #38bdf8;      /* Sky Robot Cyan */
  --accent-green: #10b981;     /* Emerald Green */
  --accent-red: #ef4444;       /* Alert Red */

  --gradient-accent: linear-gradient(135deg, #f59e0b, #ea580c);
  --gradient-blue: linear-gradient(135deg, #0284c7, #2563eb);
  --gradient-card: linear-gradient(180deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.8));

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Reset & Base Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout App Container */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-primary);
}

/* Top App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  z-index: 20;
  flex-shrink: 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(245, 158, 11, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.2);
  flex-shrink: 0;
}

.robot-header-icon {
  width: 26px;
  height: 26px;
  display: block;
}

.brand-info {
  min-width: 0;
}

.brand-info h1 {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-info p {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.badge-green {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.3);
}

.badge-green .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  animation: pulse-green 2s infinite;
}

.badge-amber {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
}

.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border-color: var(--border-focus);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* Live Stats Overview Bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.stats-bar.collapsed {
  display: none;
}

.stats-bar::-webkit-scrollbar {
  display: none;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  border-color: rgba(245, 158, 11, 0.3);
}

.stat-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}

.stat-icon.blue { background: rgba(56, 189, 248, 0.12); color: var(--accent-blue); }
.stat-icon.amber { background: rgba(245, 158, 11, 0.12); color: var(--accent-amber); }
.stat-icon.green { background: rgba(16, 185, 129, 0.12); color: var(--accent-green); }
.stat-icon.red { background: rgba(239, 68, 68, 0.12); color: var(--accent-red); }

.stat-data {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.stat-value {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

/* Chat History Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

/* Clean & Minimalist Initial Greeting */
.welcome-clean {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  margin: auto 0;
  animation: fadeIn 0.3s ease-out;
}

.welcome-clean.hidden {
  display: none;
}

.robot-pulse-ring {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.18) 0%, rgba(15, 23, 42, 0.4) 70%);
  border: 1px solid rgba(245, 158, 11, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.25);
  animation: pulse-ring 3s infinite ease-in-out;
}

.robot-hero-avatar {
  width: 44px;
  height: 44px;
  display: block;
}

.welcome-clean-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.welcome-clean-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 440px;
  line-height: 1.45;
}

/* Chat Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: fadeIn 0.2s ease-out;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.message.user .avatar {
  background: var(--gradient-blue);
  color: #fff;
}

.message.bot .avatar {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 3px;
}

.message.bot .avatar img {
  width: 100%;
  height: 100%;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.message.user .bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.message.bot .bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 2px;
  box-shadow: var(--shadow-sm);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* Markdown Styling inside Bubbles */
.bubble p {
  margin-bottom: 6px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  color: #fff;
  font-weight: 600;
}

.bubble ul, .bubble ol {
  margin: 4px 0 6px 18px;
}

.bubble li {
  margin-bottom: 3px;
}

/* Responsive Table with horizontal scroll */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.78rem;
  background: rgba(11, 17, 32, 0.7);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: block;
  overflow-x: auto;
  scrollbar-width: thin;
}

.bubble th, .bubble td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.bubble th {
  background: rgba(245, 158, 11, 0.14);
  color: var(--accent-amber);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.4px;
}

.bubble tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.bubble code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--accent-blue);
}

/* Tool execution status pill */
.tool-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--accent-amber);
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  margin-bottom: 6px;
  animation: pulse 1.5s infinite;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-amber);
  animation: typing 1.4s infinite ease-in-out;
}

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

/* Input Container & Quick Chips */
.chat-input-wrapper {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)) 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  z-index: 20;
  flex-shrink: 0;
}

.input-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.input-chips::-webkit-scrollbar {
  display: none;
}

.mini-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.72rem;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.mini-chip:hover {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--accent-amber);
  color: #fff;
}

.mini-chip:active {
  transform: scale(0.96);
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-form:focus-within {
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  min-height: 24px;
  line-height: 1.4;
  padding: 6px 0;
}

.chat-textarea::placeholder {
  color: var(--text-dim);
  font-size: 0.86rem;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

/* Modal Popup (Pengaturan & Info) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.3rem;
  padding: 4px;
}

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

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.86rem;
  outline: none;
}

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

.btn-primary {
  background: var(--gradient-accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  width: 100%;
}

.info-box {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: #a7f3d0;
  margin-top: 12px;
  line-height: 1.45;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes typing {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

@keyframes pulse-ring {
  0%, 100% { transform: scale(1); box-shadow: 0 0 15px rgba(245, 158, 11, 0.2); }
  50% { transform: scale(1.05); box-shadow: 0 0 25px rgba(245, 158, 11, 0.4); }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Mobile Phones (max 640px) */
@media (max-width: 640px) {
  .app-header {
    padding: 8px 12px;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .robot-header-icon {
    width: 22px;
    height: 22px;
  }

  .brand-info h1 {
    font-size: 0.9rem;
  }

  .header-badges .badge-model {
    display: none; /* Sembunyikan badge di layar HP kecil */
  }

  .stats-bar {
    padding: 6px 12px;
    gap: 6px;
  }

  .stat-card {
    min-width: 110px;
    padding: 5px 8px;
    gap: 6px;
  }

  .stat-icon {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }

  .stat-value {
    font-size: 0.82rem;
  }

  .message {
    max-width: 94%;
  }

  .bubble {
    font-size: 0.85rem;
    padding: 9px 12px;
  }

  .welcome-clean {
    padding: 16px 10px;
  }

  .robot-pulse-ring {
    width: 58px;
    height: 58px;
    margin-bottom: 10px;
  }

  .robot-hero-avatar {
    width: 36px;
    height: 36px;
  }

  .welcome-clean-title {
    font-size: 1.05rem;
  }

  .chat-input-wrapper {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) 12px;
  }

  .chat-textarea::placeholder {
    font-size: 0.8rem;
  }
}

/* Widescreen & Tablets */
@media (min-width: 1024px) {
  .app-container {
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
  }

  .message {
    max-width: 82%;
  }
}
