/* ============================================
   TIMEOFF MANAGER — LIVE CHAT WIDGET
   ============================================ */

/* ── Reset for widget scope ── */
.tom-chat *, .tom-chat *::before, .tom-chat *::after { box-sizing: border-box; margin: 0; padding: 0; }
.tom-chat { font-family: 'Figtree', system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5; color: #333; }

/* ── Floating Trigger Button ── */
.tom-chat-trigger {
  position: fixed; bottom: 24px; right: 24px; z-index: 9990;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 22px; background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff; border: none; border-radius: 50px;
  cursor: pointer; font-family: inherit; font-size: .88rem;
  font-weight: 600; letter-spacing: .3px;
  box-shadow: 0 6px 28px rgba(79,70,229,.35);
  transition: all .3s; outline: none;
}
.tom-chat-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 36px rgba(79,70,229,.45);
}
.tom-chat-trigger svg { flex-shrink: 0; }
.tom-chat-trigger .trigger-label { white-space: nowrap; }
.tom-chat-trigger .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #6b7280;
  flex-shrink: 0; transition: background .3s;
}
.tom-chat-trigger .status-dot.online { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.5); }
.tom-chat-trigger .unread-badge {
  display: none; position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: #dc2626; color: #fff; border-radius: 50px;
  font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.tom-chat-trigger .unread-badge:empty, .tom-chat-trigger .unread-badge[data-count="0"] { display: none; }

/* ── Chat Panel ── */
.tom-chat-panel {
  position: fixed; bottom: 24px; right: 24px; z-index: 9995;
  width: 380px; max-height: 560px; height: calc(100vh - 120px);
  background: #fff; border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
  display: none; flex-direction: column; overflow: hidden;
  animation: tomChatSlideUp .3s ease;
}
.tom-chat-panel.open { display: flex; }
@keyframes tomChatSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ── Panel Header ── */
.tom-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; background: #4f46e5; color: #fff;
  flex-shrink: 0;
}
.tom-chat-header .ch-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #818cf8, #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  flex-shrink: 0; overflow: hidden;
}
.tom-chat-header .ch-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.tom-chat-header .ch-avatar .ch-avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-weight: 700; font-size: .85rem; color: #fff;
}
.tom-chat-header .ch-info { flex: 1; min-width: 0; }
.tom-chat-header .ch-name { font-weight: 600; font-size: .9rem; }
.tom-chat-header .ch-status {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; color: rgba(255,255,255,.7); margin-top: 1px;
}
.tom-chat-header .ch-status .status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #6b7280;
  flex-shrink: 0;
}
.tom-chat-header .ch-status .status-dot.online { background: #22c55e; }
.tom-chat-header .ch-actions { display: flex; gap: 4px; }
.tom-chat-header .ch-actions button {
  width: 32px; height: 32px; border: none; background: rgba(255,255,255,.1);
  color: #fff; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; font-size: 0;
}
.tom-chat-header .ch-actions button:hover { background: rgba(255,255,255,.2); }

/* ── Pre-Chat Form ── */
.tom-prechat {
  flex: 1; display: flex; flex-direction: column;
  padding: 28px 22px; overflow-y: auto;
}
.tom-prechat h3 {
  font-size: 1.1rem; color: #1a1a1a;
  margin-bottom: 6px;
}
.tom-prechat p { font-size: .82rem; color: #999; margin-bottom: 20px; }
.tom-prechat .pc-field { margin-bottom: 14px; }
.tom-prechat .pc-field label {
  display: block; font-size: .72rem; font-weight: 600;
  color: #666; text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 4px;
}
.tom-prechat .pc-field input {
  width: 100%; padding: 10px 12px; border: 1px solid #e5e7eb;
  border-radius: 8px; font-size: 16px; font-family: inherit;
  background: #f9fafb; color: #333; outline: none;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
.tom-prechat .pc-field input:focus {
  border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.1);
  background: #fff;
}
.tom-prechat .pc-field .pc-error {
  font-size: .72rem; color: #dc2626; margin-top: 3px; display: none;
}
.tom-prechat .pc-submit {
  width: 100%; padding: 12px; background: #4f46e5; color: #fff;
  border: none; border-radius: 30px; font-size: .88rem;
  font-weight: 600; letter-spacing: .5px; cursor: pointer;
  font-family: inherit; transition: background .2s; margin-top: 6px;
}
.tom-prechat .pc-submit:hover { background: #4338ca; }
.tom-prechat .pc-offline-note {
  font-size: .78rem; color: #92400e; background: #fffbeb;
  padding: 10px 14px; border-radius: 8px; margin-top: 12px;
  border-left: 3px solid #d97706;
}
.tom-prechat .pc-offline-note.hidden { display: none; }

/* ── Messages Area ── */
.tom-messages {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
  background: #f9fafb;
}
.tom-messages::-webkit-scrollbar { width: 4px; }
.tom-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.tom-msg {
  max-width: 80%; padding: 10px 14px;
  border-radius: 14px; font-size: .88rem;
  line-height: 1.5; word-wrap: break-word;
  animation: tomMsgIn .2s ease;
}
@keyframes tomMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.tom-msg.visitor {
  align-self: flex-end; background: #4f46e5; color: #fff;
  border-bottom-right-radius: 4px;
}
.tom-msg.admin {
  align-self: flex-start; background: #fff; color: #333;
  border: 1px solid #e5e7eb; border-bottom-left-radius: 4px;
}
.tom-msg .msg-sender {
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .3px; margin-bottom: 2px; opacity: .7;
}
.tom-msg .msg-time {
  font-size: .65rem; opacity: .6; margin-top: 4px;
  text-align: right;
}
.tom-msg.admin .msg-time { text-align: left; }

/* Attachment in message */
.tom-msg .msg-attachment {
  margin-top: 8px; display: block;
}
.tom-msg .msg-attachment img {
  max-width: 100%; max-height: 200px;
  border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(0,0,0,.08);
}
.tom-msg .msg-attachment .file-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: rgba(0,0,0,.05);
  border-radius: 6px; font-size: .78rem; font-weight: 500;
  color: inherit; text-decoration: none;
}
.tom-msg.visitor .msg-attachment .file-link { background: rgba(255,255,255,.2); color: #fff; }

/* System messages */
.tom-msg-system {
  text-align: center; font-size: .72rem; color: #999;
  padding: 4px 0;
}

/* Typing indicator */
.tom-typing {
  display: none; align-self: flex-start;
  padding: 10px 14px; background: #fff; border: 1px solid #e5e7eb;
  border-radius: 14px; border-bottom-left-radius: 4px;
  margin: 0 18px;
}
.tom-typing.visible { display: flex; gap: 4px; align-items: center; }
.tom-typing span {
  width: 6px; height: 6px; background: #bbb; border-radius: 50%;
  animation: tomDot 1.4s infinite;
}
.tom-typing span:nth-child(2) { animation-delay: .2s; }
.tom-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tomDot { 0%,60%,100% { opacity: .3; transform: scale(.8); } 30% { opacity: 1; transform: scale(1); } }

/* ── Input Bar ── */
.tom-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 14px; border-top: 1px solid #e5e7eb;
  background: #fff; flex-shrink: 0;
}
.tom-input-bar .attach-btn {
  width: 36px; height: 36px; border: none;
  background: #f3f4f6; color: #999; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: all .2s;
}
.tom-input-bar .attach-btn:hover { background: #e5e7eb; color: #666; }
.tom-input-bar textarea {
  flex: 1; resize: none; border: 1px solid #e5e7eb;
  border-radius: 10px; padding: 8px 12px; font-size: 16px;
  font-family: inherit; outline: none; background: #f9fafb;
  min-height: 36px; max-height: 100px; line-height: 1.4;
  transition: border-color .2s;
  -webkit-appearance: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
.tom-input-bar textarea:focus {
  font-size: 16px;
}
.tom-input-bar textarea:focus { border-color: #4f46e5; background: #fff; }
.tom-input-bar .send-btn {
  width: 36px; height: 36px; border: none;
  background: #4f46e5; color: #fff; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: all .2s;
}
.tom-input-bar .send-btn:hover { background: #4338ca; }
.tom-input-bar .send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Attachment preview in input */
.tom-attach-preview {
  display: none; padding: 8px 14px; border-top: 1px solid #e5e7eb;
  background: #f9fafb; flex-shrink: 0;
}
.tom-attach-preview.visible { display: flex; align-items: center; gap: 8px; }
.tom-attach-preview .ap-name { flex: 1; font-size: .78rem; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tom-attach-preview .ap-size { font-size: .72rem; color: #999; }
.tom-attach-preview .ap-remove {
  width: 24px; height: 24px; border: none; background: #fee2e2;
  color: #dc2626; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; flex-shrink: 0;
}

/* ── End Chat Bar ── */
.tom-end-bar {
  display: none;
  padding: 6px 14px 10px;
  justify-content: center;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}
.tom-end-btn {
  background: none;
  border: 1px solid #e5e7eb;
  color: #999;
  font-size: .72rem;
  padding: 4px 14px;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.tom-end-btn:hover {
  border-color: #dc2626;
  color: #dc2626;
  background: #fef2f2;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .tom-chat {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
  }
  .tom-chat-trigger {
    pointer-events: auto;
    position: fixed;
    bottom: 16px; right: 16px;
    padding: 12px; border-radius: 50%;
    z-index: 9999;
  }
  .tom-chat-trigger .trigger-label { display: none; }
  .tom-chat-trigger .status-dot { position: absolute; top: -1px; right: -1px; width: 10px; height: 10px; border: 2px solid #4f46e5; }
  /* Must stay display:none until .open — otherwise mobile viewports (incl. GSC smartphone) show full-screen chat over the page */
  .tom-chat-panel {
    pointer-events: auto;
    position: fixed;
    top: 0; bottom: 0; right: 0; left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
    padding-top: env(safe-area-inset-top, 0px);
    box-sizing: border-box;
    overflow: hidden;
    display: none;
    flex-direction: column;
    touch-action: pan-y;
    -webkit-text-size-adjust: 100%;
  }
  .tom-chat-panel.open {
    display: flex;
  }
  .tom-chat-panel .tom-chat-header {
    position: relative;
    top: 0;
    z-index: 2;
    flex-shrink: 0;
  }
  .tom-chat-panel .tom-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tom-chat-panel .tom-prechat {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tom-chat-panel .tom-input-bar {
    flex-shrink: 0;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    background: #fff;
    border-top: 1px solid #e5e7eb;
  }
  /* Prevent iOS zoom on input focus */
  .tom-chat-panel .tom-input-bar textarea,
  .tom-chat-panel .tom-prechat input {
    font-size: 16px !important;
    transform: none !important;
    touch-action: manipulation !important;
    -webkit-text-size-adjust: 100% !important;
  }
  .tom-chat-panel .tom-end-bar {
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 6px);
  }
  .tom-chat-panel .tom-attach-preview {
    flex-shrink: 0;
  }
  .tom-chat-panel .tom-typing {
    flex-shrink: 0;
    margin: 0 12px 8px;
  }
  /* Prevent body scroll when chat is open */
  body.tom-chat-open {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: none;
  }
}
@media (min-width: 481px) and (max-width: 768px) {
  .tom-chat-panel { width: 340px; max-width: calc(100vw - 32px); }
  .tom-chat-trigger { padding: 12px 16px; font-size: .82rem; }
}
