/*
 * ASSIDU UI quality layer
 * Shared finishing rules for every portal, account flow and dashboard.
 * Feature styles may define layout; this file owns legibility, interaction
 * targets, focus treatment, responsive guardrails and motion preferences.
 */

:root {
    color-scheme: light;
    accent-color: var(--primary-ink);
}

:root[data-theme="dark"],
body.brand-metallic {
    color-scheme: dark;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    letter-spacing: -0.006em;
    text-rendering: optimizeLegibility;
}

[x-cloak] {
    display: none !important;
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

button,
input,
select,
textarea {
    color: inherit;
    letter-spacing: inherit;
}

button,
[role="button"],
summary,
label[for],
input[type="checkbox"],
input[type="radio"] {
    -webkit-tap-highlight-color: transparent;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
[aria-disabled="true"] {
    cursor: not-allowed !important;
    opacity: 0.52;
}

::placeholder {
    color: var(--text-muted);
    opacity: 0.88;
}

/* A visible, consistent keyboard focus ring is non-negotiable across portals. */
:where(
    a,
    button,
    input,
    select,
    textarea,
    summary,
    [tabindex]:not([tabindex="-1"]),
    [contenteditable="true"]
):focus-visible {
    outline-style: solid !important;
    outline-width: 3px !important;
    outline-color: var(--primary-ink) !important;
    outline-color: color-mix(in srgb, var(--primary) 72%, white 28%) !important;
    outline-offset: 3px !important;
    box-shadow: var(--focus-ring) !important;
    transition-duration: 0s !important;
}

main:focus {
    outline: none;
}

.skip-link {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    z-index: 10000;
    min-height: 42px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-elevated);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    font-weight: 700;
    text-decoration: none;
    transform: translate(-50%, -160%);
    transition: transform 160ms ease;
}

.skip-link:focus {
    transform: translate(-50%, 0);
}

/* Type scale */
h1,
h2,
h3,
h4 {
    color: var(--text);
    text-wrap: balance;
}

h1 {
    font-size: clamp(26px, 2vw, 30px);
    line-height: 1.18;
    letter-spacing: -0.025em;
}

h2 {
    font-size: clamp(21px, 1.5vw, 24px);
    line-height: 1.24;
    letter-spacing: -0.018em;
}

h3 {
    font-size: var(--text-lg);
    line-height: 1.35;
    letter-spacing: -0.01em;
}

h4 {
    font-size: var(--text-base);
    line-height: 1.4;
}

.page-title {
    margin-bottom: 6px;
    font-size: clamp(26px, 2vw, 30px);
    line-height: 1.18;
    letter-spacing: -0.025em;
}

.page-sub {
    max-width: 72ch;
    margin-bottom: 28px;
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: 1.55;
}

.section-title {
    margin-bottom: 14px;
    color: var(--text-secondary);
    font-size: var(--text-base);
    line-height: 1.35;
    letter-spacing: -0.005em;
}

.text-sm {
    font-size: var(--text-sm);
}

.text-xs {
    font-size: var(--text-xs);
}

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

p,
li,
dd {
    text-wrap: pretty;
}

.items-start {
    align-items: flex-start;
}

/* Legacy views contain hundreds of inline micro-labels. Keep the true minimum
   at 12px without disturbing intentionally compact diagrams or icon geometry. */
:where(
    [style*="font-size:7px"],
    [style*="font-size:7.5px"],
    [style*="font-size:8px"],
    [style*="font-size:9px"],
    [style*="font-size:10px"],
    [style*="font-size:11px"]
) {
    font-size: var(--text-xs) !important;
}

:where(
    .badge,
    .stat-label,
    .form-error,
    .validation-summary-errors li,
    .filter-tab,
    .ftab,
    .toggle-wrap,
    .widget-badge,
    .widget-list-sub,
    .widget-stat-label,
    .app-grid-label,
    .notif-time,
    .notif-msg,
    .pat-share-label,
    .pat-share-status,
    .chat-file-size,
    .chat-file-name,
    .chat-typing,
    .chat-mention-item-role,
    .tcl-team-sub,
    .pw-card-sub,
    .pw-card-shared-by,
    .tw-card-sub
) {
    font-size: var(--text-xs);
    line-height: 1.45;
}

/* Controls */
.btn {
    min-height: var(--control-height);
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: var(--text-sm);
    line-height: 1.2;
    font-weight: 650;
    letter-spacing: -0.003em;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    color: var(--on-primary);
}

.btn-primary {
    border-color: color-mix(in srgb, var(--primary-ink) 20%, transparent);
}

.btn-success {
    background: var(--success-action);
    color: #fff;
}

.btn-danger {
    background: var(--danger-action);
    color: #fff;
}

.btn-sm {
    min-height: var(--control-height-sm);
    padding: 7px 13px;
    font-size: var(--text-xs);
}

.btn-lg {
    min-height: 48px;
    padding: 12px 24px;
    font-size: var(--text-base);
}

.btn-outline {
    padding: 8px 17px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.btn-sm.btn-outline {
    padding: 6px 12px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label,
label.form-label {
    margin-bottom: 7px;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: 1.35;
    font-weight: 650;
}

.form-input,
.input,
.search-bar,
.app-dialog-input,
select.form-input,
textarea.form-input {
    min-height: 44px;
    padding: 10px 13px;
    border-color: var(--border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    color: var(--text);
    font-size: var(--text-base);
    line-height: 1.4;
}

textarea.form-input {
    min-height: 112px;
    resize: vertical;
}

.form-input:hover,
.input:hover,
.search-bar:hover,
.app-dialog-input:hover {
    border-color: color-mix(in srgb, var(--primary-ink) 52%, var(--border));
}

.form-input:focus,
.input:focus,
.search-bar:focus,
.app-dialog-input:focus {
    border-color: var(--primary-ink);
    box-shadow: var(--focus-ring);
}

.form-error,
.validation-summary-errors li {
    margin-top: 6px;
    color: var(--danger-ink);
    font-size: var(--text-xs);
    line-height: 1.45;
}

.alert {
    padding: 13px 15px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: var(--text-sm);
    line-height: 1.5;
}

.alert-success {
    border-color: color-mix(in srgb, var(--success-ink) 28%, transparent);
    background: color-mix(in srgb, var(--success) 11%, transparent);
    color: var(--success-ink);
}

.alert-warning {
    border-color: color-mix(in srgb, var(--warning-ink) 28%, transparent);
    background: color-mix(in srgb, var(--warning) 11%, transparent);
    color: var(--warning-ink);
}

.alert-danger,
.alert-error {
    border-color: color-mix(in srgb, var(--danger-ink) 28%, transparent);
    background: color-mix(in srgb, var(--danger) 11%, transparent);
    color: var(--danger-ink);
}

.alert-info {
    border-color: color-mix(in srgb, var(--info-ink) 28%, transparent);
    background: color-mix(in srgb, var(--info) 11%, transparent);
    color: var(--info-ink);
}

.spinner-border {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-ink);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

/* Surfaces */
.card {
    border-color: var(--border-light);
    border-radius: 18px;
    padding: 24px;
    background: var(--card);
    box-shadow: var(--shadow-sm), var(--glass-inner-glow);
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-sm), var(--glass-inner-glow);
}

:where(
    a.card,
    button.card,
    .card[role="button"],
    .card[onclick],
    .card.card-interactive
):hover {
    border-color: var(--border);
    box-shadow: var(--shadow), var(--glass-inner-glow);
    transform: translateY(-1px);
}

.stat-card {
    min-height: 112px;
    padding: 20px;
    border-color: var(--border-light);
    border-radius: 16px;
    background: var(--card);
}

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
    gap: 16px;
}

.layout-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
    gap: 24px;
    align-items: start;
}

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

.stat-num {
    font-size: clamp(28px, 2.5vw, 34px);
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.stat-label {
    margin-top: 5px;
    color: var(--text-muted);
}

.badge {
    min-height: 24px;
    padding: 4px 9px;
    border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
    border-radius: 999px;
    font-weight: 650;
}

.badge-ortho {
    color: var(--ortho-ink);
}

.badge-perio {
    color: var(--perio-ink);
}

.empty-state {
    max-width: 680px;
    margin-inline: auto;
    padding: 56px 28px;
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: 1.6;
}

.empty-state-icon {
    margin-bottom: 16px;
    opacity: 0.58;
}

/* Navigation and page shell */
.sidebar {
    padding: 22px 0 max(18px, env(safe-area-inset-bottom));
    background: var(--glass-bg);
    border-right-color: var(--border-light);
}

.sidebar-logo {
    min-height: 48px;
    padding: 0 22px 22px;
    font-size: var(--text-lg);
}

.nav-section {
    padding: 16px 20px 6px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.25;
    letter-spacing: 0.1em;
}

.nav-item {
    min-height: 42px;
    gap: 11px;
    margin: 2px 10px;
    padding: 9px 13px;
    border-radius: 11px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.3;
    font-weight: 520;
}

.nav-item.active {
    color: var(--primary-ink);
    font-weight: 650;
}

.nav-icon {
    width: 24px;
    font-size: 17px;
}

.nav-sep {
    margin: 12px 18px;
}

.main-content {
    min-width: 0;
    padding: 32px clamp(24px, 3vw, 48px) 48px;
}

.portal-utility-bar {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin: -12px -16px 12px;
}

.sidebar-toggle {
    width: 44px;
    height: 44px;
    padding: 0;
    align-items: center;
    justify-content: center;
    font-size: 0;
}

.sidebar-toggle::before {
    content: "\2630";
    font-size: 20px;
    line-height: 1;
}

.tabs {
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    min-height: 44px;
    padding: 11px 15px;
    border: 0;
    border-bottom: 2.5px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.35;
}

.filter-tab,
.ftab {
    min-height: 36px;
    padding: 8px 13px;
    border-radius: 10px;
}

.toggle-switch {
    width: 44px;
    height: 26px;
    border-radius: 999px;
}

.toggle-switch::after {
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
}

.toggle-switch.on::after {
    left: 20px;
}

/* Home shell and dashboard widgets */
.topbar {
    min-height: var(--topbar-height);
    padding: 10px clamp(18px, 3vw, 36px);
    border-bottom-color: var(--border-light);
}

.topbar-logo {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    border-radius: 10px;
}

.topbar-logo img {
    height: 26px;
}

.topbar-right {
    gap: 10px;
}

.theme-toggle-btn,
.app-grid-btn,
.topbar-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.topbar-avatar {
    color: var(--on-primary);
    font-size: var(--text-sm);
}

.topbar-account {
    position: relative;
    display: inline-flex;
}

.account-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1000;
    width: 224px;
    overflow: hidden;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-elevated);
    box-shadow: var(--shadow-lg);
}

