﻿/* WaPanel — single-operator WhatsApp Cloud API console.
   Light theme only, by product decision. */

:root {
  --wa-teal: #075e54;
  --wa-teal-dark: #054c44;
  --wa-green: #25d366;
  --wa-green-dark: #128c7e;
  --wa-chat-bg: #efeae2;
  --wa-bubble-in: #ffffff;
  --wa-bubble-out: #d9fdd3;
  --wa-panel: #ffffff;
  --wa-border: #e4e6e8;
  --wa-muted: #667781;
  --wa-ink: #111b21;
  --wa-hover: #f5f6f6;
  --wa-read: #53bdeb;
  --wa-active: #f0f2f5;

  --nav-w: 232px;
  --list-w: 360px;
  --info-w: 320px;
  --topbar-h: 56px;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--wa-ink);
  background: var(--wa-active);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.925rem;
}

a { text-decoration: none; }

/* ------------------------------------------------------------------ shell */

.app-shell {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.app-nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--wa-teal);
  color: #d7ded9;
  display: flex;
  flex-direction: column;
}

.app-nav .brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 1rem;
  color: #fff;
  font-weight: 600;
  letter-spacing: .01em;
  background: var(--wa-teal-dark);
  flex: 0 0 auto;
}

.app-nav .brand i { font-size: 1.35rem; color: var(--wa-green); }

.app-nav .nav-scroll { overflow-y: auto; padding: .5rem 0; flex: 1 1 auto; }

.app-nav a.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  color: #d7ded9;
  border-left: 3px solid transparent;
  white-space: nowrap;
}

.app-nav a.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }

.app-nav a.nav-item.active {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border-left-color: var(--wa-green);
}

.app-nav a.nav-item i { width: 1.25rem; text-align: center; font-size: 1.05rem; }

.app-nav .nav-badge {
  margin-left: auto;
  background: var(--wa-green);
  color: #06231c;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  padding: .05rem .45rem;
}

.app-nav .nav-foot {
  flex: 0 0 auto;
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, .12);
  font-size: .8rem;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--wa-active);
}

.app-topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  background: var(--wa-panel);
  border-bottom: 1px solid var(--wa-border);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
}

.app-topbar .page-title { font-weight: 600; font-size: 1.02rem; margin: 0; }

.app-body { flex: 1 1 auto; min-height: 0; overflow: auto; }

.app-body.is-flush { overflow: hidden; }

.content-pad { padding: 1.25rem; }

/* Mobile: the nav becomes an off-canvas drawer. */
.nav-toggle { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 991.98px) {
  .nav-toggle { display: inline-flex; }

  .app-nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1045;
    transform: translateX(-100%);
    transition: transform .18s ease-out;
  }

  .app-shell.nav-open .app-nav { transform: none; }

  .app-shell.nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(0, 0, 0, .35);
  }
}

/* ------------------------------------------------------------------ cards */

.stat-card {
  background: var(--wa-panel);
  border: 1px solid var(--wa-border);
  border-radius: .6rem;
  padding: .9rem 1rem;
  height: 100%;
}

.stat-card .stat-label {
  color: var(--wa-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .2rem;
}

.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }

.stat-card .stat-sub { color: var(--wa-muted); font-size: .8rem; }

.panel {
  background: var(--wa-panel);
  border: 1px solid var(--wa-border);
  border-radius: .6rem;
}

.panel > .panel-head {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--wa-border);
  font-weight: 600;
}

.panel > .panel-body { padding: 1rem; }

/* ------------------------------------------------------------------ inbox */

.inbox {
  display: flex;
  height: 100%;
  min-height: 0;
}

.inbox-list {
  width: var(--list-w);
  flex: 0 0 var(--list-w);
  background: var(--wa-panel);
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inbox-list .list-head {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--wa-border);
  flex: 0 0 auto;
}

.inbox-list .list-scroll { overflow-y: auto; flex: 1 1 auto; }

