:root {
    --bg-color: #101426;
    --surface-color: rgba(20, 26, 46, 0.86);
    --surface-alt: rgba(28, 33, 54, 0.9);
    --surface-muted: rgba(32, 37, 59, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text-color: #f5f7ff;
    --text-muted: #8e94b2;
    --text-subtle: #61678a;
    --primary: #4d7dff;
    --primary-hover: #3d68da;
    --secondary: #22c3aa;
    --secondary-hover: #1ba68f;
    --danger: #ff5c7c;
    --danger-hover: #e74e6f;
    --warning: #f4c361;
    --success: #4bd18b;
    --info: #5ec7ff;
    --shadow-lg: 0 32px 68px -28px rgba(10, 13, 40, 0.65);
    --shadow-md: 0 18px 40px -24px rgba(10, 13, 40, 0.6);
    --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.02), 0 16px 30px -28px rgba(8, 11, 30, 0.9);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --font-stack: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.18s ease-in-out;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

::selection {
    background: rgba(77, 125, 255, 0.35);
    color: var(--text-color);
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-stack);
    font-size: 16px;
    line-height: 1.6;
    background: linear-gradient(160deg, #0b0d1b 0%, #151a33 45%, #0e1528 100%);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    overflow-y: scroll;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--primary-hover);
}

h1,
h2,
h3,
h4 {
    margin: 0;
    font-weight: 600;
    line-height: 1.2;
}

p {
    margin: 0;
}

code {
    font-family: "JetBrains Mono", "Fira Code", "Segoe UI Mono", monospace;
    font-size: 0.85rem;
    padding: 0.15rem 0.35rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    color: var(--info);
}

.muted {
    color: var(--text-muted);
}

.text-danger {
    color: var(--danger);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-success {
    background: rgba(75, 209, 139, 0.15);
    color: #4bd18b;
}

.badge-danger {
    background: rgba(255, 92, 124, 0.15);
    color: #ff5c7c;
}

.last-sync {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
}

body.dashboard-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 1.5rem;
    padding-bottom: 2rem;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.6rem clamp(1.5rem, 4vw, 2.6rem);
    background: rgba(10, 13, 28, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(18px);
}

.branding h1 {
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    letter-spacing: 0.02em;
}

.branding .muted {
    margin-top: 0.25rem;
    font-size: 0.95rem;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.app-main {
    width: min(1160px, 92%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 3rem;
}

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: none;
    color: var(--text-color);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #3955ff);
    box-shadow: 0 12px 32px -18px rgba(77, 125, 255, 0.9);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), #314be0);
    transform: translateY(-1px);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary), #1d9e8a);
    box-shadow: 0 12px 32px -18px rgba(34, 195, 170, 0.9);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, var(--secondary-hover), #188b79);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #ff3f68);
    box-shadow: 0 12px 32px -18px rgba(255, 92, 124, 0.85);
}

.btn-danger:hover {
    background: linear-gradient(135deg, var(--danger-hover), #f03f64);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text-color);
}

.btn-outline:hover {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.08);
}

.btn-small {
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
}

.btn[disabled],
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.copy-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.8rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.copy-button:hover {
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
}

.alert {
    padding: 1.05rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.04);
    box-shadow: var(--shadow-sm);
    font-size: 0.95rem;
}

.alert-success {
    border-color: rgba(75, 209, 139, 0.35);
    background: rgba(75, 209, 139, 0.12);
    color: #49c783;
}

.alert-error {
    border-color: rgba(255, 92, 124, 0.35);
    background: rgba(255, 92, 124, 0.12);
    color: #ff5c7c;
}

.alert-warning {
    border-color: rgba(244, 195, 97, 0.35);
    background: rgba(244, 195, 97, 0.14);
    color: #f4c361;
}

.tab-controls {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: var(--shadow-sm);
    width: fit-content;
}

.tab-button {
    padding: 0.55rem 1.4rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), transform var(--transition);
}

.tab-button:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.tab-button.is-active {
    background: linear-gradient(135deg, rgba(77, 125, 255, 0.18), rgba(77, 125, 255, 0.05));
    color: var(--text-color);
    transform: translateY(-1px);
}

