/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --camea-orange:      #fd661e;
  --camea-orange-dark: #D4651A;
  --bg-base:           #111D28;
  --bg-surface:        #1b3351;
  --bg-surface-mid:    #243447;
  --bg-surface-alt:    #2E4057;
  --text-primary:      #F5F5F5;
  --text-secondary:    #A0A8B0;
  --text-muted:        #6B7480;
  --border:            #2E4057;
  --msg-own-bg:        #F47920;
  --msg-own-text:      #ffffff;
  --msg-own-border:    #D4651A;
  --msg-other-bg:      #1C2B3A;
  --msg-other-text:    #F5F5F5;
  --msg-other-border:  #2E4057;
  --input-bg:          #111D28;
  --scrollbar-thumb:   #2E4057;
}

body.light-mode {
  --bg-base:           #F0F2F5;
  --bg-surface:        #333333;  
  --bg-surface-mid:    #E8EBF0;
  --bg-surface-alt:    #D8DCE3;
  --text-primary:      #1C2B3A;
  --text-secondary:    #4A5568;
  --text-muted:        #020202;
  --border:            #CBD5E0;
  --msg-own-bg:        #F47920;
  --msg-own-text:      #ffffff;
  --msg-own-border:    #D4651A;
  --msg-other-bg:      #FFFFFF;
  --msg-other-text:    #1C2B3A;
  --msg-other-border:  #CBD5E0;
  --input-bg:          #F8F9FB;
  --scrollbar-thumb:   #CBD5E0;
}

html, body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100%;
  overflow-x: hidden;
  transition: background 0.25s, color 0.25s;
}

/* ===== THEME BUTTON ===== */
.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 10px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.theme-btn:hover { background: var(--bg-surface-alt); color: var(--text-primary); border-color: var(--camea-orange); }
.theme-btn .theme-icon  { font-size: 1rem; }
.theme-btn .theme-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== HEADER ===== */
.header {
  background: var(--bg-surface);
  border-bottom: 3px solid var(--camea-orange);
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.25s;
}

.header-left {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.header-logo { height: 32px; width: auto; flex-shrink: 0; }
body.light-mode .header-logo { filter: invert(1) brightness(0.2); }

.header-divider {
  display: inline-block;
  width: 1px;
  height: 28px;
  background: var(--camea-orange);
  margin: 0 12px;
  opacity: 0.6;
  flex-shrink: 0;
}

.header-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--camea-orange);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ===== LANGUAGE FLAGS ===== */
.lang-switcher { display: flex; gap: 4px; }

.lang-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 2px 3px;
  opacity: 0.45;
  transition: opacity 0.2s, border-color 0.2s;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lang-btn:hover  { opacity: 0.85; }
.lang-btn.active { opacity: 1; border-color: var(--camea-orange); }

/* ===== BUTTONS ===== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
  min-height: 40px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary   { background: var(--camea-orange); color: #fff; }
.btn-primary:hover { background: var(--camea-orange-dark); }

.btn-secondary { background: var(--bg-surface-alt); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-surface-mid); }

.btn-resolve   { background: #2D8653; color: #fff; }
.btn-resolve:hover { background: #1f5e3a; }

.btn-reopen    { background: #6B7480; color: #fff; }
.btn-reopen:hover  { background: #555d66; }

.btn-logout    { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-logout:hover  { background: var(--bg-surface-alt); color: var(--text-primary); }

/* ===== LOGIN PAGE ===== */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: var(--bg-base);
  transition: background 0.25s;
}

.login-lang {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 6px;
}

.login-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--camea-orange);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  transition: background 0.25s, border-color 0.25s;
}

.login-logo { text-align: center; margin-bottom: 32px; }

.logo-img { height: 44px; width: auto; display: block; margin: 0 auto 14px; }
body.light-mode .logo-img { filter: invert(1) brightness(0.2); }

.logo-divider { width: 48px; height: 3px; background: var(--camea-orange); border-radius: 2px; margin: 0 auto 14px; }

.login-logo h1 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  line-height: 1.6;
}

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

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.25s;
}
.form-group input:focus { border-color: var(--camea-orange); box-shadow: 0 0 0 3px rgba(244,121,32,0.15); }

.error-msg { color: #e05c5c; font-size: 0.875rem; margin-bottom: 14px; min-height: 20px; text-align: center; }

/* ===== DASHBOARD ===== */
.dashboard-page { display: flex; flex-direction: column; height: 100dvh; }

.dashboard-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.dashboard-heading {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-left: 4px solid var(--camea-orange);
  padding-left: 12px;
}

.conversation-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 64px;
}
.conversation-item:hover,
.conversation-item:active { background: var(--bg-surface-mid); border-left-color: var(--camea-orange); }

.conv-status { flex-shrink: 0; }