.account-menu-item {
    display: flex;
    width: 100%;
    min-height: 42px;
    align-items: center;
    gap: 9px;
    padding: 9px 11px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--text);
    font-size: var(--text-sm);
    line-height: 1.3;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.account-menu-item:hover {
    background: var(--card-hover);
    color: var(--text);
    text-decoration: none;
}

.account-menu-item-accent {
    color: var(--primary-ink);
}

.account-menu-item-danger {
    color: var(--danger-ink);
}

.account-menu-separator {
    height: 1px;
    margin: 6px 10px;
    background: var(--border-light);
}

.account-menu-form {
    margin: 0;
}

.home-content {
    width: min(100%, var(--content-max));
    min-height: calc(100vh - var(--topbar-height));
    margin-inline: auto;
    padding: 32px clamp(20px, 3vw, 48px) 48px;
}

.grid-stack-item-content {
    border-color: var(--glass-border);
    border-radius: 20px;
    background: var(--card);
    box-shadow: var(--shadow), var(--glass-inner-glow);
}

.grid-stack-item-content::before {
    border-radius: 20px;
    opacity: 0.52;
}

.widget-header {
    min-height: 48px;
    padding: 15px 18px 10px;
}

.widget-title {
    font-size: 14px;
    line-height: 1.35;
}

