* { box-sizing: border-box; }
body {
    margin: 0;
    background: #f3f5f8;
    color: #17202a;
    font-family: Arial, Helvetica, sans-serif;
}
.topbar {
    align-items: center;
    background: #ffffff;
    border-bottom: 1px solid #d9e0e8;
    display: flex;
    gap: 24px;
    justify-content: space-between;
    min-height: 68px;
    padding: 14px 28px;
}
.topbar strong { display: block; font-size: 18px; }
.topbar span { color: #5d6978; font-size: 13px; }
nav { display: flex; gap: 8px; }
nav a {
    border: 1px solid #cfd8e3;
    color: #263445;
    padding: 9px 13px;
    text-decoration: none;
}
nav a.active { background: #204f6e; border-color: #204f6e; color: #fff; }
.menu-toggle { display: none; }
main { margin: 0 auto; max-width: 1120px; padding: 28px; }
.app-footer {
    color: #667384;
    font-size: 13px;
    padding: 16px 28px 24px;
    text-align: center;
}
.app-footer a,
.login-brand a {
    color: #204f6e;
    font-weight: 700;
    text-decoration: none;
}
.app-footer a:hover,
.login-brand a:hover { text-decoration: underline; }
.login-page { background: #eef2f6; }
.login-wrap {
    align-items: center;
    display: grid;
    min-height: 100vh;
    padding: 24px;
}
.login-panel {
    margin: 0 auto;
    max-width: 420px;
    width: 100%;
}
.login-brand {
    border-top: 1px solid #d9e0e8;
    margin-top: 20px;
    padding-top: 16px;
    text-align: center;
}
.panel {
    background: #fff;
    border: 1px solid #d9e0e8;
    margin-bottom: 18px;
    padding: 22px;
}
h1, h2, h3 { margin-top: 0; }
.section-title {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-title h1,
.section-title h2 { margin: 0; }
.log-actions {
    align-items: center;
    display: flex;
    gap: 10px;
}
.log-search {
    align-items: center;
    display: flex;
    gap: 8px;
}
.logs-header {
    align-items: flex-start;
}
.logs-header h1 {
    flex: 0 0 auto;
}
.logs-header .log-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
    flex-wrap: wrap;
}
.logs-header .log-search {
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
}
.logs-header .log-search input,
.logs-header .log-search select {
    width: auto;
}
.logs-header .log-search input[name="log_search"] {
    flex: 1 1 210px;
    min-width: 190px;
}
.logs-header .log-search input[type="date"] {
    flex: 0 1 145px;
    min-width: 135px;
}
.logs-header .log-search select {
    flex: 0 1 150px;
    min-width: 120px;
}
.logs-header button {
    font-size: 14px;
    line-height: 1.15;
    min-height: 38px;
    padding: 8px 12px;
}
.logs-header button.secondary,
.logs-header button.danger {
    max-width: 96px;
}
.logs-header .js-confirm-form {
    flex: 0 0 auto;
}
.log-search input { min-width: 220px; }
.log-search select { min-width: 190px; }
.log-search a { color: #204f6e; text-decoration: none; }
.dashboard-cards {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.dash-card {
    background: #f7f9fb;
    border: 1px solid #d9e0e8;
    display: grid;
    gap: 8px;
    min-height: 96px;
    padding: 16px;
}
.dash-card span {
    color: #5d6978;
    font-size: 13px;
    font-weight: 700;
}
.dash-card strong {
    color: #17202a;
    font-size: 34px;
    line-height: 1;
}
.column-config {
    border: 1px solid #d9e0e8;
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px;
}
.column-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.column-item {
    align-items: center;
    background: #f7f9fb;
    border: 1px solid #cfd8e3;
    cursor: grab;
    display: flex;
    gap: 7px;
    padding: 7px 9px;
}
.column-item input { width: auto; }
.drag-handle {
    color: #778394;
    font-weight: 700;
}
.form-grid, .message-editor {
    display: grid;
    gap: 16px;
}
.user-editor {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 22px;
}
.user-editor button { align-self: end; }
.type-fields {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.template-send-fields {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.field-config {
    border: 1px solid #d9e0e8;
    display: grid;
    gap: 12px;
    padding: 14px;
}
.field-config-row {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(160px, 1fr) 130px minmax(140px, 1fr) auto;
}
.muted { color: #6b7583; }
.builder-layout {
    align-items: start;
    display: grid;
    gap: 22px;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}
.whatsapp-preview {
    background: #f5f5f5;
    border: 1px solid #d9e0e8;
    min-height: 420px;
    padding: 26px;
    position: sticky;
    top: 16px;
}
.wa-chat {
    background:
        radial-gradient(circle at 12px 12px, rgba(0,0,0,.035) 1px, transparent 2px),
        #fafafa;
    background-size: 28px 28px;
    border: 1px solid #e2e6ea;
    min-height: 360px;
    padding: 34px 20px;
}
.wa-bubble {
    background: #207a3a;
    color: #fff;
    font-weight: 700;
    line-height: 1.38;
    margin-left: auto;
    max-width: 78%;
    padding: 14px 16px;
    position: relative;
    white-space: normal;
}
.wa-bubble::after {
    border-bottom: 10px solid transparent;
    border-left: 12px solid #207a3a;
    content: "";
    position: absolute;
    right: -11px;
    top: 0;
}
.wa-action {
    background: #f4f4f4;
    border: 1px solid #c8cdd3;
    color: #202832;
    display: block;
    margin: 14px 0 0 auto;
    max-width: 78%;
    width: 100%;
}
.preview-box {
    background: #f7f9fb;
    border: 1px solid #d9e0e8;
    display: grid;
    gap: 8px;
    min-height: 72px;
    padding: 14px;
}
.preview-box p { margin: 0; white-space: normal; }
.preview-box span { color: #5d6978; font-size: 13px; }
.preview-button {
    background: #204f6e;
    justify-self: start;
    padding: 8px 14px;
}
label { color: #344154; display: grid; gap: 7px; font-weight: 700; }
input, select, textarea {
    border: 1px solid #bbc6d3;
    color: #17202a;
    font: inherit;
    padding: 10px 11px;
    width: 100%;
}
textarea { resize: vertical; }
.input-actions {
    display: flex;
    gap: 8px;
}
.input-actions input {
    min-width: 0;
}
button {
    background: #1f6f50;
    border: 0;
    color: white;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 11px 15px;
}
button.danger { background: #a33131; }
button.warning { background: #8a6416; }
button.secondary { background: #59677a; }
button.small {
    font-size: 13px;
    padding: 8px 10px;
    white-space: nowrap;
    width: auto;
}
button:disabled {
    background: #9aa6b2;
    cursor: not-allowed;
}
.check { align-items: center; display: flex; gap: 8px; }
.check input { width: auto; }
.alert {
    border: 1px solid;
    margin-bottom: 18px;
    padding: 12px 14px;
}
.alert.success { background: #e9f7ef; border-color: #8ed3ad; color: #165c3a; }
.alert.error { background: #fff1f0; border-color: #e0aaa5; color: #8f2d24; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; min-width: 760px; width: 100%; }
th, td { border-bottom: 1px solid #e3e8ef; padding: 10px; text-align: left; vertical-align: top; }
th { background: #f7f9fb; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 4px 8px; }
.badge.ok { background: #ddf3e7; color: #14643f; }
.badge.fail { background: #ffe3e0; color: #8f2d24; }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.message-card { border: 1px solid #d9e0e8; padding: 16px; }
.message-card > div:first-child { align-items: start; display: flex; justify-content: space-between; gap: 12px; }
.message-card p { color: #3b4656; white-space: normal; }
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }
@media (max-width: 680px) {
    .topbar {
        align-items: center;
        flex-direction: row;
        min-height: 62px;
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .menu-toggle {
        display: block;
        padding: 9px 12px;
    }
    nav {
        background: #fff;
        border-left: 1px solid #d9e0e8;
        box-shadow: -12px 0 30px rgba(23, 32, 42, .15);
        display: none;
        flex-direction: column;
        gap: 10px;
        height: 100vh;
        max-width: 82vw;
        padding: 18px;
        position: fixed;
        right: 0;
        top: 0;
        width: 280px;
        z-index: 30;
    }
    body.menu-open nav { display: flex; }
    nav a { text-align: center; }
    main {
        max-width: 100%;
        padding: 16px;
    }
    .panel {
        margin-left: auto;
        margin-right: auto;
        padding: 16px;
    }
    .section-title { align-items: stretch; flex-direction: column; }
    .log-actions,
    .log-search { align-items: stretch; flex-direction: column; }
    .log-search input,
    .log-search select { min-width: 0; }
    .column-list { flex-direction: column; }
    .dashboard-cards { grid-template-columns: 1fr 1fr; }
    .input-actions { flex-wrap: wrap; }
    .input-actions input { flex: 1 1 100%; }
    .type-fields { grid-template-columns: 1fr; }
    .field-config-row { grid-template-columns: 1fr; }
    .builder-layout { grid-template-columns: 1fr; }
    .whatsapp-preview {
        min-height: 320px;
        padding: 14px;
        position: static;
    }
    .wa-chat {
        min-height: 280px;
        padding: 22px 12px;
    }
    .wa-bubble,
    .wa-action { max-width: 88%; }
    table { min-width: 680px; }
}
@media (max-width: 420px) {
    .dashboard-cards { grid-template-columns: 1fr; }
}
