/* assets/css/templates.css */

.page-wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 72px 24px 60px;
}

.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 600; margin-bottom: 2px; }
.page-sub { font-size: 13.5px; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────── */
.btn {
    font-family: inherit; font-size: 13px; font-weight: 500;
    padding: 8px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-dark); background: var(--white);
    color: var(--text); cursor: pointer; transition: all .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 15px; color: var(--text-muted); padding: 4px 6px; border-radius: var(--radius-sm); }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-icon.small { font-size: 13px; padding: 2px 4px; }

/* ── Loading ──────────────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 0; color: var(--text-muted); font-size: 13.5px; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 0; color: var(--text-faint); }

/* ── Badges ───────────────────────────────────── */
.badge {
    font-size: 11px; font-weight: 500; padding: 3px 8px;
    border-radius: 999px; letter-spacing: .02em;
}
.badge.active { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge.inactive { background: var(--bg); color: var(--text-faint); border: 1px solid var(--border); }

/* ── Template cards ───────────────────────────── */
.tpl-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tpl-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    transition: box-shadow .15s, opacity .15s;
}
.tpl-card:hover { box-shadow: var(--shadow-md); }
.tpl-card.off { opacity: .5; }

.tpl-top {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 12px;
}

.tpl-type-row { display: flex; align-items: baseline; gap: 8px; }
.tpl-type-label { font-size: 15px; font-weight: 600; color: var(--text); }
.tpl-type-code {
    font-size: 11px; font-family: 'SFMono-Regular', ui-monospace, monospace;
    color: var(--text-faint); background: var(--bg);
    padding: 2px 6px; border-radius: 4px;
}

/* ── Message preview ──────────────────────────── */
.tpl-preview {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 180px;
    overflow-y: auto;
}

.placeholder {
    display: inline-block;
    background: #dbeafe;
    color: #1d4ed8;
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 12px;
    font-weight: 500;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid #93c5fd;
    cursor: help;
}

/* ── Param chips ──────────────────────────────── */
.tpl-params {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.param-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 8px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
}

.param-chip .param-num {
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 11px;
    color: #1d4ed8;
    font-weight: 500;
}

/* ── Footer row ───────────────────────────────── */
.tpl-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.tpl-gupshup {
    font-size: 11px;
    color: var(--text-faint);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gupshup-label { margin-right: 4px; }
.tpl-gupshup code {
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 11px;
}

.tpl-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Toggle ───────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute; inset: 0; background: var(--border-dark);
    border-radius: 11px; transition: background .2s;
}
.toggle-slider::before {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 16px; height: 16px; background: var(--white);
    border-radius: 50%; transition: transform .2s;
    box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.toggle input:checked + .toggle-slider { background: #10b981; }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Modal ────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 200; display: flex; align-items: center;
    justify-content: center; padding: 24px;
}
.modal {
    background: var(--white); border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto;
}
.modal-lg { max-width: 620px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 0;
}
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-muted); cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px 24px; }

/* ── Forms ────────────────────────────────────── */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea {
    width: 100%; padding: 8px 10px; font-size: 13px; font-family: inherit;
    color: var(--text); border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm); background: var(--white); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    border-color: var(--text); box-shadow: 0 0 0 3px rgba(17,19,24,.08);
}
.form-row textarea {
    resize: vertical;
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 12.5px;
    line-height: 1.6;
}
.hint { font-size: 11px; color: var(--text-faint); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error {
    display: none; font-size: 13px; color: var(--danger);
    background: var(--danger-bg); border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 14px;
}
.form-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }

/* ── Param rows in modal ──────────────────────── */
.param-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.param-num-label {
    font-family: 'SFMono-Regular', ui-monospace, monospace;
    font-size: 12px;
    color: #1d4ed8;
    font-weight: 500;
    min-width: 32px;
}

.param-row select {
    flex: 1;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-family: inherit;
    color: var(--text);
    background: var(--white);
    outline: none;
}

.param-row .p-custom {
    width: 140px;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    font-family: inherit;
    color: var(--text);
    background: var(--white);
}

/* ── Preview box in modal ─────────────────────── */
.tpl-preview-box {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
}

@media (max-width: 640px) {
    .page-header { flex-direction: column; gap: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .tpl-footer { flex-direction: column; align-items: flex-start; }
    .modal-lg { max-width: 100%; }
    .param-row { flex-wrap: wrap; }
}