.widget-body {
    padding: 2px 18px 16px;
    font-size: var(--text-sm);
    line-height: 1.5;
}

.widget-list-item {
    min-height: 44px;
    padding: 9px 0;
    font-size: var(--text-sm);
}

.widget-icon-card {
    gap: 10px;
    padding: 18px;
}

.widget-icon-card .wic-icon {
    width: 58px;
    height: 58px;
    border-radius: 17px;
}

.widget-icon-card .wic-label {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.customize-btn {
    min-height: 42px;
    padding: 9px 20px;
    font-size: var(--text-sm);
}

.app-grid-dropdown {
    width: min(360px, calc(100vw - 24px));
    padding: 18px;
    border-color: var(--border);
    background: var(--surface-elevated);
}

.app-grid {
    position: relative;
    display: inline-flex;
}

.app-grid-title {
    font-size: var(--text-base);
}

.app-grid-items {
    gap: 10px;
}

.app-grid-item {
    min-height: 82px;
    gap: 7px;
    padding: 10px 5px;
}

.app-grid-label {
    color: var(--text-secondary);
    font-weight: 650;
}

/* Tables remain dense enough for clinical data, never cramped. */
.table,
table,
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
}

.table th,
.data-table th {
    padding: 12px 14px;
    color: var(--text-muted);
    font-size: var(--text-xs);
    line-height: 1.35;
    letter-spacing: 0.045em;
}