.tab-panel {
    display: none;
    flex-direction: column;
    gap: 1.2rem;
}

.tab-panel.is-active {
    display: flex;
}

.grid {
    display: grid;
    gap: 1rem;
}

.grid-metrics {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.card {
    position: relative;
    padding: 1.4rem;
    border-radius: var(--radius-lg);
    background: var(--surface-color);
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.card::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(145deg, rgba(77, 125, 255, 0.08), rgba(34, 195, 170, 0.04));
    opacity: 0;
    transition: opacity var(--transition);
}

.card:hover::after {
    opacity: 1;
}

.card.card-error {
    border-color: rgba(255, 92, 124, 0.25);
    background: rgba(255, 92, 124, 0.08);
}

.card-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-header.with-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.metric-card {
    gap: 0.65rem;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: var(--shadow-md);
}

.metric-card h3 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
}

.metric-card .metric-value {
    font-size: clamp(1.8rem, 3.2vw, 2.4rem);
    font-weight: 700;
    letter-spacing: 0.01em;
}

.metric-card.success {
    border-color: rgba(75, 209, 139, 0.4);
    background: rgba(75, 209, 139, 0.08);
}

.metric-card.danger {
    border-color: rgba(255, 92, 124, 0.35);
    background: rgba(255, 92, 124, 0.08);
}

.metric-card.info {
    border-color: rgba(94, 199, 255, 0.35);
    background: rgba(94, 199, 255, 0.08);
}

.list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
}

.pill-danger {
    background: rgba(255, 92, 124, 0.15);
    color: #ff5c7c;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.tag-success {
    border-color: rgba(75, 209, 139, 0.4);
    color: #4bd18b;
}

.tag-danger {
    border-color: rgba(255, 92, 124, 0.4);
    color: #ff5c7c;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.table-actions input[type="search"] {
    width: 220px;
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-color);
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.table-actions input[type="search"]:focus {
    outline: none;
    border-color: rgba(77, 125, 255, 0.6);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 0 3px rgba(77, 125, 255, 0.18);
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(12, 14, 28, 0.6);
}

.table-wrapper table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

.table-wrapper thead {
    background: rgba(255, 255, 255, 0.03);
}

.table-wrapper th,
.table-wrapper td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.9rem;
}

.table-wrapper th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
}

.table-wrapper tbody tr:hover {
    background: rgba(77, 125, 255, 0.06);
}

