:root {
    --green-900: #075e54;
    --green-800: #0b6b5f;
    --green-700: #128c7e;
    --green-100: #dcf8c6;
    --ink: #17211f;
    --muted: #68736f;
    --line: #d8dedb;
    --panel: #f7f9f8;
    --chat-bg: #efe7d8;
    --white: #ffffff;
    --danger: #b42318;
    --shadow: 0 14px 40px rgba(18, 32, 28, 0.18);
    font-family: Arial, Helvetica, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    color: var(--ink);
    background: #dbe4e0;
}

button,
input,
textarea {
    font: inherit;
}

.login-body {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: 24px;
    background:
        linear-gradient(180deg, var(--green-900) 0 34%, #dfe8e4 34% 100%);
}

.login-card {
    width: min(420px, 100%);
    padding: 30px;
    border-radius: 8px;
    background: var(--white);
    box-shadow: var(--shadow);
}

.login-brand,
.brand-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark,
.avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: var(--white);
    background: var(--green-900);
    font-weight: 700;
    letter-spacing: 0;
}

.brand-mark {
    flex: 0 0 auto;
}

.login-brand h1,
.brand-row h1,
.chat-title h2 {
    margin: 0;
    font-size: 18px;
}

.login-brand p,
.brand-row p,
.chat-title p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.login-error {
    margin: 22px 0 0;
    padding: 11px 12px;
    border: 1px solid #f2b8b5;
    border-radius: 6px;
    color: var(--danger);
    background: #fff4f2;
}

.login-form {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

.login-form label {
    display: grid;
    gap: 7px;
    color: #34423e;
    font-size: 13px;
    font-weight: 700;
}

.login-form input,
.search-wrap input,
.composer textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    outline: none;
    background: var(--white);
}

.login-form input {
    height: 44px;
    padding: 0 12px;
}

.login-form input:focus,
.search-wrap input:focus,
.composer textarea:focus {
    border-color: var(--green-700);
    box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.14);
}

.login-form button,
.composer button {
    min-height: 44px;
    border: 0;
    border-radius: 6px;
    color: var(--white);
    background: var(--green-900);
    font-weight: 700;
    cursor: pointer;
}

.login-form button:hover,
.composer button:hover {
    background: var(--green-800);
}

.app-body {
    overflow: hidden;
}

.app-shell {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    height: 100vh;
    background: var(--panel);
}

.sidebar {
    display: grid;
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    min-width: 0;
    border-right: 1px solid var(--line);
    background: var(--white);
}

.sidebar-header,
.chat-header {
    display: flex;
    align-items: center;
    min-height: 68px;
    padding: 12px 16px;
    background: #f0f4f2;
    border-bottom: 1px solid var(--line);
}

.sidebar-header {
    justify-content: space-between;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button,
.mobile-back {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 6px;
    color: #2c3935;
    background: transparent;
    text-decoration: none;
    cursor: pointer;
}

.icon-button:hover,
.mobile-back:hover {
    background: #e3ebe7;
}

.search-wrap {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: var(--white);
}

.search-wrap input {
    height: 40px;
    padding: 0 12px;
    background: #f5f7f6;
}

.status-strip {
    min-height: 30px;
    padding: 7px 14px;
    color: var(--muted);
    background: #fbfcfb;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
}

.admin-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 32px;
    padding: 7px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    background: #ffffff;
    font-size: 12px;
}

.admin-tools a {
    color: var(--green-900);
    font-weight: 700;
    text-decoration: none;
}

.admin-tools span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
}

/* Prevent any single child from blowing out the fixed 360px sidebar. */
.sidebar { overflow-x: hidden; }
.sidebar-header { overflow: hidden; }
.header-actions { flex: 0 0 auto; }

.chat-list {
    overflow-y: auto;
}

.chat-list-item {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    min-height: 78px;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid #edf0ef;
    text-align: left;
    background: var(--white);
    cursor: pointer;
}

