/* ---------------------------------------------------------------------------
   WhatsApp templates, as a page.

   Scoped entirely behind [data-wiq="tplpage"], which only exists while our
   module has the content area. Nothing here can reach a vendor screen: if the
   module never mounts, not one rule in this file matches anything.

   Colours come from the theme's tokens with literal fallbacks, so the page
   still renders if whatsiq-theme.css is ever not loaded.
   --------------------------------------------------------------------------- */

[data-wiq="tplpage"] {
  --tp-sheet: var(--wiq-sheet, #fff);
  --tp-edge: var(--wiq-border, #e6e9e5);
  --tp-rule: var(--wiq-rule, #eff1ee);
  --tp-raised: var(--wiq-raised, #f7f8f6);
  --tp-hover: var(--wiq-hover, #e9ede8);
  --tp-ink: var(--wiq-head, #1c231d);
  --tp-muted: var(--wiq-muted, #667065);
  --tp-accent: var(--wiq-primary, #1f7a52);
  --tp-r: var(--wiq-r-card, 14px);
  --tp-rc: var(--wiq-r-ctl, 10px);

  padding: 24px 28px 48px;
  font-family: var(--wiq-font, inherit);
  color: var(--tp-ink);
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}

[data-wiq="tplpage"] *,
[data-wiq="tplpage"] *::before,
[data-wiq="tplpage"] *::after { box-sizing: border-box; }

/* ---- header ---------------------------------------------------------- */
.tp-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.tp-head h1 { font-size: 21px; line-height: 1.25; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.tp-head p { margin: 0; font-size: 13px; color: var(--tp-muted); }
.tp-head .tp-grow { flex: 1 1 240px; min-width: 0; }
.tp-headacts { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- buttons --------------------------------------------------------- */
.tp-btn {
  appearance: none; border: 1px solid var(--tp-edge); background: var(--tp-sheet);
  color: var(--tp-ink); font: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: var(--tp-rc); cursor: pointer; line-height: 1.4;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.tp-btn:hover:not(:disabled) { background: var(--tp-hover); }
.tp-btn:disabled { opacity: .55; cursor: not-allowed; }
.tp-btn-primary { background: var(--tp-accent); border-color: var(--tp-accent); color: #fff; }
.tp-btn-primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--tp-accent); }
.tp-btn-sm { padding: 5px 10px; font-size: 12px; }
.tp-btn-danger { color: var(--wiq-negative, #b3261e); }

/* ---- stat tiles ------------------------------------------------------ */
.tp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tp-stat { background: var(--tp-sheet); border: 1px solid var(--tp-edge); border-radius: var(--tp-r); padding: 14px 16px; }
.tp-stat b { display: block; font-size: 24px; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
.tp-stat span { font-size: 12px; color: var(--tp-muted); }

/* ---- toolbar --------------------------------------------------------- */
.tp-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.tp-bar input[type="search"], .tp-bar select { min-height: 38px; }
.tp-bar .tp-search { flex: 1 1 260px; min-width: 0; }

/* ---- fields ---------------------------------------------------------- */
.tp-field { display: block; margin-bottom: 14px; }
.tp-field > span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--tp-ink); }
.tp-field > small { display: block; font-size: 11.5px; color: var(--tp-muted); margin-top: 4px; line-height: 1.5; }
[data-wiq="tplpage"] input, [data-wiq="tplpage"] select, [data-wiq="tplpage"] textarea,
[data-wiq="tplmodal"] input, [data-wiq="tplmodal"] select, [data-wiq="tplmodal"] textarea {
  width: 100%; font: inherit; font-size: 13px; color: var(--tp-ink);
  background: var(--tp-sheet); border: 1px solid var(--tp-edge);
  border-radius: var(--tp-rc); padding: 9px 11px; min-height: 38px;
}
[data-wiq="tplpage"] textarea, [data-wiq="tplmodal"] textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
[data-wiq="tplpage"] input:focus, [data-wiq="tplpage"] select:focus, [data-wiq="tplpage"] textarea:focus,
[data-wiq="tplmodal"] input:focus, [data-wiq="tplmodal"] select:focus, [data-wiq="tplmodal"] textarea:focus {
  outline: 2px solid var(--tp-accent); outline-offset: -1px; border-color: var(--tp-accent);
}
.tp-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }

/* ---- table ----------------------------------------------------------- */
.tp-tablewrap { background: var(--tp-sheet); border: 1px solid var(--tp-edge); border-radius: var(--tp-r); overflow-x: auto; }
.tp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tp-table th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--tp-muted); padding: 11px 16px;
  border-bottom: 1px solid var(--tp-edge); background: var(--tp-raised); white-space: nowrap;
}
.tp-table td { padding: 12px 16px; border-bottom: 1px solid var(--tp-rule); vertical-align: top; }
.tp-table tr:last-child td { border-bottom: 0; }
.tp-table tbody tr:hover { background: var(--tp-raised); }
.tp-name { font-weight: 600; word-break: break-word; }
.tp-body { color: var(--tp-muted); font-size: 12.5px; line-height: 1.55; max-width: 460px; white-space: pre-wrap; word-break: break-word; }
.tp-nowrap { white-space: nowrap; }

/* ---- status pills ---------------------------------------------------- */
.tp-pill {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px; text-transform: uppercase; white-space: nowrap;
  border: 1px solid transparent;
}
.tp-pill-approved { background: #e6f4ec; color: #15603f; border-color: #c7e6d6; }
.tp-pill-pending  { background: #fdf3e0; color: #8a5a07; border-color: #f3e0bd; }
.tp-pill-rejected { background: #fdeceb; color: #a3261e; border-color: #f5cfcc; }
.tp-pill-other    { background: var(--tp-raised); color: var(--tp-muted); border-color: var(--tp-edge); }

/* ---- form panel ------------------------------------------------------ */
.tp-panel { background: var(--tp-sheet); border: 1px solid var(--tp-edge); border-radius: var(--tp-r); padding: 20px 22px; margin-bottom: 18px; }
.tp-panel > h2 { font-size: 16px; font-weight: 700; margin: 0 0 3px; }
.tp-panel > h2 + p { margin: 0 0 18px; font-size: 12.5px; color: var(--tp-muted); }
.tp-sub { font-size: 13px; font-weight: 700; margin: 20px 0 10px; padding-top: 16px; border-top: 1px solid var(--tp-rule); }
.tp-sub:first-of-type { border-top: 0; padding-top: 0; }
.tp-item { border: 1px solid var(--tp-edge); border-radius: var(--tp-rc); padding: 14px; margin-bottom: 10px; background: var(--tp-raised); }
.tp-itemhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.tp-itemhead b { font-size: 12px; font-weight: 700; color: var(--tp-muted); text-transform: uppercase; letter-spacing: .04em; }
.tp-acts { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--tp-rule); }

/* ---- notices --------------------------------------------------------- */
.tp-note { border-radius: var(--tp-rc); padding: 11px 14px; font-size: 13px; line-height: 1.55; margin-bottom: 14px; border: 1px solid; }
.tp-note-err { background: #fdeceb; border-color: #f5cfcc; color: #8f2018; }
.tp-note-ok  { background: #e6f4ec; border-color: #c7e6d6; color: #15603f; }
.tp-note-info { background: var(--tp-raised); border-color: var(--tp-edge); color: var(--tp-muted); }

/* ---- empty / loading ------------------------------------------------- */
.tp-empty { padding: 44px 24px; text-align: center; color: var(--tp-muted); font-size: 13.5px; line-height: 1.6; }
.tp-empty b { display: block; color: var(--tp-ink); font-size: 15px; margin-bottom: 5px; font-weight: 600; }

@media (max-width: 720px) {
  [data-wiq="tplpage"] { padding: 18px 14px 40px; }
  .tp-table th:nth-child(3), .tp-table td:nth-child(3) { display: none; }
}

/* ---------------------------------------------------------------------------
   The create dialog: the vendor puts template creation in a modal with a
   preview beside it, so ours is a modal with a preview beside it. Scoped
   behind its own stamp, and appended to <body> rather than into `main`, so
   nothing the panel re-renders can take it away mid-edit.
   --------------------------------------------------------------------------- */
[data-wiq="tplmodal"] {
  position: fixed; inset: 0; z-index: 1400;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px 20px; overflow-y: auto;
  background: rgba(16, 22, 17, .45);
  font-family: var(--wiq-font, inherit);
  --tp-sheet: var(--wiq-sheet, #fff);
  --tp-edge: var(--wiq-border, #e6e9e5);
  --tp-rule: var(--wiq-rule, #eff1ee);
  --tp-raised: var(--wiq-raised, #f7f8f6);
  --tp-hover: var(--wiq-hover, #e9ede8);
  --tp-ink: var(--wiq-head, #1c231d);
  --tp-muted: var(--wiq-muted, #667065);
  --tp-accent: var(--wiq-primary, #1f7a52);
  --tp-r: var(--wiq-r-card, 14px);
  --tp-rc: var(--wiq-r-ctl, 10px);
  color: var(--tp-ink);
}
[data-wiq="tplmodal"] *, [data-wiq="tplmodal"] *::before, [data-wiq="tplmodal"] *::after { box-sizing: border-box; }

.tp-sheet {
  background: var(--tp-sheet); border-radius: var(--tp-r);
  width: 100%; max-width: 1080px; margin: auto;
  box-shadow: 0 24px 60px rgba(16, 22, 17, .22); overflow: hidden;
}
.tp-mhead { display: flex; align-items: flex-start; gap: 14px; padding: 20px 24px; border-bottom: 1px solid var(--tp-rule); }
.tp-mhead .tp-ico { flex: none; width: 38px; height: 38px; border-radius: 11px; background: var(--wiq-accent-soft, #e6f0e9); display: flex; align-items: center; justify-content: center; }
.tp-mhead .tp-ico svg { width: 20px; height: 20px; stroke: var(--tp-accent); fill: none; stroke-width: 1.8; }
.tp-mhead h2 { margin: 0 0 2px; font-size: 17px; font-weight: 700; }
.tp-mhead p { margin: 0; font-size: 12.5px; color: var(--tp-muted); line-height: 1.5; }
.tp-mhead .tp-x { margin-left: auto; flex: none; }

.tp-mbody { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 0; }
.tp-mform { padding: 22px 24px; min-width: 0; }
.tp-mside { padding: 22px 20px; border-left: 1px solid var(--tp-rule); background: var(--tp-raised); }
.tp-mside h3 { margin: 0 0 3px; font-size: 13px; font-weight: 700; }
.tp-mside > p { margin: 0 0 14px; font-size: 11.5px; color: var(--tp-muted); line-height: 1.5; }
.tp-mfoot { display: flex; gap: 10px; align-items: center; padding: 16px 24px; border-top: 1px solid var(--tp-rule); background: var(--tp-raised); }

/* ---- the phone bubble ------------------------------------------------ */
.tp-wa { background: #e6ddd4; border-radius: 12px; padding: 14px 12px; position: sticky; top: 0; }
.tp-bubble {
  background: #fff; border-radius: 8px; padding: 8px 10px 6px;
  box-shadow: 0 1px 1px rgba(0,0,0,.13); font-size: 13.2px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.tp-bubble .tp-bhead { font-weight: 700; margin-bottom: 4px; }
.tp-bubble .tp-bmedia {
  background: #cfd8cc; border-radius: 6px; height: 108px; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; color: #4d5a4c; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; white-space: normal; text-align: center; padding: 8px;
}
.tp-bubble .tp-bfoot { color: #8a8f88; font-size: 11.5px; margin-top: 5px; }
.tp-bubble .tp-btime { text-align: right; color: #8a8f88; font-size: 10.5px; margin-top: 2px; }
.tp-bbtns { margin-top: 3px; }
.tp-bbtn {
  background: #fff; border-radius: 8px; margin-top: 3px; padding: 8px;
  text-align: center; color: #0a7ea4; font-size: 13px; font-weight: 500;
  box-shadow: 0 1px 1px rgba(0,0,0,.13); white-space: normal; word-break: break-word;
}
.tp-bcards { display: flex; gap: 6px; overflow-x: auto; margin-top: 6px; padding-bottom: 4px; }
.tp-bcard { flex: none; width: 150px; }
.tp-bempty { color: #9aa199; font-style: italic; }

/* ---- variable example rows ------------------------------------------- */
.tp-vars { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 12px; }
.tp-var > span { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
.tp-varnone { font-size: 12px; color: var(--tp-muted); padding: 9px 11px; background: var(--tp-raised); border: 1px dashed var(--tp-edge); border-radius: var(--tp-rc); line-height: 1.5; }

/* ---- page chrome, matched to the vendor's screens -------------------- */
.tp-title { display: flex; align-items: center; gap: 13px; }
.tp-title .tp-ico { flex: none; width: 42px; height: 42px; border-radius: 12px; background: var(--wiq-accent-soft, #e6f0e9); display: flex; align-items: center; justify-content: center; }
.tp-title .tp-ico svg { width: 22px; height: 22px; stroke: var(--tp-accent); fill: none; stroke-width: 1.8; }
.tp-bar .tp-selwrap { flex: 0 0 190px; }
.tp-iconbtn { width: 38px; padding: 0; justify-content: center; }
.tp-iconbtn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.9; }

@media (max-width: 900px) {
  .tp-mbody { grid-template-columns: minmax(0, 1fr); }
  .tp-mside { border-left: 0; border-top: 1px solid var(--tp-rule); }
  .tp-wa { position: static; }
}

/* A file input draws its own button; the control padding above squashes it. */
[data-wiq="tplpage"] input[type="file"], [data-wiq="tplmodal"] input[type="file"] {
  padding: 7px 9px; font-size: 12.5px; background: var(--tp-raised);
}
/* The note under the example boxes belongs to the block, not to the next field. */
[data-ex] > small { display: block; font-size: 11.5px; color: var(--tp-muted); margin: 2px 0 14px; line-height: 1.5; }
/* A select needs room for its own arrow in both scopes. */
[data-wiq="tplpage"] select, [data-wiq="tplmodal"] select { padding-right: 30px; }
