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

html {
  font-size: 16px;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--background-color);
  color: var(--text-color);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ======================= LOGIN ======================= */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 2rem 1.5rem;
  background: linear-gradient(135deg, #3D3D3D 0%, #1A1A1A 100%);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
  color: #fff;
}

.logo-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(245,124,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(245,124,0,0.4);
  color: #F57C00;
}

.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-top: 0.3rem;
}

.login-tabs {
  display: flex;
  gap: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: 360px;
}

.login-tab {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.login-tab.active {
  background: rgba(255,255,255,0.95);
  color: #3D3D3D;
}

.login-form {
  display: none;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 360px;
}
.login-form.active {
  display: flex;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.8);
  font-weight: 500;
}

.form-group select {
  padding: 0.85rem 1rem;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  backdrop-filter: blur(5px);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  cursor: pointer;
}

.form-group select option {
  background: #333;
  color: #fff;
}

.form-group select option:disabled {
  color: rgba(255,255,255,0.4);
}

.form-group select:focus {
  border-color: rgba(255,255,255,0.5);
}

.form-group input {
  padding: 0.85rem 1rem;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  backdrop-filter: blur(5px);
}

.form-group input::placeholder {
  color: rgba(255,255,255,0.4);
}

.form-group input:focus {
  border-color: rgba(255,255,255,0.5);
}

.btn-primary {
  padding: 0.85rem 1.5rem;
  background: var(--secondary-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn-primary:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-secondary {
  padding: 0.75rem 1.2rem;
  background: transparent;
  color: var(--secondary-color);
  border: 2px solid var(--secondary-color);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.login-error {
  color: #FFD54F;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.5rem;
  min-height: 1.2rem;
}

/* Login Divider */
.login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.2);
}

.login-divider span {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
}

/* QR Scan Button */
.btn-qr-scan {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.8rem 1.2rem;
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  backdrop-filter: blur(5px);
}

.btn-qr-scan:active {
  background: rgba(255,255,255,0.2);
}

/* QR Scanner Overlay */
.qr-scanner-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-scanner-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1rem;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
}

.qr-scanner-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-scanner-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

.qr-scanner-container video {
  width: 100%;
  max-width: 400px;
  height: auto;
  border-radius: 12px;
}

.qr-scanner-frame {
  position: absolute;
  width: 220px;
  height: 220px;
  border: 3px solid rgba(255,255,255,0.6);
  border-radius: 16px;
  box-shadow: 0 0 0 4000px rgba(0,0,0,0.5);
}

.qr-scanner-hint {
  padding: 1.2rem;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  text-align: center;
}

/* PWA Banner */
.pwa-banner {
  margin-top: 1.5rem;
  padding: 1rem;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  text-align: center;
  width: 100%;
  max-width: 360px;
  backdrop-filter: blur(5px);
}

.pwa-banner p {
  color: rgba(255,255,255,0.9);
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.btn-install {
  padding: 0.6rem 1.2rem;
  background: var(--secondary-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* ======================= HEADER ======================= */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: var(--header-bg);
  color: var(--header-text);
  min-height: 56px;
  z-index: 10;
  flex-shrink: 0;
}

.app-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  gap: 0.25rem;
}

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--header-text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.header-btn:active {
  background: rgba(255,255,255,0.15);
}

/* ======================= DROPDOWN MENU ======================= */
.dropdown-menu {
  display: none;
  position: absolute;
  top: 50px;
  right: 8px;
  background: var(--surface-color);
  border-radius: 12px;
  box-shadow: 0 4px 24px var(--shadow-color);
  min-width: 220px;
  z-index: 100;
  overflow: hidden;
  padding: 6px 0;
  animation: slideDown 0.15s ease;
}

.dropdown-menu.open {
  display: block;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1.1rem;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.dropdown-item:active {
  background: var(--divider-color);
}

.dropdown-item.text-danger {
  color: var(--danger-color);
}

.dropdown-divider {
  height: 1px;
  background: var(--divider-color);
  margin: 4px 0;
}

/* ======================= SEARCH BAR ======================= */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--surface-color);
  border-bottom: 1px solid var(--divider-color);
  flex-shrink: 0;
}

