* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f0f2f5;
  color: #111b21;
}
.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #075e54;
}
.login-box {
  background: #fff;
  padding: 32px;
  border-radius: 10px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-box h1 { font-size: 20px; margin: 0 0 12px; text-align: center; }
.login-box input {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}
.login-box button {
  margin-top: 12px;
  padding: 10px;
  background: #25d366;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
}
.error-text { color: #d32f2f; font-size: 13px; min-height: 16px; }
.hint-text { color: #667781; font-size: 12px; margin: 0 0 4px; }

/* App shell */
.app-shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  background: #075e54;
  color: #fff;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.tag { background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.topbar-right button {
  margin-left: 8px;
  background: #128c7e;
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.new-conv-bar { padding: 8px 16px; background: #fff; border-bottom: 1px solid #ddd; display: flex; gap: 10px; align-items: center; }
.new-conv-bar button {
  background: #25d366;
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}
.search-input {
  flex: 1;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 20px;
  font-size: 13px;
}

.column-search { display: none; }
.columns-row.searching .column:not(.column-search) { display: none; }
.columns-row.searching .column-search { display: flex; width: 320px; }

.columns-toolbar { padding: 8px 16px; background: #fff; border-bottom: 1px solid #ddd; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar-label { font-size: 12px; color: #667781; }
.col-toggle { padding: 6px 12px; border: 1px solid #ccc; background: #f5f5f5; border-radius: 14px; font-size: 12px; cursor: pointer; color: #555; }
.col-toggle.active { background: #075e54; border-color: #075e54; color: #fff; }
.column-hidden { display: none !important; }

.columns-row { flex: 1; display: flex; overflow: hidden; }
.column {
  width: 240px;
  border-right: 1px solid #ddd;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.column h2 { font-size: 13px; padding: 10px 12px; margin: 0; background: #f7f7f7; border-bottom: 1px solid #eee; text-transform: uppercase; color: #555; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.conv-item:hover { background: #f5f5f5; }
.conv-item.active { background: #e7fce3; }
.conv-item.pinned { background: #fff8e1; }
.conv-item.pinned.active { background: #e7fce3; }
.conv-item-row { display: flex; gap: 8px; align-items: flex-start; }
.conv-item-body { flex: 1; min-width: 0; }
.conv-item-top { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.conv-item-flags { display: flex; gap: 2px; margin-left: auto; }
.flag-btn { background: none; border: none; cursor: pointer; font-size: 13px; opacity: 0.3; padding: 0 2px; line-height: 1; }
.flag-btn:hover { opacity: 0.7; }
.flag-btn.active { opacity: 1; }
.priority-badge { background: #ffdede; color: #c0392b; font-size: 11px; padding: 2px 6px; border-radius: 8px; }

.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #ddd; }
.avatar-xs { width: 26px; height: 26px; }
.avatar-sm { width: 36px; height: 36px; }
.avatar-lg { width: 40px; height: 40px; }
.avatar-placeholder { display: flex; align-items: center; justify-content: center; font-size: 14px; color: #999; }
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.conv-item-preview { font-size: 12px; color: #667781; margin: 2px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-dot { background: #25d366; color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 6px; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 8px; }
.badge-gray { background: #e0e0e0; color: #555; }
.badge-orange { background: #ffe0b2; color: #a05a00; }
.badge-green { background: #c8f7d0; color: #1a7a34; }

.chat-panel { flex: 1; display: flex; flex-direction: column; background: #efeae2; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #999; }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { background: #f7f7f7; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ddd; }
.chat-sub { font-size: 12px; color: #667781; }
.chat-actions button { margin-left: 6px; padding: 6px 10px; border: none; border-radius: 6px; background: #128c7e; color: #fff; cursor: pointer; }
.chat-actions button:disabled { background: #aaa; cursor: not-allowed; }
.chat-actions button.chat-toggle-btn { background: #eee; color: #555; }
.chat-actions button.chat-toggle-btn.active-toggle { background: #ffb300; color: #3a2a00; }

.context-menu {
  position: fixed;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  min-width: 220px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 4px;
}
.context-menu button {
  background: none;
  border: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: #111b21;
}
.context-menu button:hover { background: #f0f2f5; }
.context-menu button.context-menu-danger { color: #c0392b; }
.context-menu button.context-menu-danger:hover { background: #fdecea; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 60%; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.msg-in { background: #fff; align-self: flex-start; }
.msg-out { background: #d9fdd3; align-self: flex-end; }
.msg-sender { font-size: 12px; font-weight: bold; color: #128c7e; margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; }
.msg-time { font-size: 10px; color: #999; text-align: right; margin-top: 2px; }
.msg-media-img, .msg-media-video { max-width: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg-media-audio { display: block; margin-bottom: 4px; }
.msg-media-doc { display: block; margin-bottom: 4px; color: #075e54; text-decoration: none; }

.msg-row { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg-row-in { align-self: flex-start; }
.msg-row-out { align-self: flex-end; }
.msg-row-out .msg { align-self: flex-end; }

.attachment-bar { background: #fff; border-top: 1px solid #ddd; padding: 8px 16px; display: flex; gap: 8px; align-items: center; }
.attachment-bar input { flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 6px; }
.attachment-bar button { padding: 8px 12px; border: none; border-radius: 6px; cursor: pointer; }
#attachment-send { background: #25d366; color: #fff; }
#attachment-cancel { background: #eee; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 16px; background: #f0f0f0; }
.composer textarea {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid #ccc;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}
.composer button[type=submit] { background: #25d366; color: #fff; border: none; padding: 10px 16px; border-radius: 20px; cursor: pointer; }
.icon-btn { background: #fff; border: 1px solid #ccc; border-radius: 50%; width: 38px; height: 38px; cursor: pointer; font-size: 16px; }
.icon-btn.recording { background: #ff4d4d; color: #fff; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; padding: 20px; border-radius: 8px; width: 340px; display: flex; flex-direction: column; gap: 8px; }
.modal-box-large { width: 560px; max-height: 80vh; overflow-y: auto; }
.modal-box input, .modal-box select { padding: 8px; border: 1px solid #ccc; border-radius: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.modal-actions button { padding: 8px 14px; border: none; border-radius: 6px; cursor: pointer; }
#new-conv-confirm, #transfer-confirm { background: #25d366; color: #fff; }

.modal-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab-btn { padding: 8px 12px; border: none; background: #eee; border-radius: 6px 6px 0 0; cursor: pointer; }
.tab-btn.active { background: #075e54; color: #fff; }
.inline-form { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.collab-form { align-items: center; }
.checkbox-label { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table td { padding: 6px 4px; border-bottom: 1px solid #eee; font-size: 13px; }

.wa-ok { color: #1a7a34; font-weight: bold; }
.wa-warn { color: #a05a00; }
.wa-qr { max-width: 260px; display: block; margin-top: 10px; border: 1px solid #ddd; border-radius: 6px; }

.automsg-form { display: flex; flex-direction: column; gap: 6px; }
.automsg-form h4 { margin: 10px 0 2px; font-size: 13px; color: #075e54; }
.automsg-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.automsg-form textarea { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 6px; font-family: inherit; resize: vertical; }
.automsg-form input[type=time] { padding: 6px; border: 1px solid #ccc; border-radius: 6px; }
