:root { 
  font-size: 1rem;
  --primary-color: #666;
  --primary-hover: #555;
  --bg-dark: #111;
  --bg-darker: #000;
  --text-light: #eee;
  --border-color: #333;
  --vh: 1vh; /* For JavaScript viewport fix */
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  background: var(--bg-darker);
  color: var(--text-light);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  gap: 10px;
  padding: 15px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

button {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-light);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  background: rgba(255,255,255,0.1);
}

.icon-right {
  margin-left: auto;
}

.tab-active {
  font-weight: bold;
  border-bottom: 2px solid var(--primary-color);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

[data-tab-content] {
  display: none;
  flex: 1;
  overflow: hidden;
}

[data-tab-content].active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Common container styles for both journal and chat */
.content-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Content area (scrollable) */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: 120px; /* Space for input area */
  scroll-behavior: smooth;
}

/* Sticky input area at bottom */
.input-container {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-darker);
  border-top: 1px solid var(--border-color);
  padding: 15px;
  z-index: 10;
  flex-shrink: 0;
  /* Auto-resize textarea ke atas, tombol send tetap di tempat */
  display: flex;
  align-items: flex-end;
}

.input-group {
  position: relative;
  display: flex;
  gap: 10px;
  width: 100%;           /* tambahkan */
  align-items: flex-end; /* textarea & tombol tetap rata bawah */
}

textarea {
  flex: 1 1 0;      /* grow, shrink, basis 0 */
  width: 100%;      /* paksa 100% dari parent */
  background: var(--bg-dark);
  color: var(--text-light);
  border: 1px solid var(--border-color);
  padding: 12px 15px;
  border-radius: 12px;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  overflow-y: hidden; /* ganti dari auto */
  transition: all 0.2s ease;
  
  /* tambahan baru */
  height: 48px;           /* tinggi awal 1 baris */
  box-sizing: border-box; /* hitung padding & border */
}

textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(102, 102, 102, 0.2);
}

textarea::placeholder {
  color: #888;
}

/* Action buttons */
.action-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.action-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Chat specific styles */
.chat-interface {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#chatArea {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: 120px;
  scroll-behavior: smooth;
}

#chatList {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

#chat-input {
  flex: 1 1 auto;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  transition: height 0.15s ease;
}

#send-button {
  height: 40px;            /* ukuran tetap */
  flex-shrink: 0;          /* jangan ikut mengecil */
  align-self: flex-end;    /* pastikan tetap di dasar */
}

/* Chat bubbles */
.bubble {
  position: relative;
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 85%;
  word-break: break-word;
  line-height: 1.4;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 5px;
}

.bubble.user {
  background: #222;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  border-left: 4px solid #4a8bfc;
  margin-left: auto;
}

.bubble.ai {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border-left: 4px solid #10a37f;
}

.bubble.error {
  background: #2d1b1b;
  border: 1px solid #8b4444;
  align-self: flex-start;
  border-left: 4px solid #ff4444;
}

.bubble.typing {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-left: 4px solid #10a37f;
}

/* Bubble actions */
.bubble-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

.bubble:hover .bubble-actions {
  opacity: 1;
}

.bubble-action {
  background: rgba(0,0,0,0.7);
  border: none;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.bubble-action:hover {
  background: rgba(0,0,0,0.9);
}

.bubble small {
  display: block;
  font-size: 0.8em;
  color: #999;
  margin-top: 5px;
}

/* Journal specific styles */
.journal-editor {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.journal-entries {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: 120px;
}

.journal-entry {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  position: relative;
}

.journal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.journal-header h3 {
  margin: 0;
  font-size: 1.1em;
  color: var(--text-light);
}

.journal-header small {
  color: #999;
  font-size: 0.8em;
}

.journal-content {
  color: var(--text-light);
  line-height: 1.5;
  margin-bottom: 10px;
}

.delete-btn {
  background: #8b4444;
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.delete-btn:hover {
  background: #aa5555;
}

.no-journals {
  text-align: center;
  color: #666;
  font-style: italic;
  padding: 40px;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  margin-right: 10px;
}

.typing-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #666;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% { transform: scale(1); opacity: 0.5; }
  30% { transform: scale(1.2); opacity: 1; }
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #333;
  border-top: 2px solid #666;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Toast notifications */
#toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-weight: 500;
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

#toast.show {
  transform: translateX(0);
}

#toast.success {
  background: #10a37f;
}

#toast.error {
  background: #ff4444;
}

#toast.warning {
  background: #ff8800;
}

#toast.info {
  background: #4a8bfc;
}

/* Error log */
.error-log {
  position: fixed;
  bottom: 20px;
  left: 20px;
  max-width: 400px;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(0,0,0,0.9);
  border: 1px solid #8b4444;
  border-radius: 8px;
  padding: 10px;
  font-family: monospace;
  font-size: 12px;
  z-index: 1000;
  display: none;
}

.error-entry {
  margin-bottom: 5px;
  padding: 5px;
  background: rgba(139, 68, 68, 0.2);
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
  header {
    padding: 10px;
  }

  .content-area {
    padding: 10px;
    padding-bottom: 120px;
  }

  .input-container {
    padding: 10px;
  }

  .bubble {
    max-width: 90%;
  }

  textarea {
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .action-btn {
    width: 44px;
    height: 44px;
  }
}

/* ========== MOBILE VIEWPORT FIXES ========== */
.small-screen {
  --header-height: 50px;
  --input-height: 60px;
}

.small-screen #chatArea,
.small-screen #journalContainer {
  height: calc(100vh - var(--header-height) - var(--input-height)) !important;
  padding-bottom: 0 !important;
}

.small-screen .input-container {
  height: var(--input-height);
}

/* Fix keyboard overlap Redmi 6A */
@media (max-height: 480px) {
  .input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
  }
  
  .content-area {
    padding-bottom: calc(var(--input-height) + 10px) !important;
  }
}

