/* Zalo dashboard — scoped, không ảnh hưởng index.html */

:root {
  --zd-blue: #0068ff;
  --zd-blue-soft: #e8f1ff;
  --zd-bg: #f0f2f5;
  --zd-surface: #ffffff;
  --zd-border: #e4e6eb;
  --zd-text: #050505;
  --zd-muted: #65676b;
  --zd-radius: 12px;
  --zd-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.zalo-dashboard {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--zd-bg);
  color: var(--zd-text);
}

.zd-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
.zd-header {
  background: var(--zd-surface);
  border-bottom: 1px solid var(--zd-border);
  box-shadow: var(--zd-shadow);
}

.zd-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
  row-gap: 10px;
  min-height: 56px;
  box-sizing: border-box;
}

@media (max-width: 1100px) {
  .zd-header-inner {
    flex-wrap: wrap;
  }
}

.zd-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.zd-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--zd-blue), #0047b3);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.zd-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.zd-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.zd-sub {
  font-size: 0.75rem;
  color: var(--zd-muted);
}

.zd-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
  contain: layout style;
}

@media (max-width: 1100px) {
  .zd-header-actions {
    flex-wrap: wrap;
  }
}

.zd-header-account-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  justify-content: flex-end;
}

.zd-header-actions .zd-btn--ghost,
.zd-header-actions .zd-link-home {
  flex-shrink: 0;
}

.zd-status {
  font-size: 0.8125rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--zd-bg);
  color: var(--zd-muted);
  min-width: 0;
  max-width: min(100%, 26rem);
  white-space: normal;
  line-height: 1.35;
  flex-shrink: 1;
  align-self: center;
}

.zd-status--connected {
  background: #e7f7ef;
  color: #0d7a4f;
}

.zd-status--disconnected {
  background: #fff3e0;
  color: #b45309;
}

.zd-btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
}

.zd-btn--primary {
  background: var(--zd-blue);
  color: #fff;
}

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

.zd-link-home {
  font-size: 0.875rem;
  color: var(--zd-blue);
  text-decoration: none;
}

.zd-link-home:hover {
  text-decoration: underline;
}

/* Shell */
.zd-shell {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: calc(100vh - 73px);
  gap: 0;
}

@media (max-width: 768px) {
  .zd-shell {
    grid-template-columns: 1fr;
  }

  .zd-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--zd-border);
    max-height: 40vh;
  }
}

.zd-sidebar {
  background: var(--zd-surface);
  border-right: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.zd-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--zd-border);
}

.zd-sidebar-title {
  font-weight: 700;
  font-size: 0.9375rem;
  min-width: 0;
}

.zd-sidebar-lookup-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.zd-phone-lookup-form {
  margin-bottom: 4px;
}

.zd-phone-lookup-form .zd-api-field {
  margin-bottom: 10px;
}

.zd-phone-lookup-actions {
  display: flex;
  justify-content: flex-end;
}

.zd-api-secret-hint code {
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--zd-bg);
  border: 1px solid var(--zd-border);
}

.zd-api-secret-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.zd-api-secret-actions .zd-btn {
  flex: 0 0 auto;
}

.zd-conv-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.zd-conv-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}

.zd-conv-item:hover {
  background: var(--zd-bg);
}

.zd-conv-item--active {
  background: var(--zd-blue-soft);
  border-color: #cce0ff;
}

.zd-conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #94a3b8, #64748b);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.zd-conv-body {
  min-width: 0;
  flex: 1;
}

.zd-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.zd-conv-name {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zd-conv-time {
  font-size: 0.6875rem;
  color: var(--zd-muted);
  flex-shrink: 0;
}

.zd-conv-preview {
  font-size: 0.8125rem;
  color: var(--zd-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

.zd-conv-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--zd-bg);
  color: var(--zd-muted);
}

.zd-conv-badge--friend {
  background: #e7f7ef;
  color: #0d7a4f;
}

.zd-conv-badge--stranger {
  background: #fff3e0;
  color: #b45309;
}

/* Main */
.zd-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--zd-surface);
}

.zd-toolbar {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 640px) {
  .zd-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.zd-search-wrap {
  flex: 1;
  min-width: 0;
}

.zd-search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--zd-border);
  border-radius: 999px;
  font: inherit;
  background: var(--zd-bg);
}

.zd-search:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: 0 0 0 3px rgba(0, 104, 255, 0.15);
}