.table td,
.data-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border-light);
    line-height: 1.45;
}

.table tbody tr,
.data-table tbody tr {
    transition: background-color 140ms ease;
}

.data-table tbody tr:hover {
    background: var(--card-hover);
}

/* Overlays, menus and notifications */
.modal-overlay,
.wallet-modal-overlay,
.app-dialog-overlay,
#quicklook-modal {
    overscroll-behavior: contain;
}

body.modal-open,
body.sidebar-open {
    overflow: hidden;
}

.ql-window-close {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #ff5f57;
    box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.24);
    cursor: pointer;
}

#ql-edit,
#ql-info-toggle {
    min-width: 34px !important;
    width: 34px !important;
    min-height: 34px !important;
    height: 34px !important;
}

.modal-panel,
.modal-overlay > .modal,
.wallet-modal,
.app-dialog {
    border-color: var(--border);
    background: var(--surface-elevated);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    min-height: 68px;
    padding: 20px 24px 14px;
}

.modal-body {
    padding: 12px 24px 20px;
}

.modal-footer {
    padding: 16px 24px 20px;
}

.modal-close,
.wallet-modal-close {
    width: 40px;
    height: 40px;
}

.notif-item {
    min-height: 64px;
    padding: 12px 14px;
}

.notification-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.notification-bell-btn {
    position: relative;
    display: inline-flex;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.notification-bell-btn:hover,
.notification-bell-btn[aria-expanded="true"] {
    border-color: var(--border-light);
    background: var(--card-alt);
    color: var(--text);
}

.notif-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    display: flex;
    min-width: 18px;
    height: 18px;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--bg-alt);
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    line-height: 1;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.notification-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1000;
    width: min(400px, calc(100vw - 24px));
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface-elevated);
    box-shadow: var(--shadow-lg);
}

.notification-panel-header {
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px 10px;
}

.notification-panel-title {
    color: var(--text);
    font-size: var(--text-lg);
    font-weight: 700;
}

.notification-mark-all {
    min-height: 34px;
    padding: 6px 10px;
    border: 0;
    border-radius: 9px;
    background: none;
    color: var(--primary-ink);
    font-size: var(--text-xs);
    font-weight: 650;
    cursor: pointer;
}

.notification-mark-all:hover {
    background: var(--primary-light);
}

.notification-panel-divider {
    height: 1px;
    margin: 0 18px;
    background: var(--border-light);
}

.notification-list {
    max-height: min(420px, 60dvh);
    overflow-y: auto;
    padding: 8px 0;
    overscroll-behavior: contain;
}

.notification-empty {
    padding: 42px 20px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-align: center;
}

.notification-empty-icon {
    margin-bottom: 10px;
    font-size: 30px;
    opacity: 0.5;
}

.notification-panel-footer {
    padding: 12px 18px 14px;
    text-align: center;
}

.notification-view-all {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    padding: 6px 10px;
    border-radius: 9px;
    color: var(--primary-ink);
    font-size: var(--text-sm);
    font-weight: 650;
    text-decoration: none;
}

.notification-view-all:hover {
    background: var(--primary-light);
    text-decoration: none;
}

.notif-title {
    font-size: var(--text-sm);
}

.notif-msg {
    color: var(--text-muted);
}

.loading-text {
    font-size: var(--text-sm);
}

/* Persistent utilities occupy separate corners instead of colliding. */
#tcl-fab {
    right: 84px;
    left: auto;
}

#tcl-panel {
    right: 24px;
    left: auto;
    transform-origin: bottom right;
}

.assidu-upload-tray {
    left: 16px;
    max-width: calc(100vw - 32px);
}

.cb-session-row {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 4px;
    margin: 2px 0;
    padding: 3px;
    border-radius: 10px;
    color: var(--text);
}

.cb-session-row:hover {
    background: var(--card-hover);
}

.cb-session-select {
    display: flex;
    min-width: 0;
    min-height: 38px;
    flex: 1;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: var(--text-xs);
    text-align: left;
    cursor: pointer;
}

.cb-session-select i {
    flex-shrink: 0;
    color: var(--primary-ink);
}

.cb-session-select span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cb-session-delete {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.cb-session-delete:hover {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: var(--danger-ink);
}

.cb-user-bubble,
.command-bar-send {
    color: var(--on-primary);
}

.command-bar-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
}

.aut-panel {
    width: min(420px, calc(100vw - 32px));
}

/* Reveal hover affordances when their container has keyboard focus, and keep
   them visible on touch hardware where hover never exists. */