.conv-item {
  display: flex;
  gap: .7rem;
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--wa-border);
  cursor: pointer;
  color: inherit;
}

.conv-item:hover { background: var(--wa-hover); }
.conv-item.active { background: var(--wa-active); }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--wa-green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex: 0 0 auto;
  text-transform: uppercase;
}

.avatar.sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar.lg { width: 76px; height: 76px; font-size: 1.6rem; }

.conv-main { min-width: 0; flex: 1 1 auto; }
.conv-top { display: flex; align-items: baseline; gap: .5rem; }
.conv-name { font-weight: 600; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--wa-muted); font-size: .72rem; flex: 0 0 auto; }
.conv-preview { color: var(--wa-muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.unread-pill {
  background: var(--wa-green);
  color: #06231c;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  padding: .05rem .4rem;
}

.inbox-thread {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--wa-chat-bg);
  min-height: 0;
}

.thread-head {
  flex: 0 0 auto;
  background: var(--wa-panel);
  border-bottom: 1px solid var(--wa-border);
  padding: .5rem .75rem;
  display: flex;
  align-items: center;
  gap: .7rem;
}

.thread-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.thread-compose {
  flex: 0 0 auto;
  background: var(--wa-panel);
  border-top: 1px solid var(--wa-border);
  padding: .6rem .75rem;
}

.inbox-info {
  width: var(--info-w);
  flex: 0 0 var(--info-w);
  background: var(--wa-panel);
  border-left: 1px solid var(--wa-border);
  overflow-y: auto;
}

@media (max-width: 1199.98px) {
  .inbox-info { display: none; }
}

@media (max-width: 767.98px) {
  .inbox-list { width: 100%; flex: 1 1 auto; border-right: 0; }
  .inbox-thread { display: none; }

  /* On a phone the thread takes the whole screen, WhatsApp style. */
  .inbox.show-thread .inbox-list { display: none; }
  .inbox.show-thread .inbox-thread { display: flex; }
}

/* --------------------------------------------------------------- bubbles */

.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: min(78%, 560px);
  background: var(--wa-bubble-in);
  border-radius: .5rem;
  padding: .4rem .6rem .3rem;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.out .bubble { background: var(--wa-bubble-out); }

.bubble .bubble-text { white-space: pre-wrap; }
.bubble .bubble-text code { font-family: var(--bs-font-monospace); font-size: .85em; color: inherit; background: rgba(0, 0, 0, .06); padding: 0 .2em; border-radius: .2rem; }
.bubble .bubble-header { font-weight: 600; margin-bottom: .2rem; white-space: pre-wrap; }
.bubble .bubble-footer,
.bubble .bubble-subtext { color: var(--wa-muted); font-size: .8rem; margin-top: .2rem; white-space: pre-wrap; }
.bubble .reply-kind { color: var(--wa-muted); font-size: .72rem; margin-top: .15rem; }

/* A sent template's buttons, WhatsApp style: full-width rows under the text. Display only. */
.bubble .bubble-buttons { margin: .35rem -.6rem -.3rem; }
.bubble .bubble-button {
  border-top: 1px solid rgba(0, 0, 0, .08);
  color: #0a7ea4;
  text-align: center;
  padding: .4rem .6rem;
  font-size: .9rem;
  cursor: default;
}
.bubble .bubble-button .bi { margin-right: .3rem; }

.bubble .bubble-meta {
  display: flex;
  align-items: center;
  gap: .25rem;
  justify-content: flex-end;
  color: var(--wa-muted);
  font-size: .68rem;
  margin-top: .1rem;
}

.bubble.failed { background: #fdecea; }

/* Delivery ticks: big enough to read at a glance (~17px) while the time beside them stays small. */
.bubble .msg-status {
  display: inline-flex;
  align-items: center;
  font-size: 1.1rem;
  line-height: 1;
  margin-left: .1rem;
  color: var(--wa-muted);
  transition: color .2s ease;
}
.bubble .msg-status .bi::before { vertical-align: 0; }
.bubble .msg-status.status-sending { font-size: .95rem; }
.bubble .msg-status.status-read { color: var(--wa-read); }
.bubble .msg-status.status-failed { color: var(--bs-danger); }
.bubble .bubble-meta { min-height: 1.1rem; }

.bubble-media img,
.bubble-media video {
  max-width: 100%;
  border-radius: .35rem;
  display: block;
}

.bubble-detail {
  margin-top: .35rem;
  border-top: 1px dashed var(--wa-border);
  padding-top: .3rem;
  font-size: .72rem;
  color: var(--wa-muted);
}

.bubble-detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .1rem .5rem; }
.bubble-detail dt { font-weight: 600; }
.bubble-detail dd { margin: 0; overflow-wrap: anywhere; }

.day-divider {
  align-self: center;
  background: rgba(255, 255, 255, .85);
  border-radius: .5rem;
  padding: .15rem .6rem;
  font-size: .72rem;
  color: var(--wa-muted);
  margin: .5rem 0;
}

/* ---------------------------------------------------- service window chip */

.window-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border-radius: 999px;
  padding: .15rem .6rem;
  font-size: .78rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.window-chip.open { background: #e7f7ec; color: #0f5132; border-color: #badbcc; }
.window-chip.warn { background: #fff4d6; color: #7a5a00; border-color: #ffe08a; }
.window-chip.closed { background: #fdecea; color: #842029; border-color: #f5c2c7; }

.window-banner {
  background: #fdecea;
  border-top: 1px solid #f5c2c7;
  color: #842029;
  padding: .75rem;
}

.window-banner.warn { background: #fff4d6; border-top-color: #ffe08a; color: #7a5a00; }

/* ------------------------------------------------------------------ misc */

.text-muted-sm { color: var(--wa-muted); font-size: .82rem; }

.btn-wa { background: var(--wa-green-dark); border-color: var(--wa-green-dark); color: #fff; }
.btn-wa:hover, .btn-wa:focus { background: var(--wa-teal); border-color: var(--wa-teal); color: #fff; }

.tag-chip {
  display: inline-block;
  border-radius: 999px;
  padding: .05rem .5rem;
  font-size: .74rem;
  font-weight: 600;
  color: #fff;
}

/* Contact panel tags: removable chips and the "+ Etiket ekle" picker. */
.tag-chip-removable { display: inline-flex; align-items: center; gap: .25rem; padding-right: .25rem; }
.tag-chip .tag-remove {
  border: 0;
  background: rgba(0, 0, 0, .18);
  color: #fff;
  border-radius: 50%;
  width: 1.05rem;
  height: 1.05rem;
  line-height: 1;
  font-size: .85rem;
  padding: 0;
}
.tag-chip .tag-remove:hover { background: rgba(0, 0, 0, .35); }
.tag-picker { width: min(16rem, 90vw); }
.tag-picker-list { max-height: 14rem; overflow-y: auto; }
.tag-dot { width: .6rem; height: .6rem; border-radius: 50%; flex: 0 0 auto; }

.empty-state { text-align: center; color: var(--wa-muted); padding: 3rem 1rem; }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }

.drop-target { outline: 3px dashed var(--wa-green-dark); outline-offset: -8px; }

.table-sticky thead th { position: sticky; top: 0; background: var(--wa-panel); z-index: 2; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; }

/* ---- Template previews (WhatsApp-like) ------------------------------------------------ */

.tpl-preview {
  background: var(--wa-chat-bg);
  padding: .75rem;
  border-radius: .5rem;
}

.tpl-preview .bubble { max-width: 100%; }

.tpl-media-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  aspect-ratio: 1.91 / 1;
  border-radius: .35rem;
  background: #cfd8dc;
  color: #455a64;
  font-size: .85rem;
  margin-bottom: .4rem;
}

.tpl-media-slot i { font-size: 1.8rem; }

.tpl-media-img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: .35rem;
  margin-bottom: .4rem;
}

.tpl-buttons .bubble { color: #0a7ea4; text-align: center; }

.tpl-card { cursor: pointer; }
.tpl-card:has(input:checked) { outline: 2px solid var(--wa-green-dark); }
.tpl-card .tpl-kind { font-size: .8rem; }

.image-drop {
  border: 2px dashed var(--wa-border);
  border-radius: .5rem;
  padding: 1.5rem;
  text-align: center;
  background: #fafafa;
  cursor: pointer;
}

.image-drop.dragover { border-color: var(--wa-green-dark); background: #e7f7ec; }

/* Inbox template dialog: one list for "Template gönder" and "Yeni mesaj". */
.ts-template-list { max-height: 18rem; overflow-y: auto; }
.ts-template-list .list-group-item.active { background: #e7f7ec; color: inherit; border-color: var(--wa-green-dark); }
.ts-template-list .list-group-item:disabled { opacity: .65; }
.tpl-preview-host { background: var(--wa-chat-bg); max-height: 28rem; overflow-y: auto; }

/* ---- Realtime inbox ------------------------------------------------------------------- */

.live-status { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; color: var(--wa-muted); }
.live-status .live-dot { width: .5rem; height: .5rem; border-radius: 50%; background: #adb5bd; }
.live-status[data-state="connected"] .live-dot { background: #25d366; }
.live-status[data-state="reconnecting"] .live-dot,
.live-status[data-state="connecting"] .live-dot { background: #f0ad4e; }
.live-status[data-state="disconnected"] .live-dot { background: #dc3545; }

.inbox-thread { position: relative; }

.new-messages-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 5.5rem;
  z-index: 5;
  border: 0;
  border-radius: 1rem;
  padding: .3rem .8rem;
  font-size: .8rem;
  background: var(--wa-green-dark);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}

.nav-badge[hidden], .new-messages-pill[hidden] { display: none !important; }

/* Template group sorting: a grip in the group header, the group floats while dragged and a
   dashed slot shows where it will land. */
.group-handle {
  border: 0; background: transparent; color: var(--wa-muted); padding: .1rem .2rem; margin-left: -.25rem;
  line-height: 1; border-radius: .25rem; touch-action: none; font-size: 1.1rem;
}
/* Beats Bootstrap's [type=button]:not(:disabled) { cursor: pointer }. */
.group-handle:not(:disabled) { cursor: grab; }
.group-handle:hover:not(:disabled), .group-handle:focus-visible { color: var(--wa-ink); background: var(--wa-hover); }
.group-handle:disabled { cursor: default; opacity: .35; }
/* A finger needs a bigger target than a mouse. */
@media (pointer: coarse) { .group-handle { padding: .55rem .6rem; margin: -.4rem 0 -.4rem -.5rem; font-size: 1.25rem; } }
.group-dragging {
  position: fixed; z-index: 1050; margin: 0 !important;
  box-shadow: 0 .6rem 1.5rem rgba(17, 27, 33, .18); outline: 2px solid var(--wa-green-dark); opacity: .96;
}
.group-drop-slot {
  border: 2px dashed var(--wa-green-dark); border-radius: .5rem; background: rgba(37, 211, 102, .06);
  margin-bottom: 1rem;
}
body.group-sorting, body.group-sorting * { cursor: grabbing !important; user-select: none; }

/* Template body toolbar: a small emoji grid under the buttons. */
.emoji-picker {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(7, 2.2rem);
  gap: .15rem;
  padding: .35rem;
  margin-top: .25rem;
  background: #fff;
  border: 1px solid var(--bs-border-color);
  border-radius: .4rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.emoji-picker[hidden] { display: none; }
.emoji-picker .btn { font-size: 1.05rem; line-height: 1; padding: .3rem 0; }
.tpl-preview .bubble-text code { font-family: var(--bs-font-monospace); font-size: .85em; color: inherit; background: rgba(0, 0, 0, .06); padding: 0 .2em; border-radius: .2rem; }
