/* ================================================================
   ZAADWhatsPlus — Unified Production Styles
   ================================================================ */

/* ---------- Variables ---------- */
:root {
    --c-primary: #1a73e8;
    --c-primary-hover: #1557b0;
    --c-success: #16a34a;
    --c-warning: #ea580c;
    --c-danger: #dc2626;
    --c-sidebar: #1e293b;
    --c-sidebar-hover: #334155;
    --c-sidebar-active: #0f172a;
    --c-sidebar-text: #94a3b8;
    --c-sidebar-text-active: #f1f5f9;
    --c-bg: #f1f5f9;
    --c-surface: #ffffff;
    --c-border: #e2e8f0;
    --c-text: #1e293b;
    --c-text-secondary: #64748b;
    --sidebar-w: 240px;
    --topbar-h: 56px;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-size: .875em; }

/* ============ LOGIN VIEW ============ */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 1rem;
}
.login-card {
    background: var(--c-surface);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}
.login-brand {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--c-sidebar);
    margin-bottom: .25rem;
}
.login-brand span { color: var(--c-primary); }
.login-card h2 {
    text-align: center;
    font-size: 1.1rem;
    color: var(--c-text-secondary);
    font-weight: 400;
    margin-bottom: 1.5rem;
}
.login-hint {
    text-align: center;
    font-size: .8rem;
    color: var(--c-text-secondary);
    margin-top: 1.5rem;
}

/* ============ APP SHELL LAYOUT ============ */
#app-shell { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
#sidebar {
    width: var(--sidebar-w);
    background: var(--c-sidebar);
    color: var(--c-sidebar-text);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform .2s ease;
}
#sidebar .sidebar-brand {
    padding: 18px 20px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid var(--c-sidebar-hover);
}
#sidebar .sidebar-brand span { color: #60a5fa; }

#sidebar-nav { flex: 1; padding: 8px 0; }
#sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--c-sidebar-text);
    font-size: .9rem;
    text-decoration: none;
    transition: background .15s, color .15s;
}
#sidebar-nav a:hover { background: var(--c-sidebar-hover); color: var(--c-sidebar-text-active); text-decoration: none; }
#sidebar-nav a.active { background: var(--c-sidebar-active); color: var(--c-sidebar-text-active); font-weight: 600; }
#sidebar-nav .nav-divider {
    height: 1px;
    background: var(--c-sidebar-hover);
    margin: 8px 16px;
}

.sidebar-footer {
    padding: 12px 20px;
    font-size: .75rem;
    color: var(--c-sidebar-text);
    border-top: 1px solid var(--c-sidebar-hover);
}

/* --- App body --- */
#app-body {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Topbar --- */
#topbar {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    height: var(--topbar-h);
    padding: 0 24px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: var(--shadow-sm);
}
.topbar-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--c-text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
}
.topbar-btn:hover { background: var(--c-bg); }
#sidebar-toggle { display: none; }
.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    margin-left: 8px;
    color: var(--c-text);
}
.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
#topbar-user { font-size: .875rem; color: var(--c-text-secondary); }

/* --- Main Content --- */
#page-content {
    flex: 1;
    padding: 24px;
    background: var(--c-bg);
}

/* ============ COMPONENTS ============ */

/* --- Cards --- */
.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--c-text);
    margin: 0;
}

/* --- Stat grid --- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.stat-card .stat-label { font-size: .8rem; color: var(--c-text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--c-text); margin-top: 4px; }
.stat-card .stat-sub { font-size: .8rem; color: var(--c-text-secondary); margin-top: 4px; }

/* --- Dashboard detail panels --- */
.dash-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.dash-panel .card-body { padding: 1rem; }
.dash-panel .table { width: 100%; border-collapse: collapse; }
.dash-panel .table td, .dash-panel .table th { padding: 6px 10px; border-bottom: 1px solid var(--c-border); text-align: left; }
.dash-panel .table tr:last-child td { border-bottom: none; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .5rem 1rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
    gap: 6px;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-success { background: var(--c-success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: var(--c-bg); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data-table th {
    text-align: left;
    padding: .6rem .75rem;
    background: var(--c-bg);
    font-weight: 600;
    font-size: .8rem;
    color: var(--c-text-secondary);
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 2px solid var(--c-border);
}
table.data-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
table.data-table tr:hover td { background: #f8fafc; }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: .75rem;
    font-weight: 500;
}
.badge-on, .badge-success { background: #dcfce7; color: #166534; }
.badge-off, .badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warn { background: #fff7ed; color: #9a3412; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: .3rem;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    font-size: .9rem;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,.15);
}
.form-textarea { resize: vertical; min-height: 100px; font-family: inherit; }
.form-error { color: var(--c-danger); font-size: .85rem; margin-top: .3rem; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.form-inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; }

/* --- Toolbar --- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}
.toolbar .form-input, .toolbar .form-select { width: auto; min-width: 160px; }
.toolbar .spacer { flex: 1; }

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--c-surface);
    border-radius: 12px;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--c-border);
}
.modal-header h3 { font-size: 1rem; margin: 0; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--c-text-secondary);
    padding: 0 4px;
}
.modal-body { padding: 1.25rem 1.5rem; flex: 1; overflow-y: auto; }
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--c-border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Toast notifications --- */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-size: .875rem;
    color: #fff;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toastIn .25s ease;
    max-width: 380px;
}
.toast-success { background: var(--c-success); }
.toast-error { background: var(--c-danger); }
.toast-info { background: var(--c-primary); }
.toast-warn { background: var(--c-warning); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* --- Empty/loading states --- */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--c-text-secondary);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: .5rem; }
.loading-spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Feature cards --- */
.feature-grid { display: grid; gap: 12px; }
.feature-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: box-shadow .15s;
}
.feature-card:hover { box-shadow: var(--shadow-md); }
.feature-card.disabled { opacity: .6; }
.feature-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.feature-header h3 { margin: 0; font-size: .9rem; }
.feature-header h3 small { font-weight: 400; color: var(--c-text-secondary); margin-left: 4px; }
.feature-desc { font-size: .825rem; color: var(--c-text-secondary); margin: 2px 0 8px; }
.feature-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Company cards --- */
.company-grid { display: grid; gap: 12px; }
.company-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    transition: box-shadow .15s;
}
.company-card:hover { box-shadow: var(--shadow-md); }
.company-card.active { border-left: 4px solid var(--c-success); }
.company-meta { font-size: .8rem; color: var(--c-text-secondary); margin-top: 4px; }
.company-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.active-badge {
    position: absolute;
    top: 12px;
    right: 14px;
}

