:root {
    --wa-primary: #25D366;
    --wa-primary-dark: #1DA851;
    --wa-primary-soft: rgba(37, 211, 102, .14);
    --accent-blue: #2563eb;
    --accent-blue-soft: rgba(37, 99, 235, .1);
    --accent-amber: #b45309;
    --accent-amber-soft: rgba(245, 158, 11, .14);
    --accent-red: #dc2626;
    --accent-red-soft: rgba(220, 38, 38, .1);
    --chrome-dark: #111827;
    --chrome-dark-hover: rgba(255, 255, 255, .08);
    --chrome-dark-active: rgba(37, 211, 102, .16);
    --chrome-border: rgba(255, 255, 255, .08);
    --surface: #f4f6f8;
    --surface-card: #ffffff;
    --ink: #1f2933;
    --ink-muted: #6b7280;
    --border-soft: rgba(17, 24, 39, .08);
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, .06);
    --shadow-md: 0 8px 24px rgba(17, 24, 39, .08);
    --sidebar-width: 268px;
    --radius: 10px;
}

body {
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    background: var(--surface);
    color: var(--ink);
    font-size: .9375rem;
}

h1, h2, h3, h4, h5, h6 {
    letter-spacing: -.01em;
}

/* ---------- Auth ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
}

@media (min-width: 992px) {
    .auth-shell {
        grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    }
}

.auth-brand-panel {
    display: none;
    position: relative;
    overflow: hidden;
    background: linear-gradient(155deg, var(--chrome-dark) 0%, #0b3d2e 55%, var(--wa-primary-dark) 130%);
    color: #fff;
    padding: 56px;
    flex-direction: column;
    justify-content: space-between;
}

@media (min-width: 992px) {
    .auth-brand-panel {
        display: flex;
    }
}

.auth-brand-panel::after {
    content: '';
    position: absolute;
    inset: auto -20% -30% auto;
    width: 480px;
    height: 480px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37, 211, 102, .25), transparent 70%);
}

.auth-brand-tagline {
    max-width: 380px;
    color: rgba(255, 255, 255, .75);
    font-size: 1.05rem;
    line-height: 1.6;
}

.auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--surface);
}

.auth-card {
    width: min(100%, 400px);
    border: 0;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* ---------- Brand mark ---------- */
.brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--wa-primary);
    color: #062b25;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.brand-mark-text {
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.15;
    color: inherit;
}

.brand-mark-sub {
    font-size: .75rem;
    color: var(--ink-muted);
}

/* ---------- App shell ---------- */
.app-shell {
    min-height: 100vh;
}

.sidebar {
    background: var(--chrome-dark);
    color: #fff;
    width: var(--sidebar-width);
    border-right: 1px solid var(--chrome-border);
}

.sidebar .brand-mark-sub {
    color: rgba(255, 255, 255, .45);
}

.sidebar-section-label {
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .08em;
    color: rgba(255, 255, 255, .38);
    padding: 0 12px;
    margin: 18px 0 8px;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, .72);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 40px;
    padding: 0 12px;
    font-size: .9rem;
    font-weight: 500;
    transition: background-color .12s ease, color .12s ease;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    opacity: .85;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: var(--chrome-dark-hover);
}

.sidebar .nav-link.active {
    color: #fff;
    background: var(--chrome-dark-active);
    font-weight: 600;
}

.sidebar .nav-link.active i {
    color: var(--wa-primary);
    opacity: 1;
}

.app-main {
    min-width: 0;
}

@media (min-width: 992px) {
    .app-main {
        margin-left: var(--sidebar-width);
    }

    .sidebar-fixed {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1030;
    }
}

.topbar {
    background: var(--surface-card);
    border-bottom: 1px solid var(--border-soft);
}

.content-wrap {
    padding: 28px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--wa-primary-soft);
    color: var(--wa-primary-dark);
    font-weight: 700;
    font-size: .82rem;
    flex-shrink: 0;
}

/* ---------- Cards, forms, buttons ---------- */
.card {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: var(--surface-card);
    border-bottom: 1px solid var(--border-soft);
    font-weight: 600;
    padding: 14px 20px;
}

.card-body {
    padding: 20px;
}

.modal-content,
.form-control,
.form-select,
.btn {
    border-radius: 8px;
}

.form-label {
    font-weight: 600;
    font-size: .84rem;
    color: #374151;
}

.form-control,
.form-select {
    border-color: var(--border-soft);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--wa-primary);
    box-shadow: 0 0 0 .2rem var(--wa-primary-soft);
}

.btn {
    font-weight: 600;
    font-size: .875rem;
}

.btn-primary {
    --bs-btn-bg: var(--wa-primary);
    --bs-btn-border-color: var(--wa-primary);
    --bs-btn-hover-bg: var(--wa-primary-dark);
    --bs-btn-hover-border-color: var(--wa-primary-dark);
    --bs-btn-color: #062b25;
    --bs-btn-hover-color: #062b25;
}

