:root {
    --bg: #f7f4ef;
    --surface: #fffdfa;
    --ink: #211f29;
    --muted: #746f7d;
    --line: #e7dfd6;
    --purple: #25143d;
    --purple-soft: #3a2458;
    --accent: #ef7f43;
    --accent-dark: #bf5726;
    --danger: #b42318;
    --success: #157f4f;
    --shadow: 0 12px 34px rgba(39, 26, 16, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

.sidebar {
    background: var(--purple);
    color: #fff;
    padding: 22px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: block;
    color: #fff;
    text-decoration: none;
    font-weight: 900;
    letter-spacing: .08em;
    margin: 0 0 28px;
}

.nav {
    display: grid;
    gap: 5px;
}

.nav a,
.nav summary,
.nav-button {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 14px;
    padding: 10px 12px;
    background: transparent;
    color: rgba(255,255,255,.82);
    text-align: left;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
}

.nav a:hover,
.nav summary:hover,
.nav-button:hover {
    background: var(--purple-soft);
    color: #fff;
}

.nav-group {
    border-radius: 18px;
}

.nav-group a {
    margin-left: 12px;
    width: calc(100% - 12px);
    font-size: 14px;
}

.main {
    min-width: 0;
    padding: 24px;
    overflow-x: hidden;
}

.page-head,
.panel-head,
.impersonation,
.action-row,
.filters,
.row-actions,
.inline-form {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-head {
    justify-content: space-between;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}

h1,
h2 {
    margin: 0;
    line-height: 1.05;
}

h1 {
    font-size: clamp(26px, 3vw, 38px);
}

h2 {
    font-size: 20px;
}

.user-chip,
.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    background: #f0e8df;
    color: #5d5268;
    font-size: 12px;
    font-weight: 700;
}

.pill-active,
.pill-sent {
    background: #dff3e9;
    color: var(--success);
}

.pill-archived,
.pill-inactive,
.pill-failed {
    background: #efe9e7;
    color: #766a64;
}

.impersonation {
    justify-content: space-between;
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 18px;
    background: #fff4de;
    border: 1px solid #f0d19a;
}

.panel,
.metric-card,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px;
    margin-bottom: 14px;
}

.panel-compact {
    padding: 16px;
}

.panel-head {
    justify-content: space-between;
    margin-bottom: 18px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.metric-card {
    padding: 18px;
}

.metric-card span,
.muted,
.message-meta {
    color: var(--muted);
}

.metric-card strong {
    display: block;
    margin: 8px 0;
    font-size: 30px;
}

.button,
button.button,
.button-light {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 0;
    border-radius: 13px;
    padding: 9px 14px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button-light {
    background: #efe8df;
    color: var(--ink);
}

.small-link,
.link-button {
    border: 0;
    background: transparent;
    color: var(--accent-dark);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
}

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

.danger-button {
    background: var(--danger);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
    color: var(--ink);
    font-size: 16px;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.icon-btn:hover {
    border-color: #d0bfae;
    background: #fbf6ef;
}

.icon-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.flash {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #efe8df;
}

.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 40;
    display: grid;
    gap: 8px;
    width: min(360px, calc(100vw - 36px));
}

.toast {
    margin: 0;
    box-shadow: var(--shadow);
}

.flash-success {
    background: #dff3e9;
    color: var(--success);
}

.flash-error {
    background: #fde7e3;
    color: var(--danger);
}

.table-wrap {
    max-width: 100%;
    overflow-x: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    overflow: hidden;
    text-overflow: ellipsis;
}

th {
    color: var(--muted);
    font-size: 12px;
}

.actions-col {
    width: 150px;
}

.truncate-cell,
.token-mask {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.token-mask {
    display: inline-block;
    padding: 4px 7px;
    border-radius: 9px;
    background: #f4eee6;
    font-size: 12px;
}

.is-muted {
    opacity: .55;
}

.row-actions {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.form-grid,
.upload-box {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.upload-box {
    display: none;
    margin-bottom: 20px;
    padding: 16px;
    border-radius: 20px;
    background: #fbf6ef;
}

.upload-box.is-open {
    display: grid;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

label small,
.hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    min-width: 0;
    border-radius: 12px;
    padding: 10px 11px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

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

.span-2,
.form-actions {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-start;
}

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

.check input {
    width: auto;
}

.thumb {
    width: 58px;
    height: 42px;
    object-fit: cover;
    border-radius: 12px;
    cursor: pointer;
}

.pagination {
    display: flex;
    gap: 12px;
    margin-top: 18px;
}

.message-list {
    display: grid;
    gap: 12px;
}

.message {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    background: #fff;
}

.message-outgoing {
    border-color: #e4c1a8;
}

.message img {
    max-width: 280px;
    border-radius: 14px;
}

.button-builder {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 22px;
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
}

.auth-card-wide {
    width: min(760px, 100%);
}

.auth-brand {
    color: var(--purple);
    font-weight: 900;
    letter-spacing: .08em;
    margin-bottom: 14px;
}

.auth-card form {
    display: grid;
    gap: 14px;
    margin-top: 20px;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    padding: 20px;
    background: rgba(20, 14, 28, .45);
    z-index: 20;
}

.modal.is-open {
    display: grid;
}

.modal-card {
    position: relative;
    width: min(720px, 100%);
    max-height: 88vh;
    overflow: auto;
    border-radius: 24px;
    background: #fff;
    padding: 22px;
}

.confirm-card {
    width: min(420px, 100%);
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.modal-card img {
    max-width: 100%;
    border-radius: 18px;
}

.modal-close {
    position: absolute;
    right: 14px;
    top: 12px;
    border: 0;
    background: #efe8df;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    cursor: pointer;
}

.copy-row {
    display: flex;
    gap: 10px;
}

.modal-image {
    display: block;
    max-height: 78vh;
    object-fit: contain;
    margin: 0 auto;
}

.scenario-settings {
    grid-template-columns: 1.2fr .6fr .8fr;
}

.scenario-builder {
    display: grid;
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr) minmax(260px, 330px);
    gap: 14px;
    align-items: start;
    max-width: 100%;
}

.steps-panel,
.editor-panel,
.preview-panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 14px;
}

.builder-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.builder-head h3 {
    margin: 0;
}

.step-list {
    display: grid;
    gap: 8px;
}

.step-card {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 12px;
    align-items: center;
    gap: 9px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    text-decoration: none;
}

.step-card.is-selected {
    border-color: #d8a37e;
    background: #fff7ef;
}

.step-number {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 10px;
    background: #f3ece3;
    font-size: 12px;
    font-weight: 900;
}

.step-main {
    min-width: 0;
}

.step-main strong,
.step-main small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.step-main small {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #b9afa6;
}

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

.status-inactive {
    background: #b9afa6;
}

.message-editor {
    display: grid;
    gap: 14px;
}

.trigger-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.delay-row {
    display: grid;
    grid-template-columns: .8fr 1fr;
    gap: 8px;
}

.test-bot-select {
    max-width: 280px;
}

.button-panel {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.button-list {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
}

.button-row {
    display: grid;
    grid-template-columns: minmax(100px, 1.3fr) 92px minmax(100px, 1.3fr) minmax(100px, 1.2fr) 70px 32px 32px;
    gap: 7px;
    align-items: center;
}

.add-button-row {
    grid-template-columns: minmax(100px, 1.3fr) 110px minmax(100px, 1.3fr) minmax(100px, 1.2fr) 70px 94px;
}

.phone-preview {
    border-radius: 24px;
    background: #f5efe7;
    border: 1px solid #eadfd4;
    padding: 18px;
}

.chat-bubble {
    display: grid;
    gap: 10px;
    border-radius: 18px 18px 18px 6px;
    background: #fff;
    padding: 14px;
    box-shadow: 0 8px 20px rgba(39, 26, 16, .08);
}

.preview-image {
    width: 100%;
    max-height: 190px;
    object-fit: cover;
    border-radius: 14px;
}

.preview-text {
    color: var(--ink);
    line-height: 1.45;
    word-break: break-word;
}

.preview-buttons {
    display: grid;
    gap: 7px;
}

.preview-button {
    display: block;
    border-radius: 12px;
    padding: 9px 10px;
    background: #f4eee6;
    color: var(--accent-dark);
    text-align: center;
    font-weight: 800;
}

.preview-caption,
.empty-mini {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

body.nps-page {
    background: #f8f3ec;
}

.nps-page .nps-shell {
    width: min(920px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.nps-page .nps-hero,
.nps-page .nps-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.nps-page .nps-hero {
    padding: clamp(22px, 4vw, 38px);
    margin-bottom: 14px;
}

.nps-page .nps-hero h1 {
    max-width: 720px;
    margin-bottom: 10px;
}

.nps-page .nps-hero h2 {
    color: var(--accent-dark);
    font-size: clamp(18px, 2.4vw, 24px);
    margin-bottom: 14px;
}

.nps-page .nps-hero p {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.55;
}

.nps-page .nps-card {
    padding: clamp(18px, 3vw, 28px);
}

.nps-page .nps-form {
    display: grid;
    gap: 16px;
}

.nps-page fieldset.nps-question {
    min-inline-size: 0;
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    appearance: none;
}

.nps-page .nps-question legend {
    padding: 0 6px;
    color: var(--ink);
    font-weight: 850;
    line-height: 1.35;
}

.nps-page .nps-question legend span,
.nps-page .nps-textarea span {
    color: var(--danger);
}

.nps-page .rating-scale {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.nps-page .rating-option {
    display: block;
    cursor: pointer;
    min-width: 0;
}

.nps-page .rating-option input {
    position: absolute;
    width: 1px !important;
    min-width: 1px;
    max-width: 1px;
    height: 1px !important;
    min-height: 1px;
    max-height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
    opacity: 0;
}

.nps-page .rating-option span {
    display: grid;
    place-items: center;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fbf6ef;
    color: var(--ink);
    font-size: 18px;
    font-weight: 900;
}

.nps-page .rating-option input:checked + span {
    border-color: var(--accent);
    background: #fff1e8;
    color: var(--accent-dark);
    box-shadow: inset 0 0 0 2px rgba(239, 127, 67, .16);
}

.nps-page .rating-option input:focus-visible + span {
    outline: 3px solid rgba(239, 127, 67, .28);
    outline-offset: 2px;
}

.nps-page .rating-help {
    margin: 9px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.nps-page .conditional-comment {
    display: none;
    margin-top: 12px;
}

.nps-page .conditional-comment.is-visible {
    display: grid;
}

.nps-page .nps-textarea {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}

.nps-page textarea,
.nps-page .conditional-comment textarea,
.nps-page .nps-textarea textarea {
    width: 100%;
    min-height: 96px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 13px;
    background: #fffdfa;
    color: var(--ink);
    font: inherit;
    line-height: 1.45;
    resize: vertical;
    box-shadow: none;
    appearance: none;
}

.nps-page textarea:focus,
.nps-page .conditional-comment textarea:focus,
.nps-page .nps-textarea textarea:focus {
    border-color: var(--accent);
    outline: 3px solid rgba(239, 127, 67, .16);
}

.nps-page .field-error {
    display: block;
    margin-top: 7px;
    color: var(--danger);
    font-size: 13px;
    font-weight: 700;
}

.nps-page .nps-submit {
    width: 100%;
    min-height: 52px;
    font-size: 16px;
}

.nps-page .nps-submit:disabled {
    opacity: .72;
    cursor: wait;
}

.nps-page .nps-success {
    padding: 30px;
    border-radius: 20px;
    background: #fff7ef;
    text-align: center;
}

.nps-page .nps-success p {
    color: var(--muted);
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .main {
        padding: 18px;
    }

    .page-head,
    .panel-head,
    .impersonation {
        align-items: flex-start;
        flex-direction: column;
    }

    .metric-grid,
    .form-grid,
    .upload-box,
    .scenario-settings,
    .trigger-fields {
        grid-template-columns: 1fr;
    }

    .scenario-builder {
        grid-template-columns: 1fr;
    }

    .button-row,
    .add-button-row,
    .button-builder {
        grid-template-columns: 1fr;
    }

    .nps-page .nps-shell {
        width: min(100% - 18px, 920px);
        padding-top: 10px;
    }

    .nps-page .nps-hero,
    .nps-page .nps-card {
        border-radius: 18px;
    }

    .nps-page .rating-scale {
        gap: 6px;
    }

    .nps-page .rating-option span {
        min-height: 44px;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    thead {
        display: none;
    }

    tr {
        padding: 10px 0;
        border-bottom: 1px solid var(--line);
    }

    td {
        border-bottom: 0;
        padding: 6px 0;
        white-space: normal;
    }

    .row-actions {
        justify-content: flex-start;
    }
}
