:root {
    --brand-primary: #2e7d32;
    --brand-secondary: #f4f7f2;
    --ink: #1f2328;
    --ink-soft: #57606a;
    --line: #e3e6ea;
    --bg: #f6f7f9;
    --white: #fff;
    --danger: #c0362c;
    --radius: 8px;
    --app-width: 1100px;
    --sidebar-width: 300px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
}

/* Fixed-width centered app shell */
.app {
    width: var(--app-width);
    max-width: 100%;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--white);
    box-shadow: var(--shadow);
}

/* ---- Header ---- */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--white);
}
.brand-mark { display: flex; align-items: center; }
.brand-mark img { display: block; border-radius: 6px; }
.brand-chooser {
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
    padding: 8px 32px 8px 14px;
    font-size: 13px;
    color: var(--ink-soft);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M2 4l4 4 4-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* ---- Body ---- */
.app-body {
    flex: 1;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 0;
}

/* ---- Sidebar ---- */
.sidebar {
    border-right: 1px solid var(--line);
    background: #fbfcfd;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}
.sidebar-title { font-weight: 600; font-size: 13px; }
.comm-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}
.comm-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    margin-bottom: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
    cursor: pointer;
}
.comm-item:hover { border-color: #cfd4da; }
.comm-item.is-active {
    border-color: var(--brand-primary);
    box-shadow: inset 0 0 0 1px var(--brand-primary);
}
.comm-item .drag-handle {
    cursor: grab;
    color: #b3bac1;
    font-size: 14px;
    line-height: 1;
    user-select: none;
}
.comm-item .comm-item-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}
.comm-item .comm-item-dup {
    border: 0;
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 5px;
    opacity: 0;
}
.comm-item:hover .comm-item-dup { opacity: 1; }
.comm-item .comm-item-dup:hover { background: var(--brand-secondary); color: var(--brand-primary); }
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: var(--shadow); }

.empty-hint { padding: 16px; color: var(--ink-soft); font-size: 13px; }

/* ---- Main ---- */
.main { min-height: 0; display: flex; flex-direction: column; }
.editor { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.comm-name {
    flex: 1;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 7px 9px;
    font-size: 16px;
    font-weight: 600;
}
.comm-name:hover { border-color: var(--line); }
.comm-name:focus { outline: none; border-color: var(--brand-primary); }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 12px; color: var(--ink-soft); min-width: 56px; text-align: right; }

.editor-toggles {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}
.seg {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.seg-btn {
    border: 0;
    background: var(--white);
    padding: 6px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--ink-soft);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.is-active { background: var(--brand-primary); color: #fff; font-weight: 600; }

.editor-body { flex: 1; min-height: 0; overflow-y: auto; }
.channel-block { padding: 4px 0; }
.channel-block + .channel-block { border-top: 1px solid var(--line); }
.channel-title {
    margin: 0;
    padding: 12px 16px 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-soft);
}
.panel { padding: 12px 16px 16px; }

.field { display: block; margin-bottom: 14px; }
.field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 5px;
}
.field-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
}
.field-input:focus { outline: none; border-color: var(--brand-primary); }
.sms-input { resize: vertical; }

#quillEditor { background: var(--white); min-height: 240px; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--line); }
.ql-container.ql-snow { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.ql-toolbar.ql-snow { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }

/* ---- Buttons ---- */
.btn {
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--ink);
    border-radius: var(--radius);
    padding: 7px 12px;
    font-size: 13px;
    cursor: pointer;
}
.btn:hover { border-color: #cfd4da; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.btn-primary:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #ecc9c5; }
.btn-danger:hover { background: #fdf1f0; }

/* ---- Email preview ---- */
.email-preview {
    width: 100%;
    height: 560px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
}

/* ---- SMS ---- */
.sms-counter { font-size: 12px; color: var(--ink-soft); }
.phone {
    width: 320px;
    margin: 8px auto;
    border: 10px solid #20242a;
    border-radius: 28px;
    background: #20242a;
    box-shadow: var(--shadow);
}
.phone-screen {
    background: #eef0f3;
    border-radius: 18px;
    padding: 18px 12px;
    min-height: 320px;
}
.sms-bubble {
    background: var(--brand-primary);
    color: #fff;
    padding: 10px 14px;
    border-radius: 16px 16px 16px 4px;
    max-width: 85%;
    font-size: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.sms-bubble.is-empty { background: #d7dbe0; color: var(--ink-soft); }