/* --- Page header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    font-size: .85rem;
}

/* --- JSON editor in modal --- */
.json-editor {
    width: 100%;
    min-height: 250px;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: .8rem;
    padding: .75rem;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    resize: vertical;
    line-height: 1.5;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    #app-body { margin-left: 0; }
    #sidebar-toggle { display: block; }
    #page-content { padding: 16px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .form-row { flex-direction: column; }
    .toolbar { gap: 6px; }
    .toolbar .form-input, .toolbar .form-select { min-width: 0; flex: 1; }
}

/* ============ INBOX LAYOUT (3-panel) ============ */
.inbox-layout {
    display: flex;
    height: calc(100vh - var(--topbar-h) - 48px);
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.inbox-list {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--c-border);
    background: var(--c-surface);
}
.inbox-list-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--c-border);
}
.inbox-list-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.inbox-list-title h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}
.inbox-list-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 8px;
}
.inbox-filters {
    display: flex;
    gap: 6px;
}
.inbox-filters .form-select,
.inbox-filters .form-input {
    font-size: .8rem;
    padding: 5px 8px;
    flex: 1;
}
.inbox-list-body {
    flex: 1;
    overflow-y: auto;
}
.inbox-list-body .conversation-card {
    margin: 0;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    padding: 12px 16px;
}
.inbox-list-body .conversation-card:hover {
    transform: none;
    box-shadow: none;
    background: #f8fafc;
}
.inbox-list-body .conversation-card.conv-active {
    background: #e8f0fe;
    border-left: 3px solid var(--c-primary);
    padding-left: 13px;
}
.inbox-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}
.inbox-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
}
.inbox-empty-inner {
    text-align: center;
    color: var(--c-text-secondary);
}
.inbox-empty-icon {
    font-size: 3rem;
    margin-bottom: 8px;
    opacity: .5;
}
.inbox-back-btn { display: none; }

/* ============ CONVERSATIONS ============ */
.conversation-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .1s;
}
.conversation-card:hover {
    background: #f8fafc;
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}
.conv-avatar {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary), #4f9cf7);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(26,115,232,.25);
}
.conv-info { flex: 1; min-width: 0; }
.conv-header { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-weight: 600; font-size: .95rem; }
.conv-time { font-size: .75rem; color: var(--c-text-secondary); white-space: nowrap; }
.conv-preview { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.conv-last {
    flex: 1; min-width: 0;
    font-size: .85rem; color: var(--c-text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-last.conv-outbound { color: var(--c-text); }
.conv-unread {
    background: #25d366;
    color: #fff;
    font-size: .7rem; font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    flex-shrink: 0;
    min-width: 20px;
    text-align: center;
}
.conv-meta { font-size: .72rem; color: var(--c-text-secondary); margin-top: 2px; }

/* ============ CHAT LAYOUT (WhatsApp-style) ============ */
.chat-layout {
    display: flex;
    height: calc(100vh - var(--topbar-h) - 48px);
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Chat top bar */
.chat-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-surface);
    min-height: 56px;
}
.chat-topbar-info { flex: 1; min-width: 0; }
.chat-topbar-name { font-weight: 600; font-size: .95rem; display: block; }
.chat-topbar-phone { font-size: .78rem; color: var(--c-text-secondary); }
.chat-topbar-actions { display: flex; gap: 6px; }

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c8bfb6' fill-opacity='0.08'%3E%3Cpath d='M30 0l30 30-30 30L0 30z'/%3E%3C/g%3E%3C/svg%3E");
}

/* Chat bubbles */
.chat-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: .9rem;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,.06);
    animation: bubbleIn .15s ease-out;
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.chat-inbound {
    align-self: flex-start;
    background: #fff;
    border-bottom-left-radius: 2px;
}
.chat-outbound {
    align-self: flex-end;
    background: #dcf8c6;
    border-bottom-right-radius: 2px;
}
.chat-content { margin-bottom: 2px; }
.chat-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: .68rem;
    color: rgba(0,0,0,.4);
    margin-top: 2px;
}
.chat-type-tag {
    display: block;
    font-size: .75rem;
    color: var(--c-text-secondary);
    margin-bottom: 2px;
}
.chat-media-label { font-size: .85rem; color: var(--c-text-secondary); }

/* Status ticks */
.status-tick {
    font-size: .7rem;
    letter-spacing: -2px;
    margin-left: 2px;
}
.tick-sent { color: rgba(0,0,0,.35); }
.tick-delivered { color: rgba(0,0,0,.5); }
.tick-read { color: #53bdeb; font-weight: 700; }
.tick-failed { color: var(--c-danger); letter-spacing: normal; }
.tick-pending { color: rgba(0,0,0,.25); letter-spacing: normal; }

/* Input bar */
.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--c-border);
    background: #f0f2f5;
}
.chat-input-bar .form-input {
    flex: 1;
    border-radius: 20px;
    padding: 8px 16px;
}
.chat-input-bar .btn { border-radius: 20px; padding: 8px 20px; }
.chat-input-bar .btn-icon { padding: 8px 12px; font-size: 1.1rem; line-height: 1; flex-shrink: 0; }

/* ============ CHAT SIDEBAR (info panel) ============ */
.chat-sidebar {
    width: 0;
    overflow: hidden;
    border-left: 1px solid var(--c-border);
    background: var(--c-surface);
    transition: width .25s ease;
    flex-shrink: 0;
}
.chat-sidebar.open { width: 280px; }
.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--c-border);
}
.chat-sidebar-header h3 { margin: 0; font-size: .95rem; }
.chat-topbar-status { margin-left: 4px; }
#chat-sidebar-body { padding: 12px 16px; overflow-y: auto; max-height: calc(100% - 50px); }
.sidebar-section { margin-bottom: 16px; }
.sidebar-section h4 { font-size: .8rem; text-transform: uppercase; color: var(--c-text-secondary); margin-bottom: 8px; letter-spacing: .5px; }
.sidebar-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: .85rem;
    border-bottom: 1px solid #f1f5f9;
}
.sidebar-label { color: var(--c-text-secondary); font-size: .78rem; }