.zd-tabs {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.zd-tab {
  font: inherit;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--zd-border);
  background: var(--zd-surface);
  color: var(--zd-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.zd-tab--active {
  background: var(--zd-blue-soft);
  border-color: #b3d4ff;
  color: var(--zd-blue);
}

.zd-thread-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.zd-thread-header {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--zd-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.zd-thread-title {
  font-weight: 700;
  font-size: 1rem;
}

.zd-thread-meta {
  font-size: 0.75rem;
  color: var(--zd-muted);
}

.zd-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #f1f5f9 0%, #fafbfc 48px);
}

.zd-bubble-row {
  display: flex;
  width: 100%;
}

.zd-bubble-row--them {
  justify-content: flex-start;
}

.zd-bubble-row--me {
  justify-content: flex-end;
}

.zd-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.45;
}

.zd-bubble--them {
  background: var(--zd-surface);
  border: 1px solid var(--zd-border);
  border-bottom-left-radius: 4px;
}

.zd-bubble--me {
  background: var(--zd-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.zd-bubble-time {
  font-size: 0.65rem;
  opacity: 0.75;
  margin-top: 6px;
}

.zd-composer-hint {
  padding: 12px 16px;
  border-top: 1px solid var(--zd-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zd-hint-text {
  font-size: 0.75rem;
  color: var(--zd-muted);
}

.zd-composer-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--zd-border);
  border-radius: 10px;
  font: inherit;
  background: var(--zd-bg);
}

.zd-composer-input:disabled {
  opacity: 0.7;
}

.zd-empty {
  text-align: center;
  color: var(--zd-muted);
  padding: 32px 16px;
  font-size: 0.875rem;
}

.zd-btn--secondary {
  background: var(--zd-surface);
  color: var(--zd-text);
  border: 1px solid var(--zd-border);
}

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

.zd-api-panel {
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--zd-border);
  background: #fafcff;
}

.zd-api-panel.zd-chat-composer {
  flex-shrink: 0;
  margin: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--zd-border);
  border-bottom: none;
  background: linear-gradient(180deg, #f8fafc 0%, var(--zd-surface) 100%);
  box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.07);
}

.zd-chat-composer__title {
  margin-bottom: 8px;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
}

.zd-chat-composer__row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
}

.zd-chat-composer__field {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.zd-chat-composer__input {
  border-radius: 14px;
  min-height: 44px;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
  border-color: #e2e8f0;
}

.zd-chat-composer__input:focus {
  outline: none;
  border-color: var(--zd-blue);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05), 0 0 0 3px rgba(0, 104, 255, 0.12);
}

.zd-chat-composer__send {
  flex-shrink: 0;
  margin: 0;
}

.zd-chat-composer__send.zd-api-send-row {
  margin-top: 0;
}

.zd-chat-composer__send .zd-btn {
  min-width: 72px;
  padding: 10px 16px;
  border-radius: 12px;
}

.zd-composer-hint-inline {
  margin: 8px 0 0;
  text-align: right;
}

.zd-thread-area--active .zd-thread-header {
  border-bottom-color: #e2e8f0;
}

@media (max-width: 520px) {
  .zd-chat-composer__row {
    flex-direction: column;
    align-items: stretch;
  }

  .zd-chat-composer__send {
    align-self: flex-end;
  }
}

.zd-api-panel-title {
  margin: 0 0 12px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--zd-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.zd-qr-img {
  display: inline-block;
  border-radius: 8px;
  background: #fff;
  vertical-align: middle;
}

.zd-api-banner {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  min-height: 1.2em;
}

.zd-api-banner--error {
  color: #b45309;
}

.zd-api-field {
  flex: 1;
  min-width: 200px;
}

.zd-api-field label,
.zd-api-panel .zd-api-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--zd-muted);
  margin-bottom: 6px;
}

.zd-api-input,
.zd-msg-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--zd-border);
  border-radius: 10px;
  font: inherit;
  background: var(--zd-surface);
}

.zd-msg-textarea {
  resize: vertical;
  min-height: 56px;
}

.zd-api-input:disabled,
.zd-msg-textarea:disabled {
  opacity: 0.65;
}

.zd-lookup-result {
  font-size: 0.8125rem;
  color: var(--zd-text);
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--zd-blue-soft);
  border-radius: 8px;
}

.zd-api-send-row {
  margin-top: 8px;
}

.zd-account-label {
  font-size: 0.8125rem;
  color: var(--zd-text);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zd-account-select {
  font: inherit;
  font-size: 0.8125rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--zd-border);
  background: var(--zd-surface);
  color: var(--zd-text);
  max-width: 220px;
}

.zd-account-select:disabled {
  opacity: 0.55;
}

.zd-btn--ghost {
  background: transparent;
  color: var(--zd-blue);
  border: 1px solid #cce0ff;
}

.zd-btn--ghost:hover {
  background: var(--zd-blue-soft);
}

.zd-btn--ghost.zd-btn--active-secret {
  border-color: rgba(0, 104, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(0, 104, 255, 0.12);
}

.zd-account-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 280px;
}

.zd-account-preview__avatar-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.zd-account-preview__img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--zd-border);
  background: var(--zd-bg);
  display: block;
}

.zd-account-preview__img[hidden],
.zd-account-preview__img:not([src]),
.zd-account-preview__img[src=""] {
  display: none !important;
}

.zd-account-preview__initials {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--zd-blue), #0047b3);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.zd-account-preview__initials[hidden] {
  display: none !important;
}

.zd-account-preview__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.zd-account-preview__name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--zd-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zd-account-preview__uid {
  font-size: 0.6875rem;
  color: var(--zd-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* Modal đăng nhập QR (+ TK mới) */
.zd-login-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.zd-login-modal[hidden] {
  display: none !important;
}

.zd-login-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.zd-login-modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--zd-surface);
  border-radius: var(--zd-radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--zd-border);
  padding: 20px 22px 24px;
}

.zd-login-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.zd-login-modal__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.zd-login-modal__close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--zd-bg);
  color: var(--zd-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.zd-login-modal__close:hover {
  background: var(--zd-border);
  color: var(--zd-text);
}

.zd-login-modal__hint {
  margin: 0 0 12px;
  font-size: 0.8125rem;
  color: var(--zd-muted);
}

.zd-login-modal__qr {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

.zd-login-modal__status {
  margin: 12px 0 0;
  font-size: 0.8125rem;
  color: var(--zd-text);
  text-align: center;
  min-height: 1.25em;
}
