/* ============================================================
   DESIGN TOKENS
   Palet: pine gelap untuk sidebar, teal muted untuk aksen,
   putih pucat kehijauan untuk kanvas utama.
   ============================================================ */
:root {
  --bg-app: #eef1f0;
  --bg-canvas: #f6f8f7;
  --sidebar-bg: #10241f;
  --sidebar-bg-raised: #16302a;
  --sidebar-border: #1e3b33;
  --sidebar-text: #e6ede9;
  --sidebar-text-muted: #93a89f;

  --accent: #1c7c6b;
  --accent-dark: #145c4f;
  --accent-soft: #e2f2ee;

  --text-primary: #16211d;
  --text-secondary: #5b6b65;
  --text-inverse: #f4f7f5;

  --border: #dde3e0;
  --border-strong: #c7d0cc;

  --bubble-out: #1c7c6b;
  --bubble-out-text: #f4f7f5;
  --bubble-in: #ffffff;
  --bubble-in-text: #16211d;

  --danger: #c0453a;
  --success: #2f9e6e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(16, 36, 31, 0.06);
  --shadow-2: 0 8px 24px rgba(16, 36, 31, 0.12);

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

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

a {
  color: inherit;
}

input:focus-visible,
button:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ============================================================
   AUTH PAGES (login.html / register.html / username-setup.html)
   Layout: panel brand di kiri, form card di kanan
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.auth-brand {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.auth-brand::after {
  content: "";
  position: absolute;
  right: -140px;
  bottom: -140px;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(28, 124, 107, 0.35), transparent 70%);
}

.auth-brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  z-index: 1;
}

.auth-brand-mark .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.auth-brand-copy {
  z-index: 1;
  max-width: 420px;
}

.auth-brand-copy h1 {
  font-size: 40px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
}

.auth-brand-copy p {
  color: var(--sidebar-text-muted);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.auth-brand-foot {
  color: var(--sidebar-text-muted);
  font-size: 13px;
  z-index: 1;
}

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg-canvas);
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-card h2 {
  font-size: 24px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.auth-card .sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 28px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: #fff;
  color: var(--text-primary);
  transition: border-color 0.15s ease;
}

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

.field-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 6px;
  min-height: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.btn-outline {
  background: #fff;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--accent);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-switch {
  margin-top: 22px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.auth-switch button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}

.google-icon {
  width: 18px;
  height: 18px;
}

/* Username setup avatar circle */
.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  margin-bottom: 20px;
}

/* ============================================================
   CHAT APP (chat.html)
   ============================================================ */
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 360px 1fr;
  background: var(--bg-canvas);
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

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

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

.me-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--sidebar-bg-raised);
  color: var(--sidebar-text);
}

.sidebar-search {
  padding: 12px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg-raised);
  color: var(--sidebar-text);
  font-size: 13px;
}

.search-box input::placeholder {
  color: var(--sidebar-text-muted);
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-text-muted);
}

.search-results {
  position: absolute;
  z-index: 10;
  left: 14px;
  right: 14px;
  margin-top: 6px;
  background: var(--sidebar-bg-raised);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}

.search-result-item {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.search-empty {
  padding: 12px;
  font-size: 12px;
  color: var(--sidebar-text-muted);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background 0.12s ease;
}

.chat-item:hover {
  background: var(--sidebar-bg-raised);
}

.chat-item.active {
  background: var(--sidebar-bg-raised);
  box-shadow: inset 3px 0 0 var(--accent);
}

.chat-item-body {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 11px;
  color: var(--sidebar-text-muted);
  flex-shrink: 0;
}

.chat-item-preview {
  font-size: 13px;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.empty-chatlist {
  padding: 40px 24px;
  text-align: center;
  color: var(--sidebar-text-muted);
  font-size: 13px;
  line-height: 1.6;
}

/* ---- Main chat panel ---- */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-canvas);
}

.chat-panel-header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
}

.chat-panel-header .status {
  font-size: 12px;
  color: var(--text-secondary);
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  margin-bottom: 6px;
}

.msg-row.out {
  justify-content: flex-end;
}

.bubble {
  max-width: 60%;
  padding: 9px 13px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: var(--shadow-1);
}

.msg-row.in .bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.msg-row.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}

.bubble-time {
  display: block;
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.7;
  text-align: right;
}

.day-divider {
  text-align: center;
  margin: 18px 0 10px;
}

.day-divider span {
  background: var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

.composer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 11px 16px;
  font-size: 14px;
  font-family: inherit;
  max-height: 120px;
  color: var(--text-primary);
}

.composer textarea:focus {
  border-color: var(--accent);
}

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

.send-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}

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

.no-chat-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 10px;
  text-align: center;
  padding: 40px;
}

.no-chat-selected h3 {
  color: var(--text-primary);
  margin: 0;
  font-size: 18px;
}

.no-chat-selected p {
  margin: 0;
  font-size: 14px;
  max-width: 320px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.toast.error {
  background: var(--danger);
}

.hidden {
  display: none !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .auth-brand {
    display: none;
  }
  .auth-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .chat-panel {
    display: none;
  }
  .app-shell.chat-open .chat-panel {
    display: flex;
  }
  .app-shell.chat-open .sidebar {
    display: none;
  }
  .back-btn {
    display: inline-flex !important;
  }
}

.back-btn {
  display: none;
}