/* ---- Sidebar editable fields ---- */
.sidebar-editable { position: relative; }
.sidebar-edit-btn {
    background: none; border: none; cursor: pointer; font-size: .7rem; padding: 2px 4px;
    opacity: 0; transition: opacity .15s; color: var(--c-text-secondary);
}
.sidebar-editable:hover .sidebar-edit-btn { opacity: 1; }
.sidebar-value { flex: 1; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sidebar-inline-input { font-size: .8rem; padding: 3px 6px; width: 100%; margin-top: 2px; }
.sidebar-edit-actions { display: flex; gap: 4px; margin-top: 3px; justify-content: flex-end; }
.btn-xs { font-size: .7rem; padding: 2px 8px; border-radius: 4px; }
.sidebar-loading { color: var(--c-text-secondary); font-size: .8rem; font-style: italic; }

/* ---- Sidebar tags ---- */
.sidebar-tag {
    display: inline-block; background: var(--c-primary-light, #e0f2fe); color: var(--c-primary, #0284c7);
    font-size: .7rem; padding: 1px 7px; border-radius: 10px; margin: 1px 2px;
}

/* ---- Sidebar status select ---- */
.sidebar-status-select { font-size: .8rem; padding: 3px 6px; max-width: 120px; }
.form-select-sm { font-size: .8rem; padding: 3px 6px; }

/* ---- Sidebar notes timeline ---- */
.sidebar-notes-timeline { max-height: 200px; overflow-y: auto; margin-bottom: 8px; }
.sidebar-notes-empty { color: var(--c-text-secondary); font-size: .8rem; font-style: italic; padding: 4px 0; }
.sidebar-note { padding: 6px 0; border-bottom: 1px solid #f1f5f9; }
.sidebar-note:last-child { border-bottom: none; }
.sidebar-note-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.sidebar-note-author { font-size: .75rem; font-weight: 600; color: var(--c-primary); }
.sidebar-note-time { font-size: .68rem; color: var(--c-text-secondary); }
.sidebar-note-content { font-size: .82rem; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.sidebar-note-form textarea { font-size: .82rem; resize: vertical; }

/* ---- Entity 360 timeline ---- */
.entity-timeline { max-height: 350px; overflow-y: auto; margin-bottom: 8px; }
.timeline-item { padding: 6px 0; border-bottom: 1px solid #f1f5f9; display: flex; gap: 8px; align-items: flex-start; }
.timeline-item:last-child { border-bottom: none; }
.timeline-icon { flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .7rem; margin-top: 1px; }
.timeline-icon-inbound { background: #f1f5f9; color: #475569; }
.timeline-icon-outbound { background: #dcfce7; color: #166534; }
.timeline-icon-note { background: #fef3c7; color: #92400e; }
.timeline-icon-activity { background: #e0e7ff; color: #3730a3; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1px; }
.timeline-actor { font-size: .72rem; font-weight: 600; color: var(--c-text-secondary); }
.timeline-time { font-size: .65rem; color: var(--c-text-secondary); }
.timeline-text { font-size: .8rem; line-height: 1.3; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline-text-note { white-space: pre-wrap; word-break: break-word; }
.timeline-text-activity { font-style: italic; color: var(--c-text-secondary); }
.timeline-empty { color: var(--c-text-secondary); font-size: .8rem; font-style: italic; padding: 4px 0; }

/* ---------- Readiness Diagnostics ---------- */
.readiness-company { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.readiness-company.readiness-active { border-color: var(--c-primary); background: #f0f7ff; }
.readiness-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.readiness-checks { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.readiness-check { font-size: .78rem; padding: 2px 8px; border-radius: 4px; }
.readiness-check.check-pass { background: #dcfce7; color: #166534; }
.readiness-check.check-fail { background: #fef2f2; color: #991b1b; }
.readiness-blockers { margin-bottom: 8px; }
.readiness-blocker { font-size: .78rem; color: var(--c-warning); padding: 2px 0; }
.readiness-activity { display: flex; gap: 16px; font-size: .75rem; color: var(--c-text-secondary); margin-bottom: 8px; }
.readiness-actions { display: flex; gap: 8px; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ---------- Failed Message Bubble ---------- */
.chat-bubble.chat-failed { border-left: 3px solid var(--c-danger); background: #fef2f2; }
.chat-bubble.chat-failed .chat-meta { color: var(--c-danger); }
.chat-failed-label { font-size: .7rem; color: var(--c-danger); font-weight: 600; }

/* ---------- Priority Badges ---------- */
.conv-priority { font-size: .65rem; padding: 1px 6px; border-radius: 3px; font-weight: 600; text-transform: uppercase; }
.conv-priority-urgent { background: #dc2626; color: #fff; }
.conv-priority-high { background: #f59e0b; color: #fff; }
.conv-priority-normal { background: #e5e7eb; color: #374151; }
.conv-priority-low { background: #dbeafe; color: #1e40af; }

/* ---------- Conversation Tags ---------- */
.conv-tag { display: inline-block; font-size: .65rem; padding: 1px 6px; border-radius: 10px; background: #e0e7ff; color: #3730a3; margin-right: 3px; white-space: nowrap; }
.conv-tag-remove { background: none; border: none; cursor: pointer; color: #6366f1; font-size: .7rem; padding: 0 2px; margin-left: 2px; }
.conv-tag-remove:hover { color: #dc2626; }

/* ---------- Queue Badge ---------- */
.conv-queue { font-size: .65rem; padding: 1px 6px; border-radius: 3px; background: #fef3c7; color: #92400e; }

/* ---------- Snoozed Indicator ---------- */
.conv-snoozed { font-size: .75rem; opacity: .7; }

/* ---------- Conv Meta Row ---------- */
.conv-meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 2px; font-size: .72rem; color: var(--c-text-secondary); }

/* ---------- Sidebar Conv Tags ---------- */
.sidebar-conv-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.sidebar-actions .btn { flex: 1; }

/* ---------- Template Grid ---------- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.template-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px; padding: 16px; }
.template-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.template-header h3 { margin: 0; font-size: .95rem; }
.template-meta { font-size: .75rem; color: var(--c-text-secondary); margin-bottom: 8px; }
.template-body { font-size: .82rem; color: var(--c-text); white-space: pre-wrap; margin-bottom: 10px; background: #f9fafb; padding: 8px; border-radius: 4px; }
.template-actions { display: flex; gap: 6px; }

/* ---------- Campaign Detail ---------- */
.campaign-detail { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; }
.campaign-detail strong { color: var(--c-text-secondary); }

/* ---------- Page Actions in Header ---------- */
.page-actions { display: flex; gap: 8px; }

/* ---------- Form Input Small ---------- */
.form-input-sm { font-size: .82rem; padding: 4px 8px; }
.btn-xs { font-size: .72rem; padding: 2px 8px; }

/* ---- Entity summary card ---- */
.entity-summary-stat { display: flex; gap: 8px; margin: 6px 0; }
.entity-stat { flex: 1; text-align: center; background: #f8fafc; border-radius: 6px; padding: 4px 2px; }
.entity-stat-val { font-size: .9rem; font-weight: 700; color: var(--c-text); display: block; }
.entity-stat-label { font-size: .62rem; text-transform: uppercase; color: var(--c-text-secondary); letter-spacing: .3px; }

/* ---- Conversation list status badges ---- */
.conv-status-badge {
    display: inline-block; font-size: .65rem; padding: 1px 6px; border-radius: 8px;
    font-weight: 600; text-transform: capitalize; margin-right: 4px;
}
.conv-status-open { background: #dbeafe; color: #1d4ed8; }
.conv-status-assigned { background: #fef3c7; color: #92400e; }
.conv-status-resolved { background: #d1fae5; color: #065f46; }
.conv-status-closed { background: #e5e7eb; color: #6b7280; }
.conv-assignee { font-size: .72rem; color: var(--c-text-secondary); }

/* ============ WEBHOOKS / JSON VIEWER ============ */
.json-viewer {
    background: #0f172a;
    color: #a5f3fc;
    padding: 12px;
    border-radius: 6px;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: .78rem;
    line-height: 1.5;
    overflow: auto;
    max-height: 400px;
    white-space: pre-wrap;
    word-break: break-all;
}
.badge-sm { font-size: .65rem; padding: 1px 5px; }

/* ============ RESPONSIVE: INBOX & CHAT LAYOUT ============ */
@media (max-width: 768px) {
    .inbox-layout { height: calc(100vh - var(--topbar-h) - 16px); }
    .inbox-list { width: 100%; }
    .inbox-layout.conv-selected .inbox-list { display: none; }
    .inbox-thread { display: none; }
    .inbox-layout.conv-selected .inbox-thread { display: flex; }
    .inbox-layout .chat-sidebar.open { width: 100%; position: absolute; top: 0; right: 0; bottom: 0; z-index: 30; }
    .inbox-back-btn { display: inline-flex; }
    .chat-layout { height: calc(100vh - var(--topbar-h) - 16px); }
    .chat-sidebar.open { width: 100%; position: absolute; top: 0; right: 0; bottom: 0; z-index: 30; }
    .chat-bubble { max-width: 85%; }
}

/* ================================================================
   TEMPLATE STUDIO — Split-pane editor + phone preview
   ================================================================ */
.studio-container {
    display: flex;
    gap: 24px;
    min-height: calc(100vh - var(--topbar-h) - 120px);
}
.studio-editor {
    flex: 2;
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - var(--topbar-h) - 100px);
}
.studio-preview {
    flex: 1;
    min-width: 280px;
    max-width: 340px;
}
.studio-preview h3 {
    margin-bottom: 12px;
    color: var(--c-text-secondary);
    font-size: .9rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.studio-header h2 { font-size: 1.3rem; }
.studio-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.studio-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--c-border);
}
.studio-section:last-child { border-bottom: none; }
.studio-section h4 {
    font-size: .85rem;
    color: var(--c-text-secondary);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: 10px;
}
.studio-truth-note {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: .82rem;
    color: #92400e;
    margin-bottom: 12px;
}

/* Phone frame preview */
.phone-frame {
    background: #1a1a2e;
    border-radius: 28px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
    max-width: 320px;
    margin: 0 auto;
    position: sticky;
    top: 20px;
}
.phone-notch {
    width: 40%;
    height: 20px;
    background: #0f0f1e;
    border-radius: 0 0 12px 12px;
    margin: 0 auto 8px;
}
.phone-screen {
    background: #e5ddd5;
    border-radius: 16px;
    min-height: 420px;
    max-height: 520px;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}
.wa-msg {
    background: #fff;
    border-radius: 0 8px 8px 8px;
    padding: 8px 12px;
    max-width: 90%;
    box-shadow: 0 1px 1px rgba(0,0,0,.1);
    font-size: .85rem;
    line-height: 1.5;
}
.wa-header {
    font-weight: 700;
    font-size: .88rem;
    margin-bottom: 4px;
    color: #111;
}
.wa-header-image {
    width: 100%;
    height: 120px;
    background: #c8d6e5;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    color: #636e72;
    margin-bottom: 6px;
}
.wa-body { color: #303030; margin-bottom: 4px; white-space: pre-wrap; word-break: break-word; }
.wa-body code.wa-mono { background: #f0f0f0; padding: 2px 4px; border-radius: 3px; font-family: 'Courier New', monospace; font-size: .82rem; }
.wa-footer {
    font-size: .75rem;
    color: #888;
    margin-top: 4px;
}
.wa-buttons {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.wa-btn {
    background: #f0f2f5;
    border: 1px solid #dfe1e5;
    border-radius: 8px;
    text-align: center;
    padding: 8px;
    font-size: .82rem;
    color: var(--c-primary);
    font-weight: 500;
    cursor: default;
}
.wa-var {
    color: var(--c-primary);
    font-weight: 600;
    background: rgba(26,115,232,.08);
    padding: 1px 4px;
    border-radius: 3px;
}

/* Badges for meta vs product */
.meta-badge, .product-badge {
    display: inline-block;
    font-size: .68rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: .02em;
}
.meta-badge { background: #dbeafe; color: #1e40af; }
.product-badge { background: #ede9fe; color: #5b21b6; }

/* Button builder row */
.studio-btn-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: var(--c-bg);
    border-radius: 6px;
    border: 1px solid var(--c-border);
}
.studio-btn-row select, .studio-btn-row input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: .82rem;
}
.studio-btn-row .btn-sm { flex-shrink: 0; }

/* Variable mapping row */
.studio-varmap-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    padding: 6px 10px;
    background: var(--c-bg);
    border-radius: 6px;
}
.studio-varmap-row code {
    min-width: 48px;
    font-weight: 600;
    color: var(--c-primary);
}
.studio-varmap-row select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: .82rem;
}

/* Template button chips */
.tpl-btn-chip {
    display: inline-block;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 2px 10px;
    font-size: .75rem;
    color: var(--c-text-secondary);
    margin: 2px 2px;
}

/* ================================================================
   WHATSAPP FLOWS — screen cards
   ================================================================ */
.flow-screens-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.flow-screen-card {
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.flow-screen-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.flow-screen-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--c-primary);
    color: white;
    font-size: .75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.flow-screen-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}
.flow-preview-field {
    margin-bottom: 10px;
}
.flow-preview-field label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: #636e72;
    margin-bottom: 3px;
}
.flow-preview-input {
    border: 1px solid #c8d6e5;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: .8rem;
    color: #999;
    background: #fafafa;
}
.flow-preview-radio {
    font-size: .8rem;
    padding: 3px 0;
    color: #444;
}

/* ================================================================
   FLOWS STUDIO — Advanced visual builder
   ================================================================ */
.fs-studio {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-h) - 20px);
    background: var(--c-surface);
    border-radius: var(--radius);
    overflow: hidden;
}
.fs-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg);
    flex-shrink: 0;
}
.fs-topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.fs-topbar-right {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.fs-flow-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}
.fs-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Sidebar tabs */
.fs-sidebar {
    width: 56px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--c-bg-secondary);
    border-right: 1px solid var(--c-border);
    padding: 6px 0;
    gap: 2px;
}
.fs-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--c-text-secondary);
    transition: all .15s;
    border-left: 3px solid transparent;
}
.fs-tab:hover { background: var(--c-border); }
.fs-tab.active {
    color: var(--c-primary);
    background: rgba(37,99,235,.08);
    border-left-color: var(--c-primary);
}

/* Panel area */
.fs-panel {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-width: 0;
}

/* Phone preview column */
.fs-preview-col {
    width: 280px;
    flex-shrink: 0;
    border-left: 1px solid var(--c-border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--c-bg-secondary);
    overflow-y: auto;
}
.fs-device-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}
.fs-device-toggle button.active {
    background: var(--c-primary);
    color: white;
}
.fs-preview-note {
    font-size: .72rem;
    color: var(--c-text-secondary);
    text-align: center;
    margin-top: 8px;
}
.phone-frame.ios-frame {
    border-radius: 32px;
}
.phone-frame.android-frame {
    border-radius: 16px;
}

/* Canvas */
.fs-canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.fs-canvas-info {
    font-size: .82rem;
    color: var(--c-text-secondary);
    margin-left: auto;
}
.fs-canvas-area {
    position: relative;
    min-height: 500px;
    background: var(--c-bg-secondary);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: auto;
}
.fs-canvas-svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.fs-canvas-nodes {
    position: relative;
    min-height: 500px;
}

/* Canvas nodes */
.fs-node {
    position: absolute;
    width: 180px;
    background: var(--c-bg);
    border: 2px solid var(--c-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    cursor: grab;
    user-select: none;
    transition: box-shadow .15s, border-color .15s;
    z-index: 1;
}
.fs-node:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.fs-node-selected {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.2);
}
.fs-node-start {
    border-top: 3px solid #10b981;
}
.fs-node-terminal {
    border-top: 3px solid #ef4444;
}
.fs-node-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}
.fs-node-title {
    font-weight: 700;
    font-size: .82rem;
}
.fs-node-badge {
    font-size: .6rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 700;
    text-transform: uppercase;
}
.fs-node-badge.start { background: #10b981; color: white; }
.fs-node-badge.terminal { background: #ef4444; color: white; }
.fs-node-sub {
    font-size: .75rem;
    color: var(--c-text-secondary);
    margin-bottom: 4px;
}
.fs-node-actions {
    display: flex;
    gap: 3px;
    justify-content: flex-end;
}
.btn-xs {
    font-size: .7rem;
    padding: 2px 6px;
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    border-radius: 4px;
    cursor: pointer;
}
.btn-xs:hover { background: var(--c-border); }

/* Toolbox */
.fs-toolbox { }
.fs-toolbox h3 { margin-top: 0; }
.fs-toolbox-hint {
    font-size: .82rem;
    color: var(--c-text-secondary);
    margin-bottom: 12px;
}
.fs-toolbox-cat { margin-bottom: 14px; }
.fs-toolbox-cat h4 {
    font-size: .85rem;
    margin: 0 0 6px 0;
    color: var(--c-text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.fs-toolbox-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.fs-toolbox-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 6px;
    font-size: .8rem;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}
.fs-toolbox-item:hover {
    border-color: var(--c-primary);
    background: rgba(37,99,235,.06);
}
.fs-toolbox-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}
.fs-toolbox-selected { margin-top: 16px; }
.fs-field-list { display: flex; flex-direction: column; gap: 4px; }
.fs-field-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 6px;
    font-size: .82rem;
}

/* Transitions */
.fs-transitions h3 { margin-top: 0; }
.fs-trans-list { display: flex; flex-direction: column; gap: 6px; }
.fs-trans-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 6px;
}
.fs-trans-flow {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.fs-trans-screen {
    font-weight: 600;
    font-size: .85rem;
    padding: 2px 8px;
    background: var(--c-bg-secondary);
    border-radius: 4px;
}
.fs-trans-arrow {
    font-size: 1.1rem;
    color: var(--c-primary);
}
.fs-trans-priority {
    font-size: .7rem;
    color: var(--c-text-secondary);
}
.fs-trans-actions { display: flex; gap: 4px; }
.fs-snippet-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Data sources */
.fs-datasource h3 { margin-top: 0; }
.fs-ds-list { display: flex; flex-direction: column; gap: 8px; }
.fs-ds-card {
    padding: 10px 12px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 6px;
}
.fs-ds-header { font-size: .9rem; margin-bottom: 4px; }
.fs-ds-detail { font-size: .8rem; color: var(--c-text-secondary); margin-bottom: 2px; }
.fs-ds-actions { margin-top: 6px; }
.fs-ds-help ul { padding-left: 20px; }
.fs-ds-help code { background: var(--c-bg-secondary); padding: 1px 5px; border-radius: 3px; font-size: .82rem; }

/* Localization */
.fs-localization h3 { margin-top: 0; }
.fs-l10n-screen {
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    background: var(--c-bg);
}
.fs-l10n-screen-header { margin-bottom: 8px; }
.fs-l10n-field {
    padding: 6px 0;
    border-top: 1px solid var(--c-border);
}
.fs-l10n-badge {
    font-size: .72rem;
    color: var(--c-text-secondary);
    margin-bottom: 3px;
}

/* Error / fallback */
.fs-errors h3 { margin-top: 0; }
.fs-error-section { margin-bottom: 12px; }
.fs-error-section h4 { margin: 0 0 6px 0; }
.fs-error-row {
    display: flex;
    align-items: center;
    padding: 4px 0;
}
.fs-error-rule {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: .88rem;
}
.fs-check-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .85rem;
    cursor: pointer;
}

/* Sandbox */
.fs-sandbox h3 { margin-top: 0; }
.fs-sandbox-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.fs-sandbox-crumb { font-size: .88rem; }
.fs-sandbox-form { display: flex; flex-direction: column; gap: 10px; }
.fs-sandbox-field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 3px; }
.fs-sandbox-radio { display: flex; align-items: center; gap: 6px; font-size: .85rem; padding: 2px 0; cursor: pointer; }
.fs-sandbox-helper { font-size: .78rem; color: var(--c-text-secondary); margin-top: 2px; }
.fs-sandbox-nav { margin-top: 12px; }
.fs-sandbox-values pre { word-break: break-all; }

/* Validation section in field editor */
.fs-validation-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--c-border); }
.fs-validation-section h4 { margin: 0 0 6px 0; font-size: .9rem; }
.fs-datasource-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--c-border); }
.fs-datasource-section h4 { margin: 0 0 6px 0; font-size: .9rem; }

/* Template modal */
.fs-tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    margin-top: 6px;
}
.fs-tpl-card {
    padding: 10px;
    border: 2px solid var(--c-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all .15s;
}
.fs-tpl-card:hover { border-color: var(--c-primary); }
.fs-tpl-card.selected {
    border-color: var(--c-primary);
    background: rgba(37,99,235,.06);
}

/* Preview helpers */
.flow-preview-heading {
    font-size: .95rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.flow-preview-body {
    font-size: .82rem;
    color: #555;
    margin-bottom: 6px;
}
.flow-preview-footer {
    font-size: .72rem;
    color: #999;
    border-top: 1px solid #eee;
    padding-top: 4px;
    margin-top: 6px;
}
.flow-preview-helper {
    font-size: .72rem;
    color: #666;
    margin-top: 2px;
}
.flow-preview-image {
    margin: 6px 0;
}

/* Responsive */
@media (max-width: 900px) {
    .fs-main { flex-direction: column; }
    .fs-sidebar { flex-direction: row; width: 100%; height: auto; overflow-x: auto; }
    .fs-sidebar .fs-tab { height: 36px; width: 44px; border-left: none; border-bottom: 3px solid transparent; }
    .fs-sidebar .fs-tab.active { border-bottom-color: var(--c-primary); border-left-color: transparent; }
    .fs-preview-col { width: 100%; border-left: none; border-top: 1px solid var(--c-border); }
}

/* ================================================================
   AUTOMATION CANVAS — sidebar + SVG viewport
   ================================================================ */
.canvas-container {
    display: flex;
    height: calc(100vh - var(--topbar-h) - 80px);
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.canvas-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #1a1a2e;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
}
.canvas-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.canvas-sidebar-header h3 {
    font-size: .95rem;
    color: #fff;
    word-break: break-word;
}
.canvas-palette-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #8888aa;
    margin-bottom: 8px;
}
.canvas-palette {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.palette-node {
    padding: 8px 10px;
    background: #2a2a3e;
    border-radius: 6px;
    cursor: grab;
    transition: background .15s;
}
.palette-node:hover { background: #3a3a50; }
.palette-node strong {
    display: block;
    font-size: .8rem;
    color: #fff;
}
.palette-node small {
    font-size: .7rem;
    color: #8888aa;
}
.canvas-sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid #2a2a3e;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.canvas-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .72rem;
    color: #8888aa;
}
.canvas-viewport {
    flex: 1;
    background: #16162a;
    position: relative;
    overflow: hidden;
    cursor: default;
}
.canvas-svg {
    width: 100%;
    height: 100%;
}
.canvas-node {
    cursor: move;
}
.canvas-node:hover rect { stroke-width: 3; }
.cv-port {
    cursor: crosshair;
    opacity: .7;
    transition: opacity .15s;
}
.cv-port:hover { opacity: 1; r: 8; }

/* Form utilities used in modals */
.form-row {
    display: flex;
    gap: 12px;
}
.form-row > * { flex: 1; }
.flex-1 { flex: 1; }

/* ================================================================
   TEMPLATE STUDIO: FORMATTING TOOLBAR & ENHANCEMENTS
   ================================================================ */
.studio-format-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 6px;
    padding: 4px 6px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 6px;
}
.fmt-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    width: 30px;
    height: 28px;
    cursor: pointer;
    font-size: .85rem;
    color: var(--c-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.fmt-btn:hover {
    background: var(--c-hover);
    border-color: var(--c-border);
    color: var(--c-text);
}
.fmt-mono { font-family: 'Courier New', monospace; font-weight: 700; }
.fmt-sep {
    width: 1px;
    height: 18px;
    background: var(--c-border);
    margin: 0 4px;
}

/* Emoji picker */
.studio-emoji-picker {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 6px;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    max-height: 180px;
    overflow-y: auto;
}
.emoji-item {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    background: transparent;
    border: none;
    transition: background .1s;
}
.emoji-item:hover { background: var(--c-hover); }

/* Character counters */
.studio-body-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}
.studio-char-count {
    font-size: .75rem;
    color: var(--c-text-secondary);
    margin-top: 2px;
    display: inline-block;
}
.studio-char-count.over-limit {
    color: #dc2626;
    font-weight: 600;
}

/* WhatsApp formatting in preview */
.wa-timestamp {
    font-size: .68rem;
    color: #999;
    text-align: right;
    margin-top: 2px;
}
.wa-placeholder {
    color: #aaa;
    font-style: italic;
}

/* Carousel preview */
.wa-carousel {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    scroll-snap-type: x mandatory;
}
.wa-carousel-card {
    min-width: 200px;
    max-width: 200px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    overflow: hidden;
    scroll-snap-align: start;
    flex-shrink: 0;
}
.wa-carousel-card .wa-card-img {
    width: 100%;
    height: 100px;
    background: #c8d6e5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    color: #636e72;
}
.wa-carousel-card .wa-card-body {
    padding: 8px 10px;
    font-size: .8rem;
    color: #303030;
}
.wa-carousel-card .wa-card-btns {
    padding: 0 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.wa-carousel-card .wa-btn {
    font-size: .75rem;
    padding: 5px 6px;
}

/* Carousel card editor */
.studio-card-row {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}
.studio-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.studio-card-header strong {
    font-size: .85rem;
    color: var(--c-text);
}
.studio-card-buttons {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--c-border);
}
.studio-card-buttons h5 {
    font-size: .78rem;
    color: var(--c-text-secondary);
    margin-bottom: 6px;
}

/* ================================================================
   INTERACTIVE COMPOSE: REPLY BUTTONS & LIST MESSAGES
   ================================================================ */
.compose-container {
    display: flex;
    gap: 24px;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}
.compose-editor {
    flex: 1;
    min-width: 0;
}
.compose-preview {
    width: 340px;
    flex-shrink: 0;
}
.compose-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    overflow: hidden;
}
.compose-mode-tab {
    flex: 1;
    padding: 10px 16px;
    text-align: center;
    cursor: pointer;
    background: var(--c-surface);
    border: none;
    font-size: .85rem;
    font-weight: 500;
    color: var(--c-text-secondary);
    transition: all .15s;
}
.compose-mode-tab.active {
    background: var(--c-primary);
    color: #fff;
}
.compose-mode-tab:hover:not(.active) {
    background: var(--c-hover);
}
.compose-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--c-border);
}
.compose-section:last-child { border-bottom: none; }
.compose-section h4 {
    font-size: .85rem;
    color: var(--c-text-secondary);
    margin-bottom: 8px;
}
.compose-list-section {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}
.compose-list-row {
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 6px;
}
.compose-list-row .form-row {
    margin-bottom: 4px;
}
.compose-list-row:last-child { margin-bottom: 0; }

/* WhatsApp list preview */
.wa-list-btn {
    background: #f0f2f5;
    border: 1px solid #dfe1e5;
    border-radius: 8px;
    text-align: center;
    padding: 10px;
    font-size: .82rem;
    color: var(--c-primary);
    font-weight: 500;
    margin-top: 6px;
    cursor: default;
}
.wa-reply-btns {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}
.wa-reply-btn {
    background: #f0f2f5;
    border: 1px solid #dfe1e5;
    border-radius: 20px;
    text-align: center;
    padding: 8px 12px;
    font-size: .82rem;
    color: var(--c-primary);
    font-weight: 500;
    cursor: default;
}

/* ================================================================
   STARTER LIBRARY
   ================================================================ */
.lib-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.lib-stats {
    font-size: 13px;
    color: #888;
    margin: 8px 0 4px;
}
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 8px;
}
.lib-card {
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow .15s, border-color .15s;
}
.lib-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 2px 12px rgba(59,130,246,.12);
}
.lib-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.lib-cat {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.lib-card-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 2px;
}
.lib-card-title-ar {
    font-size: 13px;
    color: #666;
    margin-bottom: 6px;
}
.lib-card-desc {
    font-size: 13px;
    color: #555;
    margin: 4px 0 8px;
    line-height: 1.4;
}
.lib-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.lib-tag {
    display: inline-block;
    background: #f0f4ff;
    color: #3b5998;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}
.lib-safety {
    font-size: 12px;
    color: #b45309;
    background: #fef3c7;
    padding: 4px 8px;
    border-radius: 4px;
    margin: 4px 0;
}
.lib-fallback {
    font-size: 12px;
    color: #1e40af;
    background: #dbeafe;
    padding: 4px 8px;
    border-radius: 4px;
    margin: 4px 0;
}

@media (max-width: 600px) {
    .lib-grid { grid-template-columns: 1fr; }
    .lib-filters { flex-direction: column; }
}

/* ================================================================
   RESPONSIVE: STUDIO & CANVAS
   ================================================================ */
@media (max-width: 900px) {
    .studio-container {
        flex-direction: column;
    }
    .studio-preview {
        max-width: 100%;
        order: -1;
    }
    .phone-frame { position: static; }
    .canvas-container { flex-direction: column; height: auto; min-height: 600px; }
    .canvas-sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 10px; gap: 8px; }
    .canvas-palette { flex-direction: row; flex-wrap: wrap; }
    .canvas-viewport { min-height: 500px; }
    .compose-container { flex-direction: column; }
    .compose-preview { width: 100%; order: -1; }
}

/* ================================================================
   CLINIC OPERATIONS
   ================================================================ */

/* Tabs */
.clinic-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--c-border); margin-bottom: 1rem; flex-wrap: wrap; }
.clinic-tab { background: none; border: none; padding: .6rem 1rem; cursor: pointer; font-size: .9rem; color: var(--c-text); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.clinic-tab:hover { background: var(--c-bg-alt); }
.clinic-tab.active { border-bottom-color: var(--c-primary); color: var(--c-primary); font-weight: 600; }

/* Operations workspace tabs */
.ops-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--c-border); margin-bottom: 1rem; flex-wrap: wrap; }
.ops-tab { background: none; border: none; padding: .55rem .85rem; cursor: pointer; font-size: .85rem; color: var(--c-text); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: background .15s, border-color .15s; }
.ops-tab:hover { background: var(--c-bg-alt); }
.ops-tab.active { border-bottom-color: var(--c-primary); color: var(--c-primary); font-weight: 600; }
.ops-subtab-header { margin-bottom: .75rem; }
.ops-subtab-header h2 { font-size: 1.1rem; margin: 0 0 .25rem 0; }
.ops-subtab-header p { font-size: .85rem; color: var(--c-text-muted); margin: 0; }

/* Clinic forms in modals */
.clinic-form { display: flex; flex-direction: column; gap: .7rem; }
.clinic-form label { display: flex; flex-direction: column; font-size: .85rem; font-weight: 500; gap: .25rem; }
.clinic-form input, .clinic-form select, .clinic-form textarea { padding: .45rem .6rem; border: 1px solid var(--c-border); border-radius: 6px; font-size: .9rem; }
.clinic-form input:focus, .clinic-form select:focus, .clinic-form textarea:focus { outline: none; border-color: var(--c-primary); }

/* Working hours grid */
.wh-groups { display: flex; flex-direction: column; gap: 1.2rem; padding: .5rem 0; }
.wh-group h3 { font-size: .95rem; margin-bottom: .4rem; }
.wh-grid { display: flex; flex-wrap: wrap; gap: .4rem; }
.wh-slot { background: #e0f2fe; padding: .3rem .7rem; border-radius: 4px; font-size: .82rem; }
.wh-inactive { background: #fee2e2; text-decoration: line-through; opacity: .6; }
.wh-day-row { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.wh-day-row input[type="checkbox"] { width: auto; }
.wh-day-row input[type="text"], .wh-day-row input:not([type]) { width: 70px; }

/* Readiness panel */
.readiness-panel { padding: .5rem 0; }
.readiness-status { padding: .8rem 1rem; border-radius: 8px; font-size: 1rem; display: flex; align-items: center; gap: 1rem; }
.readiness-operational { background: #dcfce7; color: #166534; }
.readiness-partial { background: #fef3c7; color: #92400e; }
.readiness-not_configured { background: #fee2e2; color: #991b1b; }
.readiness-mode { font-size: .85rem; opacity: .8; }
.readiness-note { font-size: .85rem; color: var(--c-text); opacity: .7; margin: .5rem 0 1rem; }
.readiness-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .6rem; }
.readiness-item { background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 8px; padding: .7rem; display: flex; justify-content: space-between; align-items: center; }
.readiness-item strong { font-size: .85rem; }
.readiness-item span { font-size: .9rem; font-weight: 600; }
.rdi-ok { border-left: 3px solid var(--c-success); }
.rdi-miss { border-left: 3px solid var(--c-danger); background: #fef2f2; }
.rdi-info { border-left: 3px solid var(--c-primary); }

/* Import Data + Status Labels */
.import-overview { background: var(--c-bg-alt); border: 1px solid var(--c-border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.import-overview h3 { margin: 0 0 .5rem; }
.import-status-bar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; font-size: .85rem; }
.status-label { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 600; text-transform: lowercase; }
.sl-verified { background: #dcfce7; color: #166534; }
.sl-imported { background: #dbeafe; color: #1d4ed8; }
.sl-inferred { background: #e0e7ff; color: #4338ca; }
.sl-missing { background: #fef3c7; color: #92400e; }
.sl-unknown { background: #f3f4f6; color: #6b7280; }

/* Appointment filters + stats bar */
.appt-filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.appt-filters select { padding: .4rem .6rem; border: 1px solid var(--c-border); border-radius: 6px; font-size: .85rem; }
.appt-stats-bar { display: flex; gap: .7rem; flex-wrap: wrap; margin-bottom: .8rem; font-size: .85rem; }
.appt-stat { padding: .2rem .5rem; border-radius: 4px; background: var(--c-bg-alt); }

/* Status badges */
.appt-badge { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .78rem; font-weight: 600; text-transform: uppercase; }
.appt-badge-new { background: #dbeafe; color: #1d4ed8; }
.appt-badge-pending_review, .appt-badge-pending { background: #fef3c7; color: #92400e; }
.appt-badge-confirmed { background: #dcfce7; color: #166534; }
.appt-badge-rescheduled { background: #e0e7ff; color: #4338ca; }
.appt-badge-canceled { background: #fee2e2; color: #991b1b; }
.appt-badge-completed { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.appt-badge-unavailable { background: #f3f4f6; color: #6b7280; }
.appt-badge-attempted { background: #fef3c7; color: #92400e; }
.appt-badge-scheduled_followup { background: #e0e7ff; color: #4338ca; }

/* Detail view */
.appt-detail { display: flex; flex-direction: column; gap: 1rem; }
.appt-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; font-size: .9rem; }
.appt-detail-actions { display: flex; gap: .5rem; align-items: center; padding-top: .5rem; border-top: 1px solid var(--c-border); }
.appt-detail-actions select { padding: .4rem; border: 1px solid var(--c-border); border-radius: 6px; flex: 1; }

/* Timeline */
.appt-timeline { display: flex; flex-direction: column; gap: .4rem; padding-left: 1rem; border-left: 2px solid var(--c-border); }
.appt-timeline-item { font-size: .82rem; display: flex; gap: .5rem; align-items: baseline; }
.appt-tl-time { color: var(--c-text); opacity: .5; min-width: 140px; font-size: .78rem; }
.appt-tl-action { font-weight: 600; }
.appt-tl-actor { opacity: .7; }

@media (max-width: 600px) {
    .clinic-tabs { gap: 0; }
    .clinic-tab { padding: .4rem .6rem; font-size: .8rem; }
    .ops-tabs { gap: 0; }
    .ops-tab { padding: .35rem .5rem; font-size: .78rem; }
    .readiness-grid { grid-template-columns: 1fr; }
    .appt-detail-grid { grid-template-columns: 1fr; }
}

/* ===================================================================
   BATCH R — Work Operations Dashboard & Unified Work Items
   =================================================================== */
.work-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.work-stat-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}
.work-stat-number { font-size: 2rem; font-weight: 700; color: var(--primary, #2563eb); line-height: 1.1; }
.work-stat-label { font-size: .85rem; color: var(--muted, #64748b); margin-top: 4px; }
.work-stat-warn .work-stat-number { color: var(--warning, #d97706); }
.work-stat-danger .work-stat-number { color: var(--danger, #dc2626); }

.work-dashboard-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}
.work-panel {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    padding: 16px;
}
.work-panel h3 { margin: 0 0 12px; font-size: 1rem; }
.work-panel-wide { grid-column: 1 / -1; }

/* Aging bars */
.work-aging-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.work-aging-label { width: 60px; font-size: .82rem; text-align: right; color: var(--muted, #64748b); }
.work-aging-track { flex: 1; height: 14px; background: var(--border, #e2e8f0); border-radius: 7px; overflow: hidden; }
.work-aging-fill { height: 100%; background: var(--primary, #2563eb); border-radius: 7px; transition: width .3s; }
.work-aging-fill.work-aging-danger { background: var(--danger, #dc2626); }
.work-aging-count { width: 30px; font-size: .82rem; font-weight: 600; }

/* Type split */
.work-type-split { display: flex; gap: 16px; flex-wrap: wrap; }
.work-type-item { font-size: .9rem; }
.work-type-icon { margin-right: 4px; }

/* Recent resolutions */
.work-recent-list { display: flex; flex-direction: column; gap: 6px; }
.work-recent-item { display: flex; align-items: center; gap: 8px; font-size: .85rem; padding: 4px 0; border-bottom: 1px solid var(--border, #e2e8f0); }
.work-recent-type { font-size: 1.1rem; }
.work-recent-outcome { background: var(--success-bg, #dcfce7); color: var(--success, #16a34a); padding: 1px 6px; border-radius: 4px; font-size: .78rem; }
.work-recent-time { margin-left: auto; color: var(--muted, #64748b); font-size: .78rem; }

/* Work table */
.work-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.work-table th { text-align: left; padding: 8px 6px; border-bottom: 2px solid var(--border, #e2e8f0); font-weight: 600; font-size: .82rem; color: var(--muted, #64748b); }
.work-table td { padding: 8px 6px; border-bottom: 1px solid var(--border, #e2e8f0); vertical-align: middle; }
.work-table tbody tr:hover { background: var(--hover, #f1f5f9); }

/* Work items filters */
.work-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
}
.work-filter-check { display: flex; align-items: center; gap: 4px; font-size: .85rem; cursor: pointer; }
.work-filter-check input { margin: 0; }

/* Bulk bar */
.work-bulk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--primary-bg, #eff6ff);
    border: 1px solid var(--primary, #2563eb);
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: .88rem;
}

/* Overdue / blocked rows */
.work-row-overdue { background: #fef2f2 !important; }
.work-row-blocked { border-left: 3px solid var(--warning, #d97706); }

/* Priority badges */
.priority-badge { padding: 1px 8px; border-radius: 4px; font-size: .78rem; font-weight: 600; }
.priority-urgent { background: #fecaca; color: #991b1b; }
.priority-high { background: #fed7aa; color: #9a3412; }
.priority-normal { background: #e2e8f0; color: #334155; }
.priority-low { background: #f0fdf4; color: #166534; }

/* Blocker badges */
.blocker-badge { padding: 1px 8px; border-radius: 4px; font-size: .78rem; font-weight: 600; background: #fef3c7; color: #92400e; }
.blocker-badge-sm { padding: 0 4px; border-radius: 3px; font-size: .72rem; background: #fef3c7; color: #92400e; }

/* Status badges for work_status */
.status-open { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #e0e7ff; color: #3730a3; }
.status-resolved { background: #dcfce7; color: #166534; }

/* Pagination */
.work-pagination { display: flex; gap: 8px; margin-top: 12px; justify-content: center; }
.work-summary-bar { font-size: .85rem; color: var(--muted, #64748b); margin-bottom: 8px; }

/* Text utility */
.text-danger { color: var(--danger, #dc2626) !important; }
.text-warn { color: var(--warning, #d97706) !important; }
.text-muted { color: var(--muted, #64748b); }

/* Sidebar work items (inbox convergence) */
.sidebar-work-items { display: flex; flex-direction: column; gap: 4px; }
.sidebar-work-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 4px;
    background: var(--hover, #f1f5f9);
    cursor: pointer;
    font-size: .82rem;
    transition: background .15s;
}
.sidebar-work-item:hover { background: var(--primary-bg, #eff6ff); }
.sidebar-work-status { font-size: .75rem; }

@media (max-width: 600px) {
    .work-dashboard-grid { grid-template-columns: repeat(2, 1fr); }
    .work-dashboard-panels { grid-template-columns: 1fr; }
    .work-filters { flex-direction: column; }
    .work-items-table { font-size: .8rem; }
    .work-items-table th:nth-child(6),
    .work-items-table td:nth-child(6),
    .work-items-table th:nth-child(8),
    .work-items-table td:nth-child(8) { display: none; }
}