.btn-outline-primary {
    --bs-btn-color: var(--chrome-dark);
    --bs-btn-border-color: var(--border-soft);
    --bs-btn-hover-bg: var(--wa-primary);
    --bs-btn-hover-border-color: var(--wa-primary);
    --bs-btn-hover-color: #062b25;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-toolbar-action {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Operator module pages ---------- */
.module-hero {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface-card);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 18px;
}

.module-hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
    gap: 18px;
    align-items: stretch;
}

.module-hero-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.module-hero-copy {
    color: var(--ink-muted);
    max-width: 720px;
    margin-bottom: 0;
}

.module-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.module-step {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: #fbfcfd;
    padding: 12px;
    min-width: 0;
}

.module-step-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-blue-soft);
    color: var(--accent-blue);
    margin-bottom: 10px;
}

.module-step-title {
    font-weight: 700;
    font-size: .86rem;
    margin-bottom: 2px;
}

.module-step-text {
    color: var(--ink-muted);
    font-size: .78rem;
    line-height: 1.4;
    margin-bottom: 0;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.metric-tile {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: var(--surface-card);
    padding: 14px;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}

.metric-label {
    color: var(--ink-muted);
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 1.45rem;
    line-height: 1.1;
    font-weight: 800;
}

.metric-note {
    color: var(--ink-muted);
    font-size: .78rem;
    margin-top: 4px;
}

.filter-panel,
.bulk-panel,
.table-card,
.form-panel,
.form-aside,
.detail-panel {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface-card);
    box-shadow: var(--shadow-sm);
}

.filter-panel,
.bulk-panel {
    padding: 18px;
    margin-bottom: 16px;
}

.panel-title-row {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.panel-title {
    font-weight: 700;
    margin-bottom: 2px;
}

.panel-subtitle {
    color: var(--ink-muted);
    font-size: .83rem;
}

.table-card {
    overflow: hidden;
}

.table-card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.table-title {
    font-weight: 700;
    margin-bottom: 2px;
}

.table-meta {
    color: var(--ink-muted);
    font-size: .82rem;
}

.entity-cell {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.entity-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--wa-primary-soft);
    color: var(--wa-primary-dark);
    font-weight: 800;
    font-size: .8rem;
}

.entity-avatar.blue {
    background: var(--accent-blue-soft);
    color: var(--accent-blue);
}

.entity-avatar.amber {
    background: var(--accent-amber-soft);
    color: var(--accent-amber);
}

.entity-main {
    min-width: 0;
}

.entity-title {
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
}

.entity-title:hover {
    color: var(--wa-primary-dark);
}

.entity-subtitle {
    color: var(--ink-muted);
    font-size: .78rem;
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-muted {
    color: var(--ink-muted);
    font-size: .82rem;
}

.soft-note {
    border: 1px solid rgba(37, 99, 235, .16);
    border-radius: 8px;
    background: var(--accent-blue-soft);
    color: #1e3a8a;
    padding: 12px 14px;
    font-size: .86rem;
}

.warning-note {
    border: 1px solid rgba(245, 158, 11, .25);
    border-radius: 8px;
    background: var(--accent-amber-soft);
    color: #7c2d12;
    padding: 12px 14px;
    font-size: .86rem;
}

.form-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
}

.form-panel {
    padding: 22px;
}

.form-aside {
    padding: 18px;
    position: sticky;
    top: 104px;
}

.form-section-title {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.form-section-subtitle {
    color: var(--ink-muted);
    margin-bottom: 18px;
}

.tip-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
}

.tip-item {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.tip-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--ink-muted);
}

.tip-title {
    font-weight: 700;
    font-size: .85rem;
    margin-bottom: 1px;
}

.tip-text {
    color: var(--ink-muted);
    font-size: .8rem;
    line-height: 1.45;
}

.choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.choice-check {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: #fbfcfd;
    padding: 10px 12px 10px 36px;
    min-height: 54px;
}

.choice-check .form-check-input {
    margin-left: -24px;
}

.choice-check .form-check-label {
    display: block;
    font-weight: 700;
}

.choice-check small {
    color: var(--ink-muted);
}

.preview-panel {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: #fbfcfd;
    padding: 14px;
}

.template-type-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--accent-blue-soft);
    color: var(--accent-blue);
    font-weight: 700;
    font-size: .75rem;
}

.template-type-pill.free {
    background: var(--wa-primary-soft);
    color: var(--wa-primary-dark);
}

.code-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    border: 1px solid var(--border-soft);
    background: var(--surface);
    color: var(--ink);
    padding: 2px 6px;
    font-size: .76rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.log-message-preview {
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: #fbfcfd;
    padding: 9px 11px;
    max-width: 360px;
    color: var(--ink);
    line-height: 1.42;
}

.log-message-preview.incoming {
    background: var(--accent-blue-soft);
    border-color: rgba(37, 99, 235, .16);
}