.chat-list-item:hover,
.chat-list-item.active {
    background: #edf5f2;
}

.avatar.small {
    width: 44px;
    height: 44px;
    font-size: 13px;
    background: #82918c;
}

.chat-list-main {
    min-width: 0;
}

.chat-list-top,
.chat-list-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-list-top strong,
.chat-list-bottom span,
.chat-number {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-list-top strong {
    font-size: 15px;
}

.chat-list-top time,
.chat-number {
    color: var(--muted);
    font-size: 12px;
}

.chat-list-bottom {
    margin-top: 5px;
}

.chat-list-bottom span {
    color: #4c5a56;
    font-size: 13px;
}

.chat-list-bottom em {
    display: grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    color: var(--white);
    background: var(--green-700);
    font-size: 12px;
    font-style: normal;
    font-weight: 700;
}

.chat-number {
    display: block;
    margin-top: 3px;
}

.empty-list {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    height: 100vh;
}

.chat-header {
    position: sticky;
    top: 0;
    z-index: 4;
    gap: 12px;
}

.mobile-back {
    display: none;
    font-size: 24px;
}

.chat-title {
    min-width: 0;
    flex: 1;
}

.chat-title h2,
.chat-title p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-health {
    color: var(--muted);
    font-size: 12px;
}

.messages-view,
.chat-messages {
    position: relative;
    overflow-y: auto;
    padding: 18px 32px 20px;
    background-color: var(--chat-bg);
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.24) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.18) 1px, transparent 1px);
    background-size: 36px 36px;
}

.empty-state {
    display: grid;
    place-items: center;
    align-content: center;
    height: 100%;
    max-width: 420px;
    margin: 0 auto;
    color: #3f4c48;
    text-align: center;
}

.empty-mark {
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    margin-bottom: 18px;
    border-radius: 50%;
    color: var(--white);
    background: var(--green-900);
    font-size: 34px;
    font-weight: 700;
}

.empty-state h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

.date-separator {
    width: max-content;
    max-width: 90%;
    margin: 12px auto;
    padding: 6px 12px;
    border-radius: 6px;
    color: #5d6a66;
    background: #f6f0e7;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    font-size: 12px;
}

.message-row {
    display: flex;
    margin: 7px 0;
}

.message-row.incoming {
    justify-content: flex-start;
}

.message-row.outgoing {
    justify-content: flex-end;
}

.system-note-row {
    width: max-content;
    max-width: 84%;
    margin: 10px auto;
    padding: 7px 12px;
    border-radius: 999px;
    color: #5c6763;
    background: rgba(255, 255, 255, 0.68);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    font-size: 12px;
    text-align: center;
}

.bubble {
    max-width: min(620px, 74%);
    padding: 8px 10px 6px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.incoming .bubble {
    background: var(--white);
    border-top-left-radius: 3px;
}

.outgoing .bubble {
    background: var(--green-100);
    border-top-right-radius: 3px;
}

.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.42;
    font-size: 14px;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 4px;
    color: #66716d;
    font-size: 11px;
}

.message-meta span {
    color: var(--green-800);
}

.media-bubble {
    display: grid;
    gap: 8px;
}

.media-bubble img,
.media-bubble video {
    display: block;
    max-width: min(320px, 62vw);
    max-height: 380px;
    border-radius: 6px;
    background: #e4e7e5;
}

.media-bubble audio {
    width: min(320px, 62vw);
}

.voice-label {
    color: #32413c;
    font-weight: 700;
    font-size: 13px;
}

.media-caption {
    overflow-wrap: anywhere;
    line-height: 1.35;
    font-size: 14px;
}

.media-file-label {
    color: #53605c;
    overflow-wrap: anywhere;
    font-size: 12px;
}

.media-placeholder,
.document-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 230px;
    max-width: min(320px, 62vw);
    padding: 12px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.62);
    color: #31413c;
}

