:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #172026;
    --muted: #6b7785;
    --line: #dfe4ea;
    --line-strong: #c8d1dc;
    --accent: #0f766e;
    --accent-soft: #e5f4f2;
    --green: #0f766e;
    --green-hover: #115e59;
    --green-soft: rgba(20, 184, 166, 0.14);
    --amber: #b45309;
    --amber-soft: #fff4df;
    --red: #dc2626;
    --red-hover: #b91c1c;
    --red-soft: rgba(239, 68, 68, 0.14);
    --blue: #2563eb;
    --blue-hover: #1d4ed8;
    --blue-soft: rgba(59, 130, 246, 0.14);
    --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

.dark {
    --bg: #0f172a;
    --sidebar-bg: #111827;
    --panel: #182033;
    --ink: #e5e7eb;
    --muted: #94a3b8;
    --line: #334155;
    --line-strong: #475569;
    --accent: #0f766e;
    --accent-soft: rgba(15, 118, 110, 0.2);
    --green: #0f766e;
    --green-hover: #115e59;
    --green-soft: rgba(20, 184, 166, 0.14);
    --amber: #f59e0b;
    --amber-soft: #78350f;
    --red: #dc2626;
    --red-hover: #b91c1c;
    --red-soft: rgba(239, 68, 68, 0.14);
    --blue: #2563eb;
    --blue-hover: #1d4ed8;
    --blue-soft: rgba(59, 130, 246, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
    overflow-x: hidden;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    min-width: 0;
    overflow-x: hidden;
}

img,
video,
canvas,
iframe {
    max-width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eef2f3;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    overflow-y: auto;
}

.dark .sidebar {
    background: var(--sidebar-bg);
}

.brand {
    padding: 8px 10px 18px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
}

.brand-name {
    font-size: 18px;
    line-height: 1.15;
    font-weight: 800;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.nav-list {
    display: grid;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 6px;
    color: #344054;
    border: 1px solid transparent;
}

.dark .nav-link {
    font-size: 14px;
    font-weight: 500;
    color: #cbd5e1;
}

.dark .nav-link:hover {
    color: #e2e8f0;
}

.nav-link:hover,
.nav-link.active {
    background: var(--accent-soft);
    color: #0f4f49;
    border-color: #cae7e2;
}

.dark .nav-link.active {
    color: #4ade80;
}

.nav-badge {
    min-width: 20px;
    min-height: 20px;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
}

.main {
    min-width: 0;
}

.topbar {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    background: rgba(255, 255, 255, .95);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.dark .topbar {
    background: rgba(17, 24, 39, .95);
}

.page {
    padding: 24px;
    width: 100%;
    max-width: 1680px;
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-title {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
}

.dark .page-title {
    font-weight: 600;
    color: #f1f5f9;
}

.page-kicker {
    color: var(--muted);
    margin-top: 4px;
}

.dark .page-kicker {
    color: #cbd5e1;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid.cards {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.panel {
    padding: 16px;
}

.metric-card {
    padding: 14px;
    min-height: 96px;
}

.metric-label {
    color: var(--muted);
    font-size: 12px;
}

.metric-value {
    margin-top: 10px;
    font-weight: 800;
    font-size: 22px;
    line-height: 1.1;
}

.metric-card.success {
    border-left: 4px solid var(--green);
}

.metric-card.warning {
    border-left: 4px solid var(--amber);
}

.metric-card.danger {
    border-left: 4px solid var(--red);
}

.metric-card.neutral {
    border-left: 4px solid var(--blue);
}

.toolbar,
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 10px;
    min-width: 0;
}

.filters {
    margin-bottom: 16px;
}

.section-title {
    margin: 0 0 12px;
    font-size: 18px;
    line-height: 1.2;
}

.dark .section-title {
    font-weight: 600;
    color: #f1f5f9;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    min-width: 0;
    max-width: 100%;
}

.dark .user-chip {
    background: var(--panel);
    border-color: var(--line);
}

.dark .user-chip strong {
    color: #f1f5f9;
}

.user-chip span span {
    display: block;
    font-size: 11px;
    line-height: 1.1;
}

.user-chip strong,
.user-chip .muted {
    overflow-wrap: anywhere;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    object-fit: cover;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid #b7ded8;
}

.avatar-initials {
    display: inline-grid;
    place-items: center;
    font-weight: 800;
}

.profile-panel {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.profile-photo-large {
    width: 160px;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--accent-soft);
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--accent);
    font-size: 48px;
    font-weight: 800;
}

.profile-photo-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.field {
    display: grid;
    gap: 6px;
}

.field.full {
    grid-column: 1 / -1;
}

label {
    color: #344054;
    font-size: 12px;
    font-weight: 700;
}

.dark label {
    color: #cbd5e1;
}

.input,
input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
}

.dark .input,
.dark input,
.dark select,
.dark textarea {
    background: var(--sidebar-bg);
    border-color: var(--line-strong);
    color: var(--ink);
}

.dark input::placeholder,
.dark select::placeholder,
.dark textarea::placeholder {
    color: #94a3b8;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    font-weight: 700;
}

.dark .btn {
    background: var(--panel);
    border-color: var(--line-strong);
    color: var(--ink);
    font-weight: 600;
}

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

.btn.primary:hover {
    background: var(--green-hover);
    border-color: var(--green-hover);
}

.btn.danger {
    border-color: var(--red);
    color: var(--red);
}

.btn.danger:hover {
    background: var(--red-soft);
}

.dark .btn.danger {
    background: transparent;
    border-color: var(--red);
    color: var(--red);
}

.dark .btn.danger:hover {
    background: var(--red-soft);
}

.btn.small {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: #344054;
    background: #fafbfc;
    font-size: 12px;
    text-transform: uppercase;
}

.dark th {
    color: var(--muted);
    background: #1f2937;
    font-weight: 600;
}

.dark td {
    color: #e2e8f0;
}

td.wrap {
    white-space: normal;
    min-width: 220px;
}

.actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.modal {
    width: min(420px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 18px 40px rgba(16, 24, 40, .18);
}

.modal::backdrop {
    background: rgba(15, 23, 42, .35);
}

.modal h3 {
    margin: 0 0 8px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge.ok,
.badge.paid,
.badge.approved,
.badge.audited,
.badge.active {
    color: var(--green);
    background: var(--green-soft);
}

.badge.pending,
.badge.payment-pending,
.badge.pending-audit,
.badge.partially-paid,
.badge.first-duplicate,
.badge.surplus,
.badge.low-stock {
    color: var(--amber);
    background: var(--amber-soft);
}

.badge.not-paid,
.badge.not-payable,
.badge.overdue,
.badge.banned,
.badge.rejected,
.badge.flagged,
.badge.not-in-budget,
.badge.deficit,
.badge.duplicate-copy,
.badge.shortage,
.badge.inactive,
.badge.not-checked {
    color: var(--red);
    background: var(--red-soft);
}

.badge.neutral {
    color: var(--blue);
    background: var(--blue-soft);
}

.badge.non-refundable {
    color: var(--blue);
    background: var(--blue-soft);
}

.badge.allowed {
    color: var(--green);
    background: var(--green-soft);
}

.dark .badge.ok,
.dark .badge.paid,
.dark .badge.approved,
.dark .badge.audited,
.dark .badge.active,
.dark .badge.allowed {
    color: #4ade80;
    background: rgba(34, 197, 94, 0.2);
}

.dark .badge.pending,
.dark .badge.payment-pending,
.dark .badge.pending-audit,
.dark .badge.partially-paid,
.dark .badge.first-duplicate,
.dark .badge.surplus,
.dark .badge.low-stock {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.2);
}

.dark .badge.not-paid,
.dark .badge.not-payable,
.dark .badge.overdue,
.dark .badge.banned,
.dark .badge.rejected,
.dark .badge.flagged,
.dark .badge.not-in-budget,
.dark .badge.deficit,
.dark .badge.duplicate-copy,
.dark .badge.shortage,
.dark .badge.inactive,
.dark .badge.not-checked {
    color: #f87171;
    background: rgba(248, 113, 113, 0.2);
}

.dark .badge.neutral,
.dark .badge.non-refundable {
    color: #60a5fa;
    background: rgba(96, 165, 250, 0.2);
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    background: #fff;
}

.dark .alert {
    background: var(--panel);
    border-color: var(--line);
}

.alert.success {
    border-color: #b7e4c7;
    background: var(--green-soft);
    color: var(--green);
}

.dark .alert.success {
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.alert.error {
    border-color: #f0b4af;
    background: var(--red-soft);
    color: var(--red);
}

.dark .alert.error {
    border-color: rgba(248, 113, 113, 0.4);
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.tab {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #475467;
    font-size: 12px;
    font-weight: 700;
}

.dark .tab {
    background: var(--panel);
    border-color: var(--line);
    color: var(--ink);
}

.tab.active {
    color: #0f4f49;
    border-color: #b7ded8;
    background: var(--accent-soft);
}

.dark .tab.active {
    color: #4ade80;
    border-color: var(--green);
    background: var(--green-soft);
}

.bar-chart {
    display: grid;
    gap: 10px;
}

.bar-row {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr) 90px;
    gap: 10px;
    align-items: center;
}

.bar-track {
    height: 12px;
    background: #edf0f3;
    border-radius: 999px;
    overflow: hidden;
}

.dark .bar-track {
    background: var(--line);
}

.bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 999px;
}

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

.dark .muted {
    color: #cbd5e1;
}

.amount-positive {
    color: var(--green);
    font-weight: 800;
}

.amount-negative {
    color: var(--red);
    font-weight: 800;
}

.amount-zero {
    color: var(--blue);
    font-weight: 800;
}

.amount-blue {
    color: var(--blue);
    font-weight: 800;
}

.pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

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

.pagination svg {
    width: 18px;
    height: 18px;
}

.pagination a,
.pagination span {
    font-size: 12px;
}

.permission-wrap {
    max-height: 70vh;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.permission-table th:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
}

.permission-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.permission-table td,
.permission-table th {
    text-align: center;
}

.permission-table th:first-child {
    text-align: left;
    min-width: 220px;
}

.check-cell {
    display: inline-grid;
    place-items: center;
}

.check-cell input {
    width: 18px;
    height: 18px;
    min-height: 18px;
}

.override-select {
    min-width: 126px;
    min-height: 32px;
    padding: 5px 7px;
    font-size: 12px;
}

.unread-row td {
    background: var(--blue-soft);
}

.dark .unread-row td {
    background: rgba(59, 130, 246, 0.15);
}

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

.message-bubble {
    width: min(780px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.dark .message-bubble {
    background: var(--panel);
    border-color: var(--line);
}

.message-bubble.mine {
    justify-self: end;
    border-color: #b7ded8;
    background: #f8fffd;
}

.dark .message-bubble.mine {
    border-color: var(--green);
    background: var(--green-soft);
}

.message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.message-body {
    white-space: pre-wrap;
    line-height: 1.5;
}

.details {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    border-top: 1px solid var(--line);
}

.details dt,
.details dd {
    margin: 0;
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
}

.details dt {
    color: var(--muted);
    font-weight: 700;
    background: #fafbfc;
}

.dark .details dt {
    background: #1f2937;
}

.queue-pay-form {
    display: grid;
    grid-template-columns: 136px 104px 128px 120px 180px auto;
    gap: 6px;
    align-items: center;
    min-width: 760px;
}

.queue-pay-form input,
.queue-pay-form select {
    min-height: 30px;
}

@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .auth-page {
        min-height: 100svh;
        padding: 12px;
        align-items: center;
    }

    .auth-card {
        width: 100%;
        padding: 18px;
    }

    .app-shell {
        display: block;
        min-width: 0;
    }

    .sidebar {
        position: relative;
        top: auto;
        height: auto;
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 12px;
        overflow: visible;
    }

    .brand {
        padding: 6px 6px 12px;
        margin-bottom: 10px;
    }

    .brand-name {
        font-size: 16px;
    }

    .nav-list {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .nav-link {
        min-height: 42px;
        padding: 9px 10px;
        font-size: 13px;
    }

    .topbar {
        position: relative;
        height: auto;
        min-height: 0;
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .topbar > div:first-child {
        min-width: 0;
    }

    .topbar > div:first-child strong {
        display: block;
        overflow-wrap: anywhere;
        line-height: 1.25;
    }

    .topbar .toolbar,
    .page-header .toolbar,
    .filters,
    .modal-actions,
    .auth-card .toolbar {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        align-items: stretch;
    }

    .topbar .btn,
    .topbar .user-chip,
    .page-header .btn,
    .filters .btn,
    .auth-card .btn,
    .modal-actions .btn {
        width: 100%;
    }

    .user-chip {
        border-radius: 8px;
        justify-content: flex-start;
    }

    .page {
        padding: 12px;
    }

    .page-header {
        display: grid;
        gap: 12px;
    }

    .page-title {
        font-size: 20px;
        overflow-wrap: anywhere;
    }

    .panel {
        padding: 12px;
    }

    .grid.cards,
    .grid.two,
    .form-grid,
    .profile-panel {
        grid-template-columns: 1fr;
    }

    .metric-card {
        min-height: 84px;
    }

    .metric-value {
        font-size: 20px;
    }

    .tabs {
        display: grid;
        grid-template-columns: 1fr;
    }

    .tab {
        border-radius: 6px;
        text-align: center;
    }

    .table-wrap {
        margin-inline: -4px;
        padding-bottom: 4px;
    }

    table {
        min-width: 680px;
    }

    th,
    td {
        padding: 8px 10px;
        font-size: 12px;
    }

    td.wrap {
        min-width: 180px;
    }

    .actions,
    .audit-actions,
    .audit-actions form,
    .audit-mini-form {
        display: grid !important;
        grid-template-columns: 1fr;
        justify-content: stretch;
        width: 100%;
        min-width: 0 !important;
    }

    .actions .btn,
    .audit-actions .btn,
    .audit-mini-form .btn,
    .audit-actions input,
    .audit-mini-form input {
        width: 100% !important;
        max-width: none !important;
    }

    .details {
        grid-template-columns: 1fr;
    }

    .details dt {
        border-bottom: 0;
        padding-bottom: 4px;
    }

    .details dd {
        padding-top: 4px;
        overflow-wrap: anywhere;
    }

    .profile-photo-large {
        width: min(160px, 100%);
        justify-self: center;
    }

    .permission-wrap {
        max-height: none;
    }

    .permission-table {
        min-width: 980px;
    }

    .permission-table th:first-child {
        min-width: 180px;
    }

    .override-select {
        min-width: 116px;
    }

    .message-bubble,
    .message-bubble.mine {
        justify-self: stretch;
        width: 100%;
    }

    .message-meta {
        display: grid;
    }

    .bar-row {
        grid-template-columns: 62px minmax(0, 1fr) 62px;
        gap: 8px;
        font-size: 12px;
    }

    .queue-pay-form {
        grid-template-columns: 1fr;
        min-width: 260px;
    }

    .pagination {
        justify-content: stretch;
    }

    .pagination nav {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .modal {
        width: calc(100vw - 24px);
        padding: 14px;
    }
}

@media (min-width: 481px) and (max-width: 767px) {
    .auth-page {
        min-height: 100svh;
        padding: 18px;
    }

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

    .app-shell {
        display: block;
    }

    .sidebar {
        position: relative;
        top: auto;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 14px;
        overflow: visible;
    }

    .nav-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .nav-link {
        min-height: 42px;
        font-size: 13px;
    }

    .topbar {
        position: relative;
        height: auto;
        min-height: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px 16px;
    }

    .topbar .toolbar,
    .page-header .toolbar,
    .auth-card .toolbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        align-items: stretch;
    }

    .filters {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .topbar .user-chip {
        grid-column: 1 / -1;
        border-radius: 8px;
    }

    .topbar .btn,
    .page-header .btn,
    .filters .btn,
    .auth-card .btn {
        width: 100%;
    }

    .page {
        padding: 16px;
    }

    .page-header {
        display: grid;
        gap: 12px;
    }

    .grid.cards,
    .grid.two,
    .form-grid,
    .profile-panel {
        grid-template-columns: 1fr;
    }

    .tabs {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tab {
        border-radius: 6px;
        text-align: center;
    }

    .details {
        grid-template-columns: 160px minmax(0, 1fr);
    }

    .permission-table {
        min-width: 1040px;
    }

    .message-bubble,
    .message-bubble.mine {
        justify-self: stretch;
        width: 100%;
    }

    .bar-row {
        grid-template-columns: 72px minmax(0, 1fr) 78px;
    }

    .queue-pay-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        min-width: 520px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: relative;
        top: auto;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 14px 18px;
        overflow: visible;
    }

    .brand {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 14px;
        padding: 6px 8px 12px;
    }

    .nav-list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .nav-link {
        min-height: 40px;
        font-size: 13px;
    }

    .topbar {
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        padding: 12px 20px;
    }

    .topbar .toolbar {
        flex: 1 1 420px;
        justify-content: flex-end;
    }

    .page {
        padding: 20px;
    }

    .page-header {
        flex-wrap: wrap;
    }

    .grid.cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid.two,
    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
    }

    .filters .btn {
        width: 100%;
    }

    .permission-table {
        min-width: 1080px;
    }

    .queue-pay-form {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        min-width: 700px;
    }
}

@media (min-width: 1025px) {
    .app-shell {
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .sidebar {
        position: sticky;
        height: 100vh;
    }
}

@media (min-width: 1441px) {
    .page {
        padding-left: 32px;
        padding-right: 32px;
    }

    .grid.cards {
        grid-template-columns: repeat(6, minmax(150px, 1fr));
    }

    .grid.two {
        grid-template-columns: repeat(2, minmax(420px, 1fr));
    }
}

@media print {
    .sidebar,
    .topbar,
    .filters,
    .toolbar,
    .actions,
    .btn {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .page {
        padding: 0;
    }

    .panel,
    .card {
        box-shadow: none;
        border: 0;
    }
}


/* === Exceel One responsive device layout fix === */
.mobile-menu-toggle {
    display: none;
}

* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
}

img,
video,
canvas {
    max-width: 100%;
    height: auto;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px) {
    html,
    body {
        overflow-x: hidden;
    }

    .app-shell {
        display: block;
        width: 100%;
        min-height: 100vh;
    }

    .sidebar {
        position: static !important;
        width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        padding: 18px !important;
        border-right: 0 !important;
        border-bottom: 1px solid rgba(148, 163, 184, 0.25);
    }

    .brand {
        margin-bottom: 12px;
    }

    .mobile-menu-toggle {
        display: flex;
        width: 100%;
        min-height: 44px;
        justify-content: center;
        align-items: center;
        gap: 8px;
        border-radius: 12px;
        border: 1px solid rgba(148, 163, 184, 0.45);
        background: transparent;
        color: inherit;
        font-weight: 800;
        font-size: 16px;
        cursor: pointer;
    }

    .nav-list {
        display: none !important;
        margin-top: 14px !important;
    }

    .sidebar.mobile-open .nav-list {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .nav-link {
        min-height: 48px;
        padding: 12px 14px !important;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .main {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .topbar {
        position: static !important;
        display: flex !important;
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
        padding: 16px 18px !important;
    }

    .topbar > div:first-child {
        width: 100%;
    }

    .topbar .toolbar {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        align-items: stretch;
    }

    .topbar .toolbar .btn,
    .topbar .toolbar form,
    .topbar .toolbar form .btn,
    .topbar .toolbar .user-chip {
        width: 100%;
        justify-content: center;
    }

    .user-chip {
        min-width: 0;
    }

    .user-chip span {
        min-width: 0;
    }

    .page {
        padding: 18px !important;
        width: 100%;
    }

    .page-header {
        display: flex !important;
        flex-direction: column;
        align-items: stretch !important;
        gap: 14px;
    }

    .page-header .toolbar {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .page-header .toolbar .btn,
    .page-header .toolbar form,
    .page-header .toolbar form .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .filters {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px !important;
        align-items: end;
    }

    .field,
    .field input,
    .field select,
    .field textarea {
        width: 100%;
        max-width: 100%;
    }

    .filters .btn {
        width: 100%;
        justify-content: center;
    }

    .panel {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .table-wrap table {
        min-width: 760px;
    }

    .tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .tab {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 16px !important;
    }

    .sidebar.mobile-open .nav-list {
        grid-template-columns: 1fr;
    }

    .topbar .toolbar,
    .page-header .toolbar,
    .filters {
        grid-template-columns: 1fr !important;
    }

    .page {
        padding: 14px !important;
    }

    .page-title {
        font-size: 30px !important;
        line-height: 1.15;
    }

    .btn,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    .tab {
        flex-basis: 100%;
    }

    .table-wrap table {
        min-width: 700px;
    }
}

@media (min-width: 1025px) {
    .mobile-menu-toggle {
        display: none !important;
    }
}
/* === End Exceel One responsive device layout fix === */


/* === Mobile/tablet appbar + drawer layout === */
.mobile-appbar,
.mobile-drawer-overlay,
.mobile-drawer-footer {
    display: none;
}

@media (max-width: 1024px) {
    html,
    body {
        overflow-x: hidden;
    }

    body.drawer-open {
        overflow: hidden;
    }

    .mobile-appbar {
        position: sticky;
        top: 0;
        z-index: 1200;
        display: flex;
        align-items: center;
        gap: 14px;
        min-height: 72px;
        padding: 10px 16px;
        background: var(--panel, #111827);
        border-bottom: 1px solid rgba(148, 163, 184, 0.25);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    }

    .mobile-drawer-button,
    .mobile-appbar-icon {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        border-radius: 999px;
        border: 1px solid rgba(148, 163, 184, 0.35);
        background: rgba(15, 23, 42, 0.18);
        color: inherit;
        font-size: 24px;
        font-weight: 900;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-drawer-button {
        border: 3px solid #2563eb;
        font-size: 28px;
    }

    .mobile-appbar-spacer {
        flex: 1;
    }

    .mobile-profile-chip {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
    }

    .mobile-profile-chip .avatar {
        width: 48px;
        height: 48px;
        border-radius: 999px;
    }

    .mobile-badge {
        position: absolute;
        top: -7px;
        right: -4px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 24px;
        height: 24px;
        padding: 0 6px;
        border-radius: 999px;
        background: #ef4444;
        color: #fff;
        font-size: 13px;
        font-weight: 900;
    }

    .app-shell {
        display: block !important;
        width: 100%;
        min-height: 100vh;
    }

    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        z-index: 1300;
        width: min(82vw, 380px) !important;
        max-width: 380px;
        height: 100vh !important;
        min-height: 100vh !important;
        padding: 22px 18px !important;
        transform: translateX(-105%);
        transition: transform 220ms ease;
        overflow-y: auto;
        border-right: 1px solid rgba(148, 163, 184, 0.28);
        box-shadow: 18px 0 45px rgba(0, 0, 0, 0.35);
    }

    body.drawer-open .sidebar {
        transform: translateX(0);
    }

    .mobile-drawer-overlay {
        position: fixed;
        inset: 0;
        z-index: 1250;
        display: block;
        background: rgba(0, 0, 0, 0.58);
        opacity: 0;
        pointer-events: none;
        transition: opacity 220ms ease;
    }

    body.drawer-open .mobile-drawer-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar .brand {
        padding-bottom: 16px;
        margin-bottom: 16px;
        border-bottom: 1px solid rgba(148, 163, 184, 0.25);
    }

    .nav-list {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        margin-top: 0 !important;
    }

    .nav-link {
        min-height: 52px;
        display: flex !important;
        align-items: center;
        justify-content: flex-start !important;
        text-align: left !important;
        padding: 13px 16px !important;
        border-radius: 14px;
        font-size: 16px;
        font-weight: 800;
    }

    .mobile-menu-toggle {
        display: none !important;
    }

    .mobile-drawer-footer {
        display: block;
        margin-top: 18px;
        padding-top: 16px;
        border-top: 1px solid rgba(148, 163, 184, 0.25);
    }

    .mobile-drawer-profile {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        border-radius: 14px;
        color: inherit;
        text-decoration: none;
        border: 1px solid rgba(148, 163, 184, 0.25);
        margin-bottom: 12px;
    }

    .mobile-drawer-profile .avatar {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
    }

    .mobile-drawer-profile strong,
    .mobile-drawer-profile small {
        display: block;
        line-height: 1.2;
    }

    .mobile-drawer-profile small {
        opacity: 0.75;
        margin-top: 3px;
    }

    .mobile-logout-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .main {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .main > .topbar {
        display: none !important;
    }

    .page {
        width: 100%;
        padding: 20px !important;
    }

    .page-header {
        display: flex !important;
        flex-direction: column;
        align-items: stretch !important;
        gap: 14px;
    }

    .page-header .toolbar {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .page-header .toolbar .btn,
    .page-header .toolbar form,
    .page-header .toolbar form .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .filters {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px !important;
        align-items: end;
    }

    .field,
    .field input,
    .field select,
    .field textarea {
        width: 100%;
        max-width: 100%;
    }

    .filters .btn {
        width: 100%;
        justify-content: center;
    }

    .panel {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-wrap table {
        min-width: 760px;
    }

    .tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .tab {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }
}

@media (max-width: 480px) {
    .mobile-appbar {
        min-height: 66px;
        padding: 9px 12px;
        gap: 10px;
    }

    .mobile-drawer-button,
    .mobile-appbar-icon,
    .mobile-profile-chip .avatar {
        width: 44px;
        height: 44px;
    }

    .sidebar {
        width: 82vw !important;
        padding: 18px 16px !important;
    }

    .page {
        padding: 16px !important;
    }

    .page-title {
        font-size: 30px !important;
        line-height: 1.15;
    }

    .page-header .toolbar,
    .filters {
        grid-template-columns: 1fr !important;
    }

    .tab {
        flex-basis: 100%;
    }

    .btn,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    .table-wrap table {
        min-width: 700px;
    }
}

@media (min-width: 1025px) {
    .mobile-appbar,
    .mobile-drawer-overlay,
    .mobile-drawer-footer {
        display: none !important;
    }

    .sidebar {
        transform: none !important;
    }
}
/* === End mobile/tablet appbar + drawer layout === */


/* Optional task/deadline message styling */
.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.checkbox-line input {
    width: 18px;
    height: 18px;
}

.message-deadline-form {
    display: grid;
    grid-template-columns: minmax(130px, 180px) minmax(180px, 230px) auto;
    gap: 8px;
    align-items: end;
    margin: 10px 0 12px;
    padding: 10px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.04);
}

.message-deadline-form .field {
    margin: 0;
}

.message-deadline-form label {
    font-size: 12px;
    font-weight: 800;
}

@media (max-width: 768px) {
    .message-deadline-form {
        grid-template-columns: 1fr;
    }

    .message-deadline-form .btn {
        width: 100%;
        justify-content: center;
    }
}

/* WhatsApp-style message page: only chat area scrolls */
.messages-chat-page {
    height: calc(100vh - 120px);
    min-height: 620px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-chat-page > .page-header {
    flex: 0 0 auto;
}

.messages-chat-page .message-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding-right: 10px;
    padding-bottom: 16px;
    scroll-behavior: smooth;
}

.messages-chat-page .chat-reply-form {
    flex: 0 0 auto;
    margin-top: 12px !important;
    max-height: 42vh;
    overflow-y: auto;
}

.message-thread::-webkit-scrollbar {
    width: 8px;
}

.message-thread::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.45);
}

/* Transparent sound toggle button */
.sound-unlock-button {
    position: fixed !important;
    left: 16px !important;
    bottom: 16px !important;
    z-index: 999999 !important;
    border: 1px solid rgba(148, 163, 184, 0.35) !important;
    border-radius: 999px !important;
    padding: 9px 13px !important;
    font-size: 13px !important;
    font-weight: 800 !important;
    cursor: pointer !important;
    color: #ffffff !important;
    background: rgba(37, 99, 235, 0.45) !important;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px rgba(0,0,0,.18) !important;
    opacity: 0.72;
}

.sound-unlock-button:hover {
    opacity: 1;
}

.sound-unlock-button.sound-on {
    background: rgba(15, 118, 110, 0.45) !important;
}

.sound-unlock-button.sound-off {
    background: rgba(100, 116, 139, 0.38) !important;
}

@media (max-width: 768px) {
    .messages-chat-page {
        height: calc(100vh - 92px);
        min-height: calc(100vh - 92px);
    }

    .messages-chat-page .chat-reply-form {
        max-height: 45vh;
    }

    .sound-unlock-button {
        left: 10px !important;
        bottom: 10px !important;
        padding: 8px 11px !important;
        font-size: 12px !important;
    }
}

/* WhatsApp-style conversations list */
.conversations-panel {
    padding: 0 !important;
    overflow: hidden;
}

.conversation-row {
    display: grid;
    grid-template-columns: 54px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 16px 18px;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.conversation-row:hover,
.unread-conversation {
    background: rgba(15, 118, 110, 0.08);
}

.conversation-avatar,
.chat-person-avatar {
    width: 52px;
    height: 52px;
    border-radius: 999px;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: rgba(15, 118, 110, 0.16);
    border: 2px solid rgba(148, 163, 184, 0.35);
    font-weight: 900;
}

.conversation-avatar img,
.chat-person-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.conversation-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.conversation-top span,
.conversation-preview {
    color: var(--muted, #94a3b8);
    font-size: 13px;
}

.conversation-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.conversation-unread {
    min-width: 26px;
    height: 26px;
    padding: 0 7px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: #0f766e;
    color: #fff;
    font-size: 13px;
    font-weight: 900;
}

/* WhatsApp-style chat page */
.whatsapp-chat-page {
    height: calc(100vh - 96px);
    min-height: 620px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-person-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 0 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.chat-back-btn {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    text-decoration: none;
    color: inherit;
    font-size: 34px;
    font-weight: 800;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.chat-person-title h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.1;
}

.chat-person-title small {
    color: var(--muted, #94a3b8);
    font-weight: 700;
}

.whatsapp-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 10px 18px 0;
    scroll-behavior: smooth;
}

.whatsapp-thread::-webkit-scrollbar {
    width: 8px;
}

.whatsapp-thread::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.45);
}

.chat-badges {
    gap: 6px !important;
    flex-wrap: wrap;
}

.chat-composer {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 46px 1fr 52px;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border-radius: 22px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.22);
}

.chat-plus-btn,
.chat-send-btn {
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 0;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    font-size: 26px;
    font-weight: 900;
}

.chat-plus-btn {
    background: rgba(148, 163, 184, 0.14);
    color: #fff;
    border: 1px solid rgba(148, 163, 184, 0.35);
}

.chat-send-btn {
    background: #0f766e;
    color: #fff;
}

.chat-compose-main {
    min-width: 0;
}

.chat-textarea {
    width: 100%;
    min-height: 46px;
    max-height: 140px;
    resize: none;
    overflow-y: auto;
    border-radius: 18px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    line-height: 1.35;
}

.chat-options-panel {
    display: none;
    margin-bottom: 10px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(15, 23, 42, 0.82);
}

.chat-composer.options-open .chat-options-panel {
    display: grid;
    gap: 10px;
}

.chat-options-panel .task-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.sound-unlock-button {
    opacity: 0.45 !important;
    padding: 7px 10px !important;
    font-size: 12px !important;
    max-width: 115px;
}

.sound-unlock-button:hover {
    opacity: 0.95 !important;
}

@media (max-width: 768px) {
    .whatsapp-chat-page {
        height: calc(100vh - 84px);
        min-height: calc(100vh - 84px);
    }

    .chat-person-header {
        padding: 10px 0 12px;
    }

    .chat-person-title h1 {
        font-size: 22px;
    }

    .whatsapp-thread {
        padding-right: 0;
    }

    .chat-composer {
        grid-template-columns: 44px 1fr 48px;
        gap: 8px;
        padding: 10px;
        border-radius: 20px;
    }

    .chat-plus-btn,
    .chat-send-btn {
        width: 44px;
        height: 44px;
    }

    .chat-options-panel .task-options {
        grid-template-columns: 1fr;
    }

    .conversation-row {
        grid-template-columns: 48px 1fr auto;
        padding: 14px 12px;
    }

    .conversation-avatar,
    .chat-person-avatar {
        width: 48px;
        height: 48px;
    }
}

/* =========================
   MODERN CHAT BUBBLE STYLE
   ========================= */

.modern-chat-page {
    height: calc(100vh - 96px);
    min-height: 620px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modern-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px 6px 16px;
    scroll-behavior: smooth;
}

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.chat-row.mine {
    justify-content: flex-end;
}

.chat-row.theirs {
    justify-content: flex-start;
}

.chat-row-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.25);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 13px;
    color: #fff;
}

.chat-row-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-bubble {
    max-width: min(72%, 720px);
    padding: 14px 16px 10px;
    border-radius: 24px;
    position: relative;
    box-shadow: 0 8px 24px rgba(0,0,0,.14);
    word-break: break-word;
    border: 1px solid rgba(255,255,255,0.05);
}

.chat-bubble.theirs {
    background: linear-gradient(180deg, rgba(50,54,63,0.96), rgba(39,43,50,0.96));
    color: #f8fafc;
    border-bottom-left-radius: 8px;
}

.chat-bubble.mine {
    background: linear-gradient(135deg, #7c3aed 0%, #9333ea 55%, #a855f7 100%);
    color: #ffffff;
    border-bottom-right-radius: 8px;
}

.chat-bubble-body {
    font-size: 18px;
    line-height: 1.35;
    font-weight: 700;
    white-space: pre-wrap;
}

.chat-bubble-subject {
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.25;
    font-weight: 900;
    opacity: 0.86;
    text-transform: uppercase;
}

.chat-bubble-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.chat-bubble-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 700;
    opacity: 0.9;
}

.chat-read-mark {
    font-weight: 900;
    letter-spacing: -1px;
}

.inline-task-editor {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.14);
}

.inline-task-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr auto;
    gap: 8px;
    align-items: center;
}

.inline-task-grid select,
.inline-task-grid input {
    min-height: 40px;
    border-radius: 12px !important;
}

.chat-task-locked {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 700;
    opacity: 0.92;
}

.modern-composer {
    display: grid;
    grid-template-columns: 46px 1fr 52px;
    gap: 10px;
    align-items: end;
    padding: 10px 12px;
    border-radius: 26px;
    border: 1px solid rgba(148,163,184,0.18);
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 -10px 28px rgba(0,0,0,.18);
}

.modern-composer .chat-textarea {
    width: 100%;
    min-height: 52px;
    max-height: 160px;
    resize: none;
    overflow-y: auto;
    border-radius: 24px !important;
    padding: 14px 18px !important;
    font-size: 17px !important;
    line-height: 1.4;
    background: rgba(30, 41, 59, 0.9);
}

.modern-composer .chat-plus-btn,
.modern-composer .chat-send-btn {
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 0;
    display: inline-grid;
    place-items: center;
    font-size: 24px;
    font-weight: 900;
    cursor: pointer;
}

.modern-composer .chat-plus-btn {
    background: rgba(71, 85, 105, 0.45);
    color: #fff;
    border: 1px solid rgba(148,163,184,0.2);
}

.modern-composer .chat-send-btn {
    background: #0f766e;
    color: #fff;
}

.modern-composer .chat-options-panel {
    display: none;
    margin-bottom: 10px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid rgba(148,163,184,0.16);
    background: rgba(15, 23, 42, 0.96);
}

.modern-composer.options-open .chat-options-panel {
    display: grid;
    gap: 10px;
}

.modern-composer .task-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 768px) {
    .modern-chat-page {
        height: calc(100vh - 84px);
        min-height: calc(100vh - 84px);
    }

    .modern-thread {
        padding: 16px 0 12px;
    }

    .chat-row {
        gap: 8px;
        margin-bottom: 12px;
    }

    .chat-row-avatar {
        width: 30px;
        height: 30px;
        flex-basis: 30px;
    }

    .chat-bubble {
        max-width: 82%;
        padding: 12px 14px 9px;
        border-radius: 22px;
    }

    .chat-bubble-body {
        font-size: 17px;
        line-height: 1.32;
    }

    .inline-task-grid {
        grid-template-columns: 1fr;
    }

    .modern-composer {
        grid-template-columns: 42px 1fr 46px;
        gap: 8px;
        padding: 8px 10px;
        border-radius: 22px;
    }

    .modern-composer .chat-plus-btn,
    .modern-composer .chat-send-btn {
        width: 42px;
        height: 42px;
    }

    .modern-composer .chat-textarea {
        min-height: 48px;
        font-size: 16px !important;
        padding: 13px 16px !important;
    }

    .modern-composer .task-options {
        grid-template-columns: 1fr;
    }
}

/* Compact chat bubbles: width follows message content */
.modern-thread .chat-row {
    width: 100%;
}

.modern-thread .chat-row.mine {
    justify-content: flex-end;
}

.modern-thread .chat-row.theirs {
    justify-content: flex-start;
}

.modern-thread .chat-bubble {
    width: fit-content;
    width: -moz-fit-content;
    min-width: 0;
    max-width: min(62%, 640px);
    padding: 11px 14px 8px;
}

.modern-thread .chat-bubble-body {
    display: block;
    width: fit-content;
    width: -moz-fit-content;
    max-width: 100%;
    font-size: 17px;
    line-height: 1.32;
}

.modern-thread .chat-bubble-meta {
    width: 100%;
    justify-content: flex-end;
}

.modern-thread .chat-bubble-tags {
    width: fit-content;
    max-width: 100%;
}

/* Task editor can be a bit wider, but not too large */
.modern-thread .inline-task-editor {
    min-width: min(360px, 100%);
}

.modern-thread .inline-task-grid {
    grid-template-columns: minmax(110px, 140px) minmax(160px, 220px) auto;
}

/* Very short messages should remain small */
.modern-thread .chat-bubble:not(:has(.inline-task-editor)) {
    min-width: auto;
}

/* Mobile compact bubbles */
@media (max-width: 768px) {
    .modern-thread .chat-bubble {
        max-width: 82%;
        padding: 10px 13px 8px;
    }

    .modern-thread .chat-bubble-body {
        font-size: 16px;
    }

    .modern-thread .inline-task-editor {
        min-width: 0;
        width: 100%;
    }

    .modern-thread .inline-task-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 420px) {
    .modern-thread .chat-bubble {
        max-width: 86%;
    }
}

/* ===== Tight message bubbles - fit text ===== */
.modern-thread .chat-row {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

.modern-thread .chat-row.mine {
    justify-content: flex-end;
}

.modern-thread .chat-row.theirs {
    justify-content: flex-start;
}

.modern-thread .chat-bubble {
    display: inline-flex;
    flex-direction: column;
    width: auto !important;
    min-width: 0 !important;
    max-width: 420px !important;
    padding: 10px 14px 8px !important;
    align-self: flex-start;
}

.modern-thread .chat-row.mine .chat-bubble {
    align-self: flex-end;
}

.modern-thread .chat-bubble-body {
    display: inline !important;
    width: auto !important;
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 17px;
    line-height: 1.32;
}

.modern-thread .chat-bubble-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    width: auto !important;
}

.modern-thread .chat-bubble-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 6px;
    width: auto !important;
    align-self: flex-end;
}

.modern-thread .chat-bubble .inline-task-editor {
    width: 100%;
    margin-top: 10px;
}

/* Short texts stay very small */
.modern-thread .chat-bubble:has(.chat-bubble-body) {
    min-width: unset !important;
}

/* Mobile */
@media (max-width: 768px) {
    .modern-thread .chat-bubble {
        max-width: 80vw !important;
        padding: 9px 12px 8px !important;
    }

    .modern-thread .chat-bubble-body {
        font-size: 16px;
    }
}

/* WhatsApp-style read ticks */
.chat-read-mark {
    font-weight: 900;
    letter-spacing: -2px;
    font-size: 14px;
}

.chat-read-mark.sent {
    color: rgba(226, 232, 240, 0.75);
}

.chat-read-mark.read {
    color: #38bdf8 !important;
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.35);
}

/* Persistent global sound toggle */
.global-sound-toggle {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 999999;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 900;
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 26px rgba(0,0,0,.18);
    opacity: .58;
}

.global-sound-toggle:hover {
    opacity: .96;
}

.global-sound-toggle.is-on {
    background: rgba(15, 118, 110, .42);
}

.global-sound-toggle.is-off {
    background: rgba(37, 99, 235, .34);
}

.global-sound-toggle.needs-tap {
    background: rgba(245, 158, 11, .42);
    animation: soundPulse 1.4s ease-in-out infinite;
}

@keyframes soundPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* Active message count + sound system */
.active-message-sound-btn {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 999999;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 900;
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 26px rgba(0,0,0,.18);
    opacity: .62;
}

.active-message-sound-btn:hover {
    opacity: 1;
}

.active-message-sound-btn.sound-on {
    background: rgba(15, 118, 110, .45);
}

.active-message-sound-btn.sound-off {
    background: rgba(37, 99, 235, .36);
}

.active-message-floating-count {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 999998;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    text-decoration: none;
    place-items: center;
    font-weight: 900;
    box-shadow: 0 14px 30px rgba(220, 38, 38, .35);
    animation: messagePulse 1.1s ease-in-out infinite;
}

.active-message-toast-wrap {
    position: fixed;
    right: 18px;
    bottom: 72px;
    z-index: 999997;
    display: grid;
    gap: 10px;
    max-width: 360px;
}

.active-message-toast {
    border: 0;
    border-radius: 16px;
    padding: 14px 16px;
    color: #fff;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 18px 40px rgba(0,0,0,.25);
    transition: all .25s ease;
}

.active-message-toast.message {
    background: #0f766e;
}

.active-message-toast.deadline {
    background: #991b1b;
}

.active-message-toast strong,
.active-message-toast span {
    display: block;
}

.active-message-toast strong {
    font-size: 14px;
    margin-bottom: 4px;
}

.active-message-toast span {
    font-size: 13px;
    line-height: 1.35;
}

.active-message-toast.hide {
    opacity: 0;
    transform: translateY(8px);
}

.badge-pulse {
    animation: messagePulse 1.1s ease-in-out infinite;
}

/* Stable chat viewport: MOBILE ONLY.
   Desktop keeps the normal app sidebar, topbar and page layout. */
@media (max-width: 767px) {
    html:has(body.chat-page-active),
    body.chat-page-active {
        width: 100%;
        height: 100%;
        overflow: hidden !important;
        overscroll-behavior: none;
        touch-action: none;
    }

    body.chat-page-active {
        position: fixed;
        inset: 0;
    }

    body.chat-page-active .mobile-appbar,
    body.chat-page-active .mobile-drawer-overlay,
    body.chat-page-active .sidebar,
    body.chat-page-active .topbar {
        display: none !important;
    }

    body.chat-page-active .app-shell,
    body.chat-page-active .main,
    body.chat-page-active .page {
        position: fixed;
        inset: 0;
        width: 100%;
        height: var(--chat-viewport-height, 100dvh);
        max-height: var(--chat-viewport-height, 100dvh);
        min-height: 0;
        display: block;
        overflow: hidden;
        padding: 0;
        margin: 0;
    }

    body.chat-page-active .chat-page {
        position: fixed;
        inset: 0;
        z-index: 20;
        width: 100%;
        height: var(--chat-viewport-height, 100dvh);
        max-height: var(--chat-viewport-height, 100dvh);
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        background: var(--bg);
        touch-action: none;
        padding: 8px;
    }

    body.chat-page-active .chat-sidebar {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    body.chat-page-active .chat-person-header,
    body.chat-page-active .chat-header {
        flex: 0 0 auto;
    }

    body.chat-page-active .chat-person-header {
        padding: 8px 0 10px;
    }

    body.chat-page-active .chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
        padding-bottom: 10px;
    }

    body.chat-page-active .chat-composer {
        flex: 0 0 auto;
        position: relative;
        z-index: 20;
        border-radius: 18px;
        padding: 8px 8px max(env(safe-area-inset-bottom), 8px);
        grid-template-columns: 42px minmax(0, 1fr) 46px;
        background: inherit;
        touch-action: auto;
    }

    body.chat-page-active .chat-plus-btn,
    body.chat-page-active .chat-send-btn {
        width: 42px;
        height: 42px;
    }

    body.chat-page-active .chat-composer textarea,
    body.chat-page-active .chat-composer input,
    body.chat-page-active .chat-composer select,
    body.chat-page-active .chat-composer button {
        touch-action: manipulation;
    }
}

@keyframes messagePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.10); }
}

@keyframes soundPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* No reload navigation loading feel */
html.page-loading .main {
    opacity: .72;
    transition: opacity .12s ease;
    pointer-events: none;
}

/* EXCEELO-IOS-CHAT-LOCK-CSS */
@media (max-width: 767px) {
    html:has(body.chat-page-active),
    body.chat-page-active {
        width: 100% !important;
        height: 100% !important;
        min-height: 100% !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }

    body.chat-page-active {
        position: fixed !important;
        inset: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body.chat-page-active .app-shell,
    body.chat-page-active .main,
    body.chat-page-active .page,
    body.chat-page-active .chat-page {
        position: fixed !important;
        top: var(--chat-viewport-top, 0px) !important;
        right: 0 !important;
        bottom: auto !important;
        left: 0 !important;
        width: 100% !important;
        height: var(--chat-viewport-height, 100dvh) !important;
        min-height: 0 !important;
        max-height: var(--chat-viewport-height, 100dvh) !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    body.chat-page-active .page {
        padding: 0 !important;
    }

    body.chat-page-active .chat-page {
        display: flex !important;
        flex-direction: column !important;
        padding: 8px !important;
    }

    body.chat-page-active .chat-person-header,
    body.chat-page-active .chat-header {
        flex: 0 0 auto !important;
    }

    body.chat-page-active .chat-messages {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y !important;
    }

    body.chat-page-active .chat-composer {
        position: relative !important;
        bottom: auto !important;
        flex: 0 0 auto !important;
        z-index: 100 !important;
        margin: 0 !important;
        padding-bottom: max(env(safe-area-inset-bottom), 8px) !important;
        touch-action: manipulation !important;
    }

    body.chat-page-active .chat-composer textarea,
    body.chat-page-active .chat-composer input,
    body.chat-page-active .chat-composer button {
        touch-action: manipulation !important;
    }
}
/* END EXCEELO-IOS-CHAT-LOCK-CSS */