.status-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-new      { background: rgba(244,121,32,0.12); color: #D4651A; border: 1px solid #F47920; }
.status-open     { background: rgba(224,145,58,0.12); color: #B8710A; border: 1px solid #E0913A; }
.status-resolved { background: rgba(45,134,83,0.12);  color: #1e6b40; border: 1px solid #2D8653; }

body.light-mode .status-new      { color: #C25A10; }
body.light-mode .status-open     { color: #8A5200; }
body.light-mode .status-resolved { color: #1a5c35; }

.conv-info { flex: 1; min-width: 0; }
.conv-customer { font-weight: 700; color: var(--text-primary); margin-bottom: 3px; font-size: 0.9rem; }
.conv-preview  { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time     { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

.no-chats { text-align: center; color: var(--text-muted); padding: 80px 0; }

/* ===== CHAT PAGE ===== */
.chat-page { display: flex; flex-direction: column; height: 100dvh; }

.chat-subheader {
  background: var(--bg-surface);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
  transition: background 0.25s;
}

.chat-subheader-left { display: flex; align-items: center; gap: 8px; min-width: 0; }

.chat-customer-name {
  font-weight: 700;
  color: var(--camea-orange);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-base);
  -webkit-overflow-scrolling: touch;
  transition: background 0.25s;
}

.message { max-width: 75%; display: flex; flex-direction: column; }
.message-own   { align-self: flex-end;   align-items: flex-end; }
.message-other { align-self: flex-start; align-items: flex-start; }

.message-sender {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.message-content {
  background: var(--msg-other-bg);
  border: 1px solid var(--msg-other-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  font-size: 0.9375rem;
  line-height: 1.5;
  word-break: break-word;
  color: var(--msg-other-text);
  transition: background 0.25s, border-color 0.25s;
}

.message-own .message-content {
  background: var(--msg-own-bg);
  border-color: var(--msg-own-border);
  color: var(--msg-own-text);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 4px;
}

.message-time { font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; }

.chat-input-area {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  transition: background 0.25s;
}

.chat-input-area textarea {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 16px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.25s;
}
.chat-input-area textarea:focus { border-color: var(--camea-orange); box-shadow: 0 0 0 3px rgba(244,121,32,0.15); }

/* ===== SCROLLBAR ===== */
@media (pointer: fine) {
  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: var(--bg-base); }
  ::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--camea-orange); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-title { font-size: 0.7rem; }
  .login-box { padding: 32px 24px; }
  .message { max-width: 85%; }
}

@media (max-width: 480px) {
  .header { height: 52px; padding: 0 12px; }
  .header-title, .header-divider { display: none; }
  .header-logo { height: 28px; }
  .lang-btn { font-size: 1.1rem; min-width: 32px; min-height: 32px; }
  .theme-btn .theme-label { display: none; }
  .theme-btn { padding: 4px 8px; }
  .btn-logout { font-size: 0.75rem; padding: 6px 10px; min-height: 34px; }
  .login-box { padding: 28px 18px; border-radius: 8px; }
  .login-logo h1 { font-size: 0.75rem; letter-spacing: 1px; }
  .dashboard-body { padding: 12px 10px; }
  .conversation-item { padding: 12px; gap: 10px; }
  .conv-customer { font-size: 0.85rem; }
  .messages-container { padding: 12px 10px; }
  .message { max-width: 90%; }
  .message-content { font-size: 0.9rem; padding: 8px 12px; }
  .chat-subheader { padding: 8px 10px; flex-direction: column; align-items: flex-start; }
  .chat-subheader .btn-resolve,
  .chat-subheader .btn-reopen { width: 100%; text-align: center; }
  .chat-input-area { padding: 10px; gap: 6px; }
  .btn-primary { padding: 8px 12px; font-size: 0.85rem; }
}

@media (max-width: 360px) {
  .login-box { padding: 20px 14px; }
  .message { max-width: 95%; }
}

@media (min-width: 900px) and (max-height: 768px) {
  .header { height: 52px; }
  .messages-container { padding: 12px 20px; }
  .dashboard-body { padding: 16px 20px; }
}


/* ===== ATTACH BUTTON ===== */
.btn-attach {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 10px;
  min-height: 44px;
  min-width: 44px;
  color: var(--text-secondary);
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.btn-attach:hover {
  background: var(--bg-surface-alt);
  border-color: var(--camea-orange);
}

/* ===== UPLOAD PREVIEW BAR ===== */
.upload-preview {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-preview img {
  height: 48px;
  width: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.upload-preview-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ===== CHAT IMAGE ===== */
.message-image {
  padding: 4px !important;
  background: transparent !important;
  border: none !important;
}
.chat-img {
  max-width: 260px;
  max-height: 200px;
  border-radius: 10px;
  cursor: zoom-in;
  display: block;
  border: 1px solid var(--border);
  transition: opacity 0.2s;
}
.chat-img:hover { opacity: 0.88; }

/* ===== IMAGE LIGHTBOX MODAL ===== */
.image-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}
.image-modal img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.modal-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.3); }

/* ===== MOBILE ===== */
@media (max-width: 480px) {
  .chat-img { max-width: 180px; max-height: 150px; }
  .btn-attach { min-width: 36px; padding: 0 6px; font-size: 1.1rem; }
}

/* ===== FAQ BUTTON ===== */
.btn-faq {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-faq:hover { background: var(--bg-surface-alt); color: var(--text-primary); border-color: var(--camea-orange); }

/* ===== FAQ MODAL ===== */
.faq-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.faq-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--camea-orange);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 16px;
}

.faq-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.faq-close {
  position: static;
  background: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
}

.faq-body {
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.faq-item { border-bottom: 1px solid var(--border); padding-bottom: 14px; }
.faq-item:last-child { border-bottom: none; padding-bottom: 0; }

.faq-question {
  font-weight: 700;
  color: var(--camea-orange);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.faq-answer {
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.chat-info-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 20px;
  font-size: 0.78rem;
  color: var(--text-muted, #888);
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
  text-align: center;
}

.info-bar-clock {
  display: flex;
  gap: 6px;
  align-items: center;
}

.info-bar-time {
  font-variant-numeric: tabular-nums; /* prevents bar jumping as digits change width */
}