.media-placeholder small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.document-card {
    text-decoration: none;
}

.doc-icon {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 6px;
    color: var(--white);
    background: #58666b;
    font-size: 11px;
    font-weight: 700;
}

.document-card strong,
.document-card small {
    display: block;
}

.document-card strong {
    overflow-wrap: anywhere;
}

.document-card small {
    margin-top: 3px;
    color: var(--muted);
}

.media-download,
.media-retry {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    max-width: 100%;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid rgba(7, 94, 84, 0.22);
    border-radius: 6px;
    color: var(--green-900);
    background: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.media-download:hover,
.media-retry:hover {
    background: #ffffff;
}

.media-retry:disabled {
    cursor: wait;
    opacity: 0.65;
}

.new-message-indicator {
    position: sticky;
    bottom: 12px;
    display: none;
    margin: 0 auto;
    padding: 8px 14px;
    border: 0;
    border-radius: 999px;
    color: var(--white);
    background: var(--green-800);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.new-message-indicator.visible {
    display: block;
}

.composer {
    position: sticky;
    bottom: 0;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 92px;
    gap: 10px;
    padding: 12px 16px;
    background: #f0f4f2;
    border-top: 1px solid var(--line);
}

.composer textarea {
    min-height: 44px;
    max-height: 140px;
    resize: none;
    padding: 12px 14px;
    line-height: 1.35;
}

.composer button:disabled,
.composer textarea:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

@media (max-width: 760px) {
    .app-shell {
        display: block;
        height: 100dvh;
        overflow: hidden;
    }

    .sidebar,
    .chat-panel {
        width: 100%;
        height: 100dvh;
    }

    .chat-panel {
        display: none;
    }

    .app-shell.chat-open .sidebar {
        display: none;
    }

    .app-shell.chat-open .chat-panel {
        display: grid;
    }

    .mobile-back {
        display: grid;
    }

    .messages-view {
        padding: 14px 10px 18px;
    }

    .bubble {
        max-width: 88%;
    }

    .media-bubble img,
    .media-bubble video,
    .media-placeholder,
    .document-card {
        max-width: min(240px, 72vw);
    }

    .media-bubble audio {
        width: min(240px, 72vw);
    }

    .composer {
        grid-template-columns: minmax(0, 1fr) 74px;
        padding: 10px;
    }

    .sidebar-header,
    .chat-header {
        min-height: 62px;
        padding: 10px 12px;
    }
}


/* === Delete controls (UMERAL admin extension) === */
.chat-list-item { position: relative; }
.chat-list-item .chat-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(120,130,127,.55);
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
  user-select: none;
}
.chat-list-item:hover .chat-delete,
.chat-list-item:focus-within .chat-delete { opacity: 1; }
.chat-list-item .chat-delete:hover { background: #c0392b; }

.bubble { position: relative; }
.bubble .message-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(120,130,127,.7);
  font-size: 16px;
  cursor: pointer;
  border: 0;
  padding: 0;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.message-row:hover .bubble .message-delete,
.bubble:focus-within .message-delete { opacity: 1; }
.bubble .message-delete:hover { background: #c0392b; }


/* === Block button (UMERAL admin extension) === */
.chat-header { display: flex; align-items: center; gap: 10px; }
.block-button {
  background: #c0392b;
  color: #fff;
  border: 0;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .85rem;
  cursor: pointer;
  font-weight: 500;
  transition: background .15s;
}
.block-button:hover { background: #a93223; }
.block-button.is-blocked { background: #1f9b4f; }
.block-button.is-blocked:hover { background: #178040; }
.block-button:disabled { opacity: .6; cursor: not-allowed; }

.chat-template-button {
  background: var(--green-900);
  color: #fff;
  border: 0;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.chat-template-button:hover { background: var(--green-800); }
.chat-template-button[hidden] { display: none !important; }


/* === Composer attach button + preview (UMERAL admin extension) === */
/* Now 4-column grid: [attach 44px] [emoji 44px] [textarea 1fr] [send 92px] */
.composer {
  grid-template-columns: 44px 44px minmax(0, 1fr) 92px !important;
  align-items: center;
  position: relative;
}
@media (max-width: 760px) {
  .composer {
    grid-template-columns: 40px 40px minmax(0, 1fr) 74px !important;
    gap: 6px;
  }
}
.composer .attach-button {
  background: transparent;
  border: 0;
  color: var(--green-700, #128c7e);
  font-size: 22px;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background .15s, transform .15s, opacity .15s;
}
.composer .attach-button:hover:not(:disabled) {
  transform: scale(1.08);
  background: rgba(18, 140, 126, 0.1);
}
.composer .attach-button:disabled { opacity: .35; cursor: not-allowed; }

.attach-preview {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f0f6f4;
  border: 1px solid #cfe0d8;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .9rem;
  color: #1c3a31;
}
.attach-preview[hidden] { display: none !important; }
.attach-preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; padding-right: 8px; }
.attach-preview-clear {
  background: rgba(0,0,0,.05);
  border: 0;
  border-radius: 50%;
  width: 22px; height: 22px; line-height: 20px;
  font-size: 16px;
  cursor: pointer;
  color: #555;
  padding: 0;
  min-height: 0;
}
.attach-preview-clear:hover { background: #c0392b; color: #fff; }


/* === Rename contact pencil button (UMERAL admin extension) === */
.chat-title h2 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.rename-button {
  background: transparent;
  border: 0;
  color: #68736f;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
  opacity: .55;
  transition: opacity .15s, background .15s, color .15s;
}
.rename-button:hover {
  opacity: 1;
  background: rgba(0,0,0,.05);
  color: var(--green-700, #128c7e);
}
.rename-button:focus-visible {
  outline: 2px solid var(--green-700, #128c7e);
  outline-offset: 2px;
}


/* === Emoji picker (UMERAL admin extension) === */
.composer .emoji-button {
  background: transparent;
  border: 0;
  color: var(--green-700, #128c7e);
  font-size: 22px;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background .15s, transform .15s, opacity .15s;
}
.composer .emoji-button:hover:not(:disabled) {
  transform: scale(1.08);
  background: rgba(18, 140, 126, 0.1);
}
.composer .emoji-button:disabled { opacity: .35; cursor: not-allowed; }

.emoji-panel {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 12px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border: 1px solid var(--line, #d8dedb);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.18);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.emoji-panel[hidden] { display: none !important; }

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--line, #d8dedb);
}
.emoji-tab {
  flex: 1;
  background: transparent;
  border: 0;
  font-size: 20px;
  padding: 8px 0 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  line-height: 1;
  transition: background .12s, border-color .12s;
  min-height: 0;
  color: inherit;
}
.emoji-tab:hover { background: rgba(0,0,0,.04); }
.emoji-tab.is-active {
  border-bottom-color: var(--green-700, #128c7e);
  background: rgba(18, 140, 126, .08);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-cell {
  background: transparent;
  border: 0;
  font-size: 22px;
  padding: 6px 0;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
  min-height: 0;
  color: inherit;
  transition: background .1s, transform .1s;
}
.emoji-cell:hover {
  background: rgba(18, 140, 126, .12);
  transform: scale(1.15);
}
.emoji-cell:focus-visible {
  outline: 2px solid var(--green-700, #128c7e);
  outline-offset: 1px;
}

@media (max-width: 760px) {
  .emoji-panel { width: calc(100vw - 24px); left: 12px; right: 12px; }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); max-height: 200px; }
}


/* === Template messaging (UMERAL admin extension) === */
.template-tag {
  display: inline-block;
  margin-bottom: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--green-700);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.tpl-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tpl-modal[hidden] { display: none !important; }

.tpl-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 21, 0.45);
}

.tpl-modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tpl-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #f0f4f2;
  border-bottom: 1px solid var(--line);
}
.tpl-modal-head h2 { margin: 0; font-size: 18px; color: var(--ink); }

.tpl-modal-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #51605b;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.tpl-modal-close:hover { background: #e3ebe7; }

.tpl-modal-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}
.tpl-synced { color: var(--muted); font-size: 12px; }

.tpl-modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}
.tpl-hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.tpl-field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: #34423e;
  font-size: 13px;
  font-weight: 700;
}
.tpl-field input,
.tpl-field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
  font-weight: 400;
  outline: none;
}
.tpl-field input:focus,
.tpl-field select:focus {
  border-color: var(--green-700);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.14);
}

.tpl-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.tpl-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: #eaf3ef;
  color: var(--green-900);
  font-size: 12px;
  font-weight: 700;
}
.tpl-chip[hidden] { display: none !important; }

.tpl-preview {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #d6e6df;
  background: var(--green-100);
  color: #1c3a31;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tpl-preview[hidden] { display: none !important; }

.tpl-variables { display: grid; gap: 0; }

.tpl-message {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.tpl-message[hidden] { display: none !important; }
.tpl-message.is-error { background: #fff4f2; border: 1px solid #f2b8b5; color: var(--danger); }
.tpl-message.is-success { background: #ecf8ef; border: 1px solid #b6e3c4; color: #1f7a44; }
.tpl-message.is-info { background: #fef8e8; border: 1px solid #f1dca0; color: #8a6a16; }

.tpl-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}
.tpl-foot-actions { display: flex; gap: 10px; }

.tpl-btn-primary,
.tpl-btn-secondary {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}
.tpl-btn-primary {
  border: 0;
  background: var(--green-900);
  color: #fff;
}
.tpl-btn-primary:hover { background: var(--green-800); }
.tpl-btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.tpl-btn-secondary {
  border: 1px solid var(--line);
  background: var(--white);
  color: #34423e;
}
.tpl-btn-secondary:hover { background: #eef3f1; }
.tpl-btn-secondary:disabled { opacity: .6; cursor: not-allowed; }

.tpl-link {
  border: 0;
  background: transparent;
  color: var(--green-900);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
}
.tpl-link:hover { text-decoration: underline; }
.tpl-link:disabled { opacity: .6; cursor: not-allowed; }

.tpl-settings-list { display: grid; gap: 12px; }
.tpl-empty { padding: 24px; text-align: center; color: var(--muted); }

.tpl-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--white);
}
.tpl-card.is-unsupported { background: #fafafa; opacity: .92; }
.tpl-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.tpl-card-top strong { font-size: 15px; overflow-wrap: anywhere; }

.tpl-badge {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}
.tpl-badge.ok { background: #e3f6e9; color: #1f7a44; }
.tpl-badge.warn { background: #fef3d6; color: #8a6a16; }
.tpl-badge.bad { background: #fde7e5; color: var(--danger); }

.tpl-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.tpl-card-tags span {
  padding: 2px 8px;
  border-radius: 6px;
  background: #f1f4f3;
  color: #4c5a56;
  font-size: 11px;
  font-weight: 600;
}
.tpl-card-tags .tpl-supported { background: #e3f6e9; color: #1f7a44; }
.tpl-card-tags .tpl-unsupported { background: #fde7e5; color: var(--danger); }

.tpl-card-preview {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f6f0e7;
  color: #3a463f;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tpl-card-reason {
  margin-top: 6px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 760px) {
  .tpl-modal { padding: 0; }
  .tpl-modal-card { width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .tpl-modal-foot { flex-direction: column-reverse; align-items: stretch; }
  .tpl-foot-actions { justify-content: space-between; }
  .tpl-foot-actions .tpl-btn-primary,
  .tpl-foot-actions .tpl-btn-secondary { flex: 1; }
}