.search-bar svg {
  color: var(--text-light);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  color: var(--text-color);
  outline: none;
  padding: 0.5rem 0;
}

.search-bar input::placeholder {
  color: var(--text-light);
}

/* ======================= CHAT LIST ======================= */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface-color);
  -webkit-overflow-scrolling: touch;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--divider-color);
  cursor: pointer;
  transition: background 0.12s;
  text-decoration: none;
  color: inherit;
}

.chat-list-item:active {
  background: var(--divider-color);
}

.chat-item-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--secondary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
}

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

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}

.chat-item-name {
  font-size: 1rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 0.72rem;
  color: var(--text-light);
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.chat-item-time.unread {
  color: var(--primary-light);
  font-weight: 600;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-item-preview {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-item-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--secondary-color);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.chat-item-status {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  margin-left: 6px;
}

.status-bot {
  background: #E8F5E9;
  color: #2E7D32;
}

.status-waiting {
  background: #FFF3E0;
  color: #E65100;
}

.status-tech {
  background: #E3F2FD;
  color: #1565C0;
}

.status-closed {
  background: #FAFAFA;
  color: #9E9E9E;
}

[data-theme="dark"] .status-bot { background: rgba(46,125,50,0.2); color: #66BB6A; }
[data-theme="dark"] .status-waiting { background: rgba(230,81,0,0.2); color: #FFA726; }
[data-theme="dark"] .status-tech { background: rgba(21,101,192,0.2); color: #42A5F5; }
[data-theme="dark"] .status-closed { background: rgba(158,158,158,0.15); color: #9E9E9E; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-light);
}

.empty-state p {
  font-size: 1rem;
  margin-top: 1rem;
  font-weight: 500;
}

.empty-state small {
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

/* ======================= MODALS ======================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal.open {
  display: flex;
}

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

.modal-content {
  background: var(--surface-color);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--divider-color);
  position: sticky;
  top: 0;
  background: var(--surface-color);
  z-index: 1;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-back {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-body {
  padding: 1.2rem;
}

.modal-body .form-group label {
  color: var(--text-color);
}

.modal-body .form-group select {
  background: var(--input-bg);
  color: var(--text-color);
  border: 2px solid var(--input-border);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  backdrop-filter: none;
}

.modal-body .form-group select option {
  background: var(--surface-color);
  color: var(--text-color);
}

.modal-body .form-group input {
  background: var(--input-bg);
  color: var(--text-color);
  border: 2px solid var(--input-border);
  backdrop-filter: none;
}

.modal-body .form-group input::placeholder {
  color: var(--text-light);
}

.color-setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--divider-color);
}

.color-setting label {
  font-size: 0.9rem;
  font-weight: 500;
}

.color-setting input[type="color"] {
  width: 44px;
  height: 32px;
  border: 2px solid var(--divider-color);
  border-radius: 8px;
  cursor: pointer;
  padding: 2px;
}

.color-actions {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

.qr-result {
  text-align: center;
  margin-top: 1.2rem;
}

.qr-result img {
  width: 250px;
  height: 250px;
  border-radius: 12px;
}

.qr-url {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.8rem;
  word-break: break-all;
}

/* ======================= SCROLLBAR ======================= */
::-webkit-scrollbar {
  width: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--text-light);
  border-radius: 3px;
}

/* ======================= NOTIFICATION ======================= */
.pending-notification {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid #e0e0e0;
  border-left: 4px solid #F57C00;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 9999;
  max-width: 90%;
  width: 380px;
  animation: slideDown 0.3s ease;
}
.pending-notif-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pending-notif-content strong {
  color: #3D3D3D;
  font-size: 0.85rem;
}
.pending-notif-content span {
  color: #666;
  font-size: 0.8rem;
}
.pending-notif-btn {
  background: #F57C00;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pending-notif-btn:active {
  background: #E65100;
}
@keyframes slideDown {
  from { transform: translateX(-50%) translateY(-100%); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ======================= UTILITY ======================= */
.hidden { display: none !important; }

@media (min-width: 768px) {
  .login-container {
    padding: 3rem;
  }
  .modal-content {
    border-radius: 16px;
    margin-bottom: 2rem;
  }
  .modal {
    align-items: center;
  }
}