.log-message-preview.outgoing {
    background: var(--wa-primary-soft);
    border-color: rgba(37, 211, 102, .22);
}

.sid-chip {
    display: inline-flex;
    max-width: 180px;
    border-radius: 6px;
    border: 1px solid var(--border-soft);
    background: var(--surface);
    color: var(--ink-muted);
    padding: 3px 7px;
    font-size: .72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.error-text {
    color: var(--accent-red);
    font-size: .78rem;
    max-width: 260px;
    white-space: normal;
}

.direction-line {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-muted);
    font-size: .82rem;
}

.direction-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-blue);
    flex-shrink: 0;
}

.direction-dot.outgoing {
    background: var(--wa-primary-dark);
}

.settings-logo-preview {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: var(--surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    overflow: hidden;
    flex-shrink: 0;
}

.settings-logo-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

@media (max-width: 1199.98px) {
    .module-hero-grid,
    .form-shell,
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .form-aside {
        position: static;
    }
}

@media (max-width: 767.98px) {
    .content-wrap {
        padding: 18px;
    }

    .module-hero,
    .filter-panel,
    .bulk-panel,
    .form-panel,
    .form-aside {
        padding: 16px;
    }

    .module-steps,
    .metric-grid,
    .choice-grid {
        grid-template-columns: 1fr;
    }

    .table-card-header,
    .panel-title-row {
        align-items: stretch;
        flex-direction: column;
    }

    .btn-toolbar-action,
    .table-card-header .btn,
    .panel-title-row .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ---------- Stat cards ---------- */
.stat-card {
    border: 1px solid var(--border-soft);
}

.stat-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 10px;
    background: var(--wa-primary-soft);
    color: var(--wa-primary-dark);
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card-label {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .06em;
    color: var(--ink-muted);
    font-weight: 600;
}

.stat-card-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

/* ---------- Badges ---------- */
.badge-soft {
    background: var(--wa-primary-soft);
    color: var(--wa-primary-dark);
    border: 1px solid rgba(37, 211, 102, .28);
    font-weight: 600;
}

/* ---------- Tables ---------- */
.table {
    --bs-table-hover-bg: rgba(17, 24, 39, .025);
}

.table thead th {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .06em;
    color: var(--ink-muted);
    font-weight: 700;
    border-bottom-width: 1px;
    padding-top: 14px;
    padding-bottom: 14px;
    background: var(--surface);
}

.table td,
.table th {
    vertical-align: middle;
    padding-top: 12px;
    padding-bottom: 12px;
}

/* ---------- Chat preview ---------- */
.chat-preview {
    background: #e9edf1 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='2' cy='2' r='1.4' fill='%23d7dee4'/%3E%3C/svg%3E");
    border-radius: var(--radius);
    padding: 18px;
}

.message-bubble {
    position: relative;
    max-width: 680px;
    background: #dcf8c6;
    border-radius: 10px;
    padding: 10px 12px 8px;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    right: -6px;
    width: 12px;
    height: 14px;
    background: #dcf8c6;
    clip-path: polygon(0 0, 0% 100%, 100% 0);
}

.message-bubble-time {
    display: block;
    text-align: right;
    font-size: .7rem;
    color: rgba(0, 0, 0, .38);
    margin-top: 4px;
}

.chat-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.chat-panel {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface-card);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.chat-header {
    min-height: 76px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.chat-thread {
    min-height: 420px;
    max-height: 62vh;
    overflow-y: auto;
    padding: 18px;
    background: #e9edf1 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='2' cy='2' r='1.4' fill='%23d7dee4'/%3E%3C/svg%3E");
}

.chat-row {
    display: flex;
    margin-bottom: 10px;
}

.chat-row.outgoing {
    justify-content: flex-end;
}

.chat-row.incoming {
    justify-content: flex-start;
}

.chat-bubble {
    width: fit-content;
    max-width: min(680px, 82%);
    border-radius: 10px;
    padding: 10px 12px 8px;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.chat-bubble.outgoing {
    background: #dcf8c6;
    color: #111827;
}

.chat-bubble.incoming {
    background: #fff;
    color: #111827;
}

.chat-meta {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    color: rgba(0, 0, 0, .42);
    font-size: .7rem;
    margin-top: 5px;
}

.chat-error {
    margin-top: 8px;
    color: var(--accent-red);
    font-size: .78rem;
}

.chat-composer {
    border-top: 1px solid var(--border-soft);
    padding: 16px 18px;
    background: var(--surface-card);
}

/* ---------- Empty state ---------- */
.empty-state {
    border: 1px dashed var(--border-soft);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    background: var(--surface-card);
}

.empty-state-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 12px;
}

/* ---------- Detail list ---------- */
.detail-list dt {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ink-muted);
    font-weight: 700;
    padding-top: 10px;
    padding-bottom: 2px;
}

.detail-list dd {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 0;
}

.detail-list dd:last-child {
    border-bottom: 0;
}