.chat-msg:focus-within .chat-msg-delete,
.rd-block:focus-within .rd-block-controls,
.rd-float:focus-within .rd-float-controls,
.rd-float:focus-within .rd-float-resize {
    display: flex;
    opacity: 1;
}

/* Responsive guardrails */
@media (max-width: 1024px) {
    .main-content {
        padding-inline: 24px;
    }

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

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

@media (max-width: 768px) {
    .sidebar {
        width: min(86vw, 320px);
    }

    .main-content {
        padding: calc(68px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
    }

    .sidebar-toggle {
        top: calc(12px + env(safe-area-inset-top));
        left: 12px;
        display: flex;
    }

    .home-content {
        padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
    }

    .topbar {
        min-height: 60px;
        padding: 8px 12px;
    }

    .topbar-right {
        gap: 6px;
    }

    .topbar-logo img {
        height: 23px;
    }

    .app-grid-dropdown {
        position: fixed;
        top: calc(64px + env(safe-area-inset-top));
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(100dvh - 88px - env(safe-area-inset-top));
        overflow-y: auto;
    }

    .notification-panel {
        position: fixed;
        top: calc(64px + env(safe-area-inset-top));
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(100dvh - 88px - env(safe-area-inset-top));
    }

    .app-grid-items {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .page-sub {
        margin-bottom: 22px;
    }

    .card {
        padding: 20px;
        border-radius: 16px;
    }

    .grid-2,
    .grid-3,
    .grid-4,
    .form-grid,
    .layout-split {
        grid-template-columns: minmax(0, 1fr);
    }

    .modal-overlay {
        align-items: flex-end;
        padding-top: max(24px, env(safe-area-inset-top));
    }

    .modal-panel,
    .modal-overlay > .modal,
    .wallet-modal {
        width: 100%;
        max-height: min(92dvh, 920px);
        border-radius: 22px 22px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

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

    .fm-modal {
        width: calc(100vw - 24px);
        min-width: 0;
        height: min(88dvh, 900px);
        min-height: 0;
        resize: none;
    }

    .collab-container {
        height: auto;
        min-height: calc(100dvh - 150px);
        flex-direction: column;
        overflow: visible;
    }

    .collab-right {
        width: 100%;
        min-width: 0;
        max-width: none;
        min-height: 420px;
        border-top: 1px solid var(--border);
        border-left: 0;
    }

    #tcl-fab {
        right: 72px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        left: auto;
    }
}

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

    .topbar-logo {
        max-width: 116px;
    }

    .topbar-logo img {
        max-width: 100%;
        object-fit: contain;
    }

    .theme-toggle-btn,
    .app-grid-btn,
    .topbar-avatar {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .app-grid-items {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stat-row {
        gap: 12px;
    }

    .btn:not(.btn-block) {
        max-width: 100%;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-inline: 18px;
    }
}

@media (hover: none), (pointer: coarse) {
    .btn,
    .btn-sm,
    .nav-item,
    .tab,
    .filter-tab,
    .ftab,
    .customize-btn,
    .back-link {
        min-height: 44px;
    }

    .theme-toggle-btn,
    .app-grid-btn,
    .topbar-avatar,
    .modal-close,
    .wallet-modal-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }

    .chat-msg-delete {
        opacity: 0.72;
    }

    .rd-block-controls,
    .rd-float-controls,
    .rd-float-resize {
        display: flex;
    }
}

/* Respect operating-system comfort settings. */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-reduced-transparency: reduce) {
    :where(
        .sidebar,
        .topbar,
        .card,
        .grid-stack-item-content,
        .app-grid-dropdown,
        .modal-panel,
        .modal-overlay > .modal,
        .wallet-modal,
        .app-dialog
    ) {
        background: var(--bg-alt) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
}

@media (forced-colors: active) {
    .btn,
    .card,
    .nav-item,
    .form-input,
    .search-bar,
    .badge {
        border: 1px solid CanvasText;
    }

    :focus-visible {
        outline: 3px solid Highlight !important;
    }
}

@media print {
    .sidebar,
    .sidebar-toggle,
    .sidebar-overlay,
    .topbar,
    .loading-overlay,
    .command-bar,
    #tcl-fab,
    #tcl-panel {
        display: none !important;
    }

    .main-content,
    .home-content {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
    }

    body {
        background: #fff;
        color: #000;
    }

    .card {
        break-inside: avoid;
        border: 1px solid #bbb;
        box-shadow: none;
    }
}
