/* ============================================================
   COC CONNECT — Customer WhatsApp-Style CSS
   ============================================================ */

:root{
  --wa-green:#25d366;
  --wa-green-dark:#128c7e;
  --wa-green-darker:#075e54;
  --wa-bg:#efeae2;
  --wa-sidebar:#ffffff;
  --wa-card:#ffffff;
  --wa-text:#111b21;
  --wa-muted:#667781;
  --wa-border:#e9edef;
  --wa-hover:#f5f6f6;
  --wa-bubble-in:#ffffff;
  --wa-bubble-out:#d9fdd3;
  --wa-badge:#25d366;
  --wa-shadow: 0 1px 3px rgba(0,0,0,.06);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 150ms ease;
}

body.coc-customer{
  background: var(--wa-bg);
  color: var(--wa-text);
  margin: 0;
}

/* ============ Layout ============ */
.coc-app{
  display: grid;
  grid-template-columns: 350px 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}
.coc-sidebar{
  background: var(--wa-sidebar);
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.coc-main{
  background: var(--wa-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ============ Search ============ */
.coc-search{
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--wa-border);
}
.coc-search input{
  width: 100%;
  box-sizing: border-box;
  padding: 9px 14px 9px 38px;
  border: none;
  background: var(--wa-hover);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667781' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.coc-search input:focus{
  background-color: #fff;
  box-shadow: 0 0 0 2px rgba(37,211,102,.2);
}

/* ============ Chat List ============ */
.coc-chatlist{
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #ced4d8 transparent;
}
.coc-chatlist::-webkit-scrollbar{ width: 6px; }
.coc-chatlist::-webkit-scrollbar-thumb{ background: #ced4d8; border-radius: 3px; }

.coc-chat{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--wa-border);
  transition: background var(--transition);
  text-decoration: none;
  color: inherit;
  position: relative;
}
.coc-chat:hover{ background: var(--wa-hover); }
.coc-chat.active{ background: #f0f2f5; }
.coc-chat.unread .coc-chat__preview{ color: var(--wa-text); font-weight: 500; }
.coc-chat.unread .coc-chat__time{ color: var(--wa-green); font-weight: 600; }

.coc-chat__icon{
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--wa-green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
  position: relative;
}
.coc-chat__icon .badge{
  position: absolute;
  top: -2px; right: -2px;
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  padding: 1px 5px;
  border: 2px solid #fff;
}

.coc-chat__body{ flex: 1; min-width: 0; }
.coc-chat__row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.coc-chat__name{
  font-weight: 600;
  font-size: 15px;
  color: var(--wa-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.coc-chat__time{
  font-size: 11.5px;
  color: var(--wa-muted);
  flex-shrink: 0;
}
.coc-chat__preview{
  font-size: 13px;
  color: var(--wa-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.coc-chat__status{
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
  flex-shrink: 0;
}
.coc-chat__status.pending{ background: #fff4d6; color: #8a6d00; }
.coc-chat__status.done{ background: #e7f8ee; color: var(--wa-green-dark); }

/* ============ Conversation Header ============ */
.coc-conv-header{
  background: #fff;
  padding: 10px 16px;
  border-bottom: 1px solid var(--wa-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.coc-conv-header .coc-chat__icon{ width: 40px; height: 40px; font-size: 16px; }
.coc-conv-header .coc-conv-title{
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.coc-conv-header .coc-conv-sub{
  font-size: 12px;
  color: var(--wa-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.coc-conv-header .coc-back{
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--wa-text);
  padding: 4px 8px;
  display: none;
  margin-left: -6px;
}

/* ============ Messages ============ */
.coc-messages{
  flex: 1;
  overflow-y: auto;
  padding: 16px 4%;
  background-color: var(--wa-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cpath d='M0 50 Q 25 25 50 50 T 100 50' fill='none' stroke='%23e0ddd5' stroke-width='0.5' opacity='0.5'/%3E%3C/svg%3E");
  background-size: 100px 100px;
  scrollbar-width: thin;
  scrollbar-color: #ced4d8 transparent;
}
.coc-messages::-webkit-scrollbar{ width: 6px; }
.coc-messages::-webkit-scrollbar-thumb{ background: #ced4d8; border-radius: 3px; }

.coc-date-sep{
  text-align: center;
  margin: 14px 0;
  font-size: 11.5px;
  color: var(--wa-muted);
}
.coc-date-sep span{
  background: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: var(--wa-shadow);
}

.coc-msg{
  display: flex;
  margin-bottom: 4px;
  animation: cocMsgIn .18s ease;
}
@keyframes cocMsgIn{
  from{ opacity: 0; transform: translateY(4px); }
  to{ opacity: 1; transform: translateY(0); }
}
.coc-msg.out{ justify-content: flex-end; }
.coc-msg.in{ justify-content: flex-start; }

.coc-bubble{
  max-width: 75%;
  padding: 8px 12px 6px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: var(--wa-shadow);
}
.coc-msg.out .coc-bubble{
  background: var(--wa-bubble-out);
  border-top-right-radius: 3px;
}
.coc-msg.in .coc-bubble{
  background: var(--wa-bubble-in);
  border-top-left-radius: 3px;
}
.coc-msg .coc-sender{
  font-size: 11.5px;
  font-weight: 600;
  color: var(--wa-green-dark);
  margin-bottom: 2px;
  display: block;
}
.coc-msg .coc-time{
  font-size: 10.5px;
  color: var(--wa-muted);
  text-align: right;
  margin-top: 3px;
  display: block;
}
.coc-msg .coc-attach{
  margin-top: 6px;
}
.coc-msg .coc-attach img{
  max-width: 240px;
  border-radius: 8px;
  display: block;
}
.coc-msg .coc-attach a{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: rgba(0,0,0,.06);
  border-radius: 6px;
  font-size: 12.5px;
  color: inherit;
  text-decoration: none;
}

/* ============ Composer ============ */
.coc-composer{
  background: #f0f0f0;
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--wa-border);
  flex-shrink: 0;
}
.coc-composer__input{
  flex: 1;
  background: #fff;
  border-radius: 22px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.coc-composer__input textarea{
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14.5px;
  max-height: 100px;
  min-height: 22px;
  line-height: 1.4;
  background: transparent;
  color: var(--wa-text);
}
.coc-composer__btn{
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--wa-green);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition);
  flex-shrink: 0;
}
.coc-composer__btn:hover{ background: var(--wa-green-dark); transform: scale(1.05); }
.coc-composer__btn:disabled{ opacity: .5; cursor: not-allowed; }
.coc-composer__btn.ghost{
  background: transparent;
  color: var(--wa-muted);
  width: 38px; height: 38px;
}
.coc-composer__btn.ghost:hover{ background: rgba(0,0,0,.05); }

/* ============ Empty states ============ */
.coc-empty{
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--wa-muted);
  padding: 30px;
}
.coc-empty .emoji{
  font-size: 64px;
  margin-bottom: 16px;
  opacity: .7;
}
.coc-empty h3{ margin: 0 0 6px; font-size: 20px; color: var(--wa-text); }
.coc-empty p{ margin: 0; font-size: 14px; }

/* ============ Spinner ============ */
.coc-spinner{
  display: inline-block;
  width: 22px; height: 22px;
  border: 2.5px solid #ced4d8;
  border-top-color: var(--wa-green);
  border-radius: 50%;
  animation: cocSpin .8s linear infinite;
}
@keyframes cocSpin{ to{ transform: rotate(360deg); } }

.coc-loading{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  color: var(--wa-muted);
  font-size: 13.5px;
}

/* ============ Bottom Nav (mobile) ============ */
.coc-bottom-nav{
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--wa-border);
  justify-content: space-around;
  padding: 8px 0 10px;
  z-index: 90;
  box-shadow: 0 -2px 8px rgba(0,0,0,.05);
}
.coc-bottom-nav a{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--wa-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 8px;
  transition: color var(--transition);
}
.coc-bottom-nav a .icon{ font-size: 20px; }
.coc-bottom-nav a.active{ color: var(--wa-green-dark); font-weight: 600; }

/* ============ Toast ============ */
.coc-toast-wrap{
  position: fixed;
  top: 70px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
  pointer-events: none;
}
.coc-toast{
  background: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  font-size: 14px;
  color: var(--wa-text);
  border-left: 4px solid var(--wa-green);
  max-width: 320px;
  pointer-events: auto;
  animation: cocToastIn .25s ease;
}
.coc-toast.error{ border-left-color: #f04438; }
.coc-toast.info{ border-left-color: #3b82f6; }
@keyframes cocToastIn{
  from{ transform: translateX(30px); opacity: 0; }
  to{ transform: translateX(0); opacity: 1; }
}

/* ============ Mobile ≤ 768px ============ */
@media (max-width: 768px){
  .coc-app{
    grid-template-columns: 1fr;
    height: calc(100vh - 52px);
  }
  .coc-sidebar{
    border-right: none;
    display: flex;
  }
  .coc-main{
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    background: var(--wa-bg);
  }
  body.coc-chat-open .coc-sidebar{ display: none; }
  body.coc-chat-open .coc-main{ display: flex; }

  .coc-back{ display: flex !important; }

  .coc-chat__icon{ width: 44px; height: 44px; font-size: 16px; }
  .coc-chat__name{ font-size: 14px; }
  .coc-bubble{ max-width: 85%; font-size: 14.5px; }
  .coc-messages{ padding: 12px 8px; }

  .coc-toast-wrap{ left: 12px; right: 12px; top: 60px; }
  .coc-toast{ max-width: none; }
}

/* ============ Dark Mode ============ */
@media (prefers-color-scheme: dark){
  :root{
    --wa-bg:#0b141a;
    --wa-sidebar:#111b21;
    --wa-card:#202c33;
    --wa-text:#e9edef;
    --wa-muted:#8696a0;
    --wa-border:#222d34;
    --wa-hover:#202c33;
    --wa-bubble-in:#202c33;
    --wa-bubble-out:#005c4b;
  }
  .coc-search input{ background-color: var(--wa-card); color: var(--wa-text); }
  .coc-composer{ background: #202c33; }
  .coc-composer__input{ background: #2a3942; }
  .coc-composer__input textarea{ color: var(--wa-text); }
  .coc-chat.unread .coc-chat__preview{ color: var(--wa-text); }
  .coc-date-sep span{ background: #182229; color: var(--wa-muted); }
  .coc-conv-header{ background: var(--wa-card); }
  .coc-bottom-nav{ background: var(--wa-sidebar); }
  .coc-header{ background: #1f2c33; }
  .coc-msg .coc-attach a{ background: rgba(255,255,255,.06); }
}