.table-note {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.instance-actions-row td {
    background: rgba(77, 125, 255, 0.03);
}

.instance-actions-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.inline-form.wrap {
    flex-wrap: wrap;
    align-items: flex-start;
}

.inline-form.wrap .phone-input {
    flex: 1 1 220px;
}

.instance-details {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(77, 125, 255, 0.05);
    border-radius: var(--radius-sm);
    display: grid;
    gap: 0.6rem;
}

.instance-detail-row {
    display: grid;
    gap: 0.25rem;
}

.instance-detail-row code {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

.token-scroll {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    overflow: hidden;
}

.token-scroll code {
    flex: 1 1 auto;
    padding: 0.35rem 0.5rem;
}

.instance-details .small {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.phone-form {
    gap: 0.5rem;
}

.phone-input {
    min-width: 180px;
}

.action-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.presence-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.form-grid.split-2 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group-inline {
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-group-inline input[type="checkbox"] {
    transform: scale(1.05);
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

input::placeholder,
textarea::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(77, 125, 255, 0.6);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 3px rgba(77, 125, 255, 0.18);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

select {
    appearance: none;
    color: var(--text-color);
    background-color: rgba(12, 16, 32, 0.85);
    background-image: linear-gradient(45deg, transparent 50%, rgba(255, 255, 255, 0.45) 50%), linear-gradient(135deg, rgba(255, 255, 255, 0.45) 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(50% + 2px), calc(100% - 12px) calc(50% + 2px);
    background-size: 6px 6px;
    background-repeat: no-repeat;
}

select option {
    background-color: rgba(10, 14, 28, 0.95);
    color: var(--text-color);
}

select option:checked,
select option:hover {
    background-color: rgba(77, 125, 255, 0.35);
    color: var(--text-color);
}

select option:disabled {
    background-color: rgba(10, 14, 28, 0.6);
    color: var(--text-subtle);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    accent-color: var(--primary);
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.92rem;
    color: var(--text-muted);
}

.form-note {
    font-size: 0.85rem;
    color: var(--text-subtle);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
}

.settings-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.settings-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.settings-option.full {
    grid-column: 1 / -1;
}

.settings-option strong {
    color: var(--text-color);
}

.settings-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.webhook-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.webhook-toggle-button {
    border-color: rgba(77, 125, 255, 0.35);
    color: var(--primary);
}

.webhook-config-card {
    margin-top: 1.1rem;
    padding: 1.1rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(77, 125, 255, 0.25);
    background: rgba(22, 28, 51, 0.9);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.webhook-config-card[data-webhook-fields] {
    transition: opacity var(--transition), visibility var(--transition);
}

.webhook-form textarea {
    min-height: 140px;
}

.webhook-form .form-note {
    margin-top: 0;
}

.qr-thumb {
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
    transition: transform var(--transition), filter var(--transition);
}

.qr-thumb-img {
    width: 68px;
    height: 68px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
}

.qr-thumb:hover .qr-thumb-img {
    transform: translateY(-2px);
    filter: drop-shadow(0 10px 12px rgba(77, 125, 255, 0.35));
}

.qr-token {
    display: grid;
    gap: 0.4rem;
    align-content: start;
}

.qr-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 2rem;
    background: rgba(6, 8, 20, 0.75);
    backdrop-filter: blur(14px);
    z-index: 30;
}

.qr-modal[aria-hidden="true"] {
    display: none;
}

.qr-modal-content {
    position: relative;
    background: rgba(18, 22, 40, 0.95);
    border-radius: var(--radius-lg);
    padding: 2rem;
    border: 1px solid rgba(77, 125, 255, 0.3);
    box-shadow: 0 28px 80px -40px rgba(10, 13, 40, 0.8);
    max-width: 420px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.qr-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    color: rgba(255, 255, 255, 0.65);
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: color var(--transition);
}

.qr-modal-close:hover {
    color: var(--text-color);
}

.qr-modal img {
    width: 220px;
    height: 220px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
}

.grid-bms {
    display: grid;
    grid-template-columns: minmax(320px, 360px) 1fr;
    gap: 1.5rem;
    align-items: flex-start;
}

.bm-form textarea,
.template-form textarea {
    resize: vertical;
}

.bm-list {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.bm-card {
    background: var(--surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.3rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.bm-card-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
}

.bm-card-title {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
}

.status-dot,
.template-status-dot {
    display: inline-block;
    width: 0.82rem;
    height: 0.82rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.32);
    flex-shrink: 0;
    margin-top: 0.1rem;
    margin-right: 0.35rem;
}

.status-active,
.status-approved {
    background: var(--success);
}

.status-pending {
    background: var(--warning);
}

.status-inactive {
    background: rgba(255, 255, 255, 0.35);
}

.status-error,
.status-rejected {
    background: var(--danger);
}

.bm-card-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

.bm-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
}

.bm-meta div {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
}

.bm-meta dt {
    margin: 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
}

.bm-meta dd {
    margin: 0.2rem 0 0;
    font-weight: 600;
    color: var(--text-color);
}

.bm-token {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.bm-error {
    font-size: 0.9rem;
}

.bm-subactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.bm-edit-panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.bm-edit-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.bm-templates {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bm-templates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
}

.template-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-item {
    background: rgba(12, 16, 34, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-overview {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
}

.template-status {
    font-size: 1.2rem;
}

.template-meta {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.template-details-button {
    white-space: nowrap;
}

.template-details {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.template-section h5 {
    margin: 0 0 0.35rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
}

.template-section pre {
    margin: 0;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.template-buttons {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.template-buttons li {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.template-modal-body {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1rem;
    align-items: flex-start;
    flex: 1 1 auto;
    overflow-y: auto;
    padding-right: 0.4rem;
}

.template-form-column {
    flex: 1 1 360px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.template-preview-column {
    flex: 1 1 300px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.template-preview-heading h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.template-preview-heading p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-subtle);
}

.template-chat-preview {
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(155deg, rgba(12, 16, 34, 0.96), rgba(6, 10, 22, 0.92));
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.template-chat-header {
    padding: 0.85rem 1rem;
    background: rgba(34, 195, 170, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-contact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.chat-contact-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.chat-contact-status {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--success);
}

.chat-contact-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.template-chat-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 280px;
}

.chat-message {
    max-width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    line-height: 1.55;
    font-size: 0.92rem;
    word-break: break-word;
}

.chat-header-bubble {
    background: rgba(77, 125, 255, 0.18);
    border-left: 3px solid var(--primary);
}

.chat-body-bubble {
    background: rgba(34, 195, 170, 0.2);
    border-left: 3px solid var(--secondary);
}

.chat-message.is-empty {
    display: none;
}

.template-preview-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.template-preview-buttons .muted {
    font-size: 0.85rem;
}

.template-preview-button {
    background: rgba(255, 255, 255, 0.14);
    color: var(--text-color);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.template-preview {
    display: none !important;
}

.template-buttons-builder {
    margin-top: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: 1rem;
    background: rgba(14, 18, 36, 0.85);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-buttons-header h3 {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 600;
}

.template-buttons-header p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-subtle);
}

.template-button-form {
    gap: 0.75rem;
}

.template-button-url.is-disabled input {
    opacity: 0.45;
    pointer-events: none;
}

.template-button-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.template-buttons-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.template-buttons-item {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
    background: rgba(8, 12, 28, 0.85);
    border: 1px solid rgba(77, 125, 255, 0.18);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
}

.template-button-pill {
    background: rgba(77, 125, 255, 0.25);
    color: var(--primary);
    font-size: 0.76rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.template-buttons-text {
    font-weight: 600;
    color: var(--text-color);
}

.template-buttons-url {
    font-size: 0.82rem;
    color: var(--info);
    word-break: break-all;
}

.template-buttons-item .template-button-remove {
    margin-left: auto;
}

.template-preview {
    margin-top: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    background: rgba(10, 14, 28, 0.8);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-preview-heading {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.template-preview-heading h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.template-preview-heading p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-subtle);
}

.template-preview-card {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    background: rgba(6, 9, 22, 0.9);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    box-shadow: var(--shadow-sm);
}

.template-preview-meta {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
}

.template-preview-name {
    font-weight: 600;
    font-size: 0.98rem;
}

.template-preview-header-text {
    font-size: 0.9rem;
    color: var(--info);
}

.template-preview-header-text.is-empty {
    color: var(--text-subtle);
    font-style: italic;
}

.template-preview-body {
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.95rem;
}

.template-preview-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.template-preview-button {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: rgba(77, 125, 255, 0.22);
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.dispatch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.5rem;
    align-items: flex-start;
}

.dispatch-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.dispatch-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.dispatch-columns {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.dispatch-column {
    flex: 1 1 320px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dispatch-options {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 0.35rem;
}

.dispatch-option {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    background: rgba(12, 16, 34, 0.75);
    padding: 0.65rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: border-color var(--transition), background var(--transition);
}

.dispatch-option.is-selected {
    border-color: rgba(34, 195, 170, 0.45);
    background: rgba(34, 195, 170, 0.12);
}

.dispatch-option-check {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    font-weight: 600;
}

.dispatch-option-check input[type="checkbox"] {
    margin-top: 0.2rem;
}

.dispatch-template-select {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.dispatch-template-select select:disabled {
    opacity: 0.6;
}

.dispatch-bm-errors {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.5rem;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.dispatch-bm-errors ul {
    margin: 0;
    padding-left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dispatch-details {
    display: grid;
    gap: 1rem;
}

.dispatch-extra-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.dispatch-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.dispatch-actions .muted {
    font-size: 0.85rem;
}

.dispatch-upload-form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.file-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(255, 255, 255, 0.18);
    background: rgba(12, 16, 32, 0.78);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.file-upload-label:hover {
    border-color: rgba(77, 125, 255, 0.45);
    background: rgba(20, 28, 52, 0.85);
}

.file-upload-label input[type="file"] {
    display: none;
}

.dispatch-status-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.dispatch-status-item {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    background: rgba(12, 16, 32, 0.78);
}

.dispatch-status-item.status-success {
    border-left-color: var(--success);
}

.dispatch-status-item.status-warning {
    border-left-color: var(--warning);
}

.dispatch-status-item.status-error {
    border-left-color: var(--danger);
}

.dispatch-status-item.status-info {
    border-left-color: var(--info);
}

.dispatch-status-header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: baseline;
}

.dispatch-status-header strong {
    font-weight: 600;
}

.bm-errors {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.bm-errors h5 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
}

.bm-errors ul {
    margin: 0;
    padding-left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.bm-error-text {
    font-weight: 600;
    color: var(--danger);
}

.template-modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    background: rgba(7, 9, 20, 0.78);
    z-index: 1000;
    padding: 1rem;
}

.template-modal-content {
    background: var(--surface-alt);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    width: min(920px, 100%);
    max-height: 92vh;
    box-shadow: var(--shadow-lg);
    padding: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
}

.template-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
}

.template-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
}

.template-form-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: radial-gradient(circle at 0% 100%, rgba(77, 125, 255, 0.25), transparent 60%), radial-gradient(circle at 100% 0%, rgba(34, 195, 170, 0.2), transparent 55%), linear-gradient(160deg, #090c1c 0%, #11162d 48%, #070b1a 100%);
}

.login-card {
    width: min(420px, 100%);
    padding: 2.2rem;
    border-radius: var(--radius-lg);
    background: rgba(18, 21, 36, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
}

.login-card h1 {
    font-size: 1.75rem;
    letter-spacing: 0.02em;
}

.login-card .btn {
    width: 100%;
    margin-top: 0.5rem;
}

.login-card small {
    font-size: 0.8rem;
    color: var(--text-subtle);
}

@media (max-width: 1024px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .table-wrapper {
        overflow-x: auto;
    }

    .table-wrapper table {
        min-width: 720px;
    }

    .grid-bms {
        grid-template-columns: 1fr;
    }

    .bm-card-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .dispatch-columns {
        flex-direction: column;
    }

    .dispatch-options {
        max-height: none;
    }

    .template-modal-content {
        width: 100%;
    }
}

@media (max-width: 768px) {
    body.dashboard-page {
        gap: 1rem;
    }

    .app-main {
        width: min(100%, 95%);
    }

    .card {
        padding: 1.1rem;
    }

    .card-header.with-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        gap: 0.6rem;
    }

    .tab-controls {
        width: 100%;
    }

    .tab-button {
        flex: 1 1 auto;
        text-align: center;
    }

    .table-actions {
        width: 100%;
    }

    .table-actions input[type="search"] {
        flex: 1 1 auto;
        width: 100%;
    }

    .instance-actions-stack,
    .settings-actions,
    .webhook-actions {
        width: 100%;
    }

    .presence-controls {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .bm-meta {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .dispatch-grid {
        grid-template-columns: 1fr;
    }

    .dispatch-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .dispatch-actions .btn {
        width: 100%;
    }

    .template-modal-content {
        width: 100%;
    }
}

@media (max-width: 1024px) {
    .template-modal-body {
        flex-direction: column;
        overflow-y: auto;
        padding-right: 0;
    }

    .template-preview-column {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .template-chat-body {
        min-height: 220px;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 1.2rem;
    }

    .app-main {
        width: 92%;
    }

    .login-card {
        padding: 1.7rem;
    }

    .tab-controls {
        padding: 0.35rem;
    }

    .btn {
        width: 100%;
    }

    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .copy-button,
    .btn-small {
        width: auto;
    }

    .bm-card-actions,
    .bm-subactions,
    .bm-edit-actions,
    .template-form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .template-details-button {
        width: 100%;
    }
}
