/* ===========================================
   Client Portal Styles
   Dark theme sidebar layout + preserved shared classes
   =========================================== */

/* Self-hosted Montserrat (variable font, weights 400-900). Portal and
   admin-auth layouts do not load critical.css, so the @font-face rules
   must also live here. Kept in sync with src/css/critical.css. */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/fonts/montserrat-v31-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/fonts/montserrat-v31-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --portal-topbar-height: calc(32px + env(safe-area-inset-top, 0px));
  --portal-header-offset: 64px;
  --portal-bottom-nav-offset: 64px;
}

body {
  background-color: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.portal-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg, #0a0a0a);
  color: var(--text, #e5e5e5);
  font-family: 'Montserrat', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Ambient Background Glow */
.bg-ambient {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: radial-gradient(circle at 10% 10%, rgba(96, 165, 250, 0.1), transparent 40%);
  background-attachment: fixed;
  pointer-events: none;
  z-index: -1;
  opacity: var(--blob-opacity);
  transition: opacity 0.3s ease;
}

/* Global portal layout */
#app-container { padding-bottom: calc(var(--portal-bottom-nav-offset) + env(safe-area-inset-bottom, 0px)); }
.bottom-nav .nav-item {
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 768px) {
  body { display: flex; }
  .bottom-nav {
    top: var(--portal-topbar-height); left: 0; bottom: 0; width: 80px;
    flex-direction: column; justify-content: flex-start;
    padding-top: 1.5rem; border-top: none; border-right: 1px solid var(--border);
  }
  .bottom-nav .nav-item {
    padding-bottom: 1.25rem;
  }
  .top-social-bar { left: 0; width: 100%; z-index: 65; }
  #app-container { padding-bottom: 0; padding-left: 80px; width: 100%; }
  .top-header { left: 80px; width: calc(100% - 80px); }
}

.portal-main {
  min-height: 100vh;
  padding-top: var(--portal-topbar-height);
  width: 100%;
}

.portal-login-logo-light {
  display: none;
}

html.light-mode .portal-login-logo-dark {
  display: none;
}

html.light-mode .portal-login-logo-light {
  display: block;
}

/* --- Top Bar --- */
.portal-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: calc(32px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 1rem 0;
  background: var(--panel, #111);
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  transition: transform 0.25s ease;
  will-change: transform;
}

.portal-topbar.is-hidden {
  transform: translateY(0);
}
.portal-topbar-text {
  color: var(--muted, #888);
  font-weight: 700;
}
.portal-topbar-link {
  display: inline-flex;
  align-items: center;
  color: var(--muted, #888);
  transition: color 0.2s;
}
.portal-topbar-link:hover {
  color: var(--text, #fff);
}

/* Topbar light-mode handled by CSS variables (--panel, --border, --muted, --text) */

/* ===========================================
   SHARED CLASSES — used by both portal & sign
   DO NOT MODIFY OR REMOVE
   =========================================== */

/* Badges → system/components.css */
/* Empty state → system/components.css */

/* --- Portal component aliases (used by portal renderers) --- */
.form-group { margin: 0; }
.doc-btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 0.5rem; border: 1px solid transparent; cursor: pointer; }
.doc-subtab { display: block; }
.portal-filter-status { accent-color: #60a5fa; }
.portal-modal-invoice { width: min(100%, 720px); }
.portal-pref-toggle { display: inline-flex; align-items: center; gap: 0.5rem; }
.notif-dot { box-shadow: 0 0 0 1px var(--panel); }

/* Toast → system/components.css */

/* Spinner → system/components.css */

/* Hidden → system/reset.css */

/* --- Modal Content Scrollers (still used) --- */
.portal-contract-preview-scroll {
  max-height: 60vh;
  overflow-y: auto;
  padding: 1rem;
  background: #fff;
  color: #111;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.7;
}

.portal-contract-preview-scroll h1,
.portal-contract-preview-scroll h2,
.portal-contract-preview-scroll h3 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
  color: #111;
}

.portal-contract-preview-scroll p {
  margin: 0 0 0.75rem;
}

.portal-invoice-preview-scroll {
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  background: #fff;
  color: #111;
  border-radius: 6px;
  font-size: 0.9rem;
}

.portal-invoice-preview-scroll *,
.portal-invoice-preview-scroll table,
.portal-invoice-preview-scroll img {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.portal-invoice-preview-scroll table {
  width: 100% !important;
  max-width: 100% !important;
  table-layout: fixed !important;
}

.portal-invoice-preview-scroll img {
  max-width: 100% !important;
  height: auto !important;
}

.portal-invoice-preview-scroll td,
.portal-invoice-preview-scroll th,
.portal-invoice-preview-scroll p,
.portal-invoice-preview-scroll span,
.portal-invoice-preview-scroll a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.portal-media-player {
  width: 100%;
  max-height: 70vh;
  border-radius: 10px;
  background: #000;
}

/* Modal close → system/components.css */

.portal-photo-lightbox {
  width: min(100%, 980px);
}

.portal-photo-lightbox-body {
  padding: 0;
}

.portal-photo-lightbox-stage {
  position: relative;
  height: min(70vh, 70dvh);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  touch-action: none;
  cursor: grab;
}

.portal-photo-lightbox-stage.is-dragging {
  cursor: grabbing;
}

.portal-photo-lightbox-img {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.portal-photo-lightbox-footer {
  justify-content: center;
}

.portal-photo-lightbox-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.portal-photographer-menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background-color 0.18s ease;
}

.portal-photographer-menu-item:hover {
  background: var(--input-bg, rgba(0, 0, 0, 0.05));
}

.portal-photographer-menu-item-icon {
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background: rgba(96, 165, 250, 0.12);
  color: #60a5fa;
  flex-shrink: 0;
}

#portal-photographer-card {
  cursor: pointer;
}

.portal-review-fab {
  position: fixed;
  right: 1rem;
  bottom: calc(5rem + env(safe-area-inset-bottom, 16px));
  z-index: 450;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: #ffffff;
  color: #000000;
  box-shadow: 0 24px 38px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.portal-review-fab-icon {
  width: 1.5rem;
  height: 1.5rem;
  display: block;
}

.portal-review-fab:hover {
  transform: scale(1.05);
}

.portal-review-fab:active {
  transform: scale(0.95);
}

.portal-review-fab-tooltip {
  position: absolute;
  right: 100%;
  margin-right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  padding: 0.375rem 0.75rem;
  background: var(--panel);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 0.5rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  border: 1px solid var(--border);
  display: none;
}

html.dark .portal-review-fab,
html:not(.light-mode) .portal-review-fab {
  background: #ffffff !important;
  color: #000000 !important;
}

html.light-mode .portal-review-fab {
  background: #000000;
  color: #ffffff;
}

@media (min-width: 640px) {
  #drawer-property-details > .tc-panel {
    width: min(calc(100% - 2rem), 500px);
  }

  #portal-invoice-modal > .tc-panel,
  #portal-contract-modal > .tc-panel,
  #portal-media-modal > .tc-panel {
    width: min(calc(100% - 2rem), 720px);
  }

  #portal-photo-lightbox-modal > .portal-photo-lightbox {
    width: min(calc(100% - 2rem), 980px);
  }
}

@media (min-width: 768px) {
  .portal-review-fab-tooltip {
    display: block;
  }

  .portal-review-fab:hover .portal-review-fab-tooltip {
    opacity: 1;
  }

  .portal-review-fab {
    bottom: 2rem;
    right: 2rem;
  }
}


/* Float field → system/components.css */

.portal-password-field input {
  padding-right: 4.25rem;
}

.portal-password-toggle {
  position: absolute;
  right: 0;
  top: 12px;
  border: none;
  background: transparent;
  color: var(--muted, #93a2bc);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.25rem 0.1rem;
}

.portal-password-toggle:hover {
  color: var(--tc-accent-blue-light, #bfdbfe);
}

/* --- Notification Dropdown Push Toggle (visual styles via tc-btn + Tailwind) --- */
.portal-notif-dropdown-panel {
  height: min(420px, calc(100svh - 5rem));
  max-height: calc(100svh - 5rem);
}

.portal-notif-dropdown-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.portal-notif-dropdown-push-toggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Notification Dropdown Items */
.portal-notif-dropdown-item {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  flex-shrink: 0;
}
.portal-notif-dropdown-item-inner {
  position: relative;
  z-index: 1;
  transition: transform 0.2s ease, background 0.15s;
  background: var(--panel, #111);
}
.portal-notif-dropdown-item.unread .portal-notif-dropdown-item-inner {
  background: rgba(96, 165, 250, 0.04);
}
.portal-notif-dropdown-item:focus-visible {
  outline: none;
}
.portal-notif-dropdown-item:focus-visible .portal-notif-dropdown-item-inner {
  outline: 2px solid rgba(96, 165, 250, 0.5);
  outline-offset: -2px;
}
.portal-notif-dropdown-item-body {
  min-width: 0;
}
.portal-notif-dropdown-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.portal-notif-dropdown-item-msg {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.portal-notif-dropdown-item-delete {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--tc-text-muted);
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.portal-notif-dropdown-item:hover .portal-notif-dropdown-item-delete {
  opacity: 1;
}
.portal-notif-dropdown-item-delete:hover {
  color: var(--tc-accent-red);
}
.portal-notif-dropdown-item-action {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  background: var(--tc-accent-red);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.portal-notif-dropdown-item.swiping .portal-notif-dropdown-item-action,
.portal-notif-dropdown-item.swipe-open .portal-notif-dropdown-item-action,
.portal-notif-dropdown-item.swipe-out .portal-notif-dropdown-item-action {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.portal-notif-dropdown-item.swiping .portal-notif-dropdown-item-inner {
  transition: none;
}
.portal-notif-dropdown-item.swipe-out .portal-notif-dropdown-item-inner {
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.portal-notif-dropdown-item.swipe-out {
  max-height: 220px;
  overflow: hidden;
  transition: max-height 0.2s ease 0.15s, border-width 0.2s ease 0.15s;
}
.portal-notif-dropdown-item.swipe-out.collapse {
  max-height: 0;
  border-top-width: 0;
  border-bottom-width: 0;
}

/* ===========================================
   DEAD OLD LAYOUT REMOVED — sidebar, overview, properties,
   documents, photos, guides, account tabs, responsive
   (all migrated to Tailwind in portal index.html + portal.js)
   =========================================== */

/* Sidebar avatar (still set by JS for legacy hooks) */
.portal-sidebar-avatar img, .portal-sidebar-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.portal-sidebar-avatar-overlay {
  position: absolute; inset: 0; border-radius: 50%; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; opacity: 0;
  transition: opacity 0.2s; cursor: pointer; color: #fff; font-size: 0.65rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
}
.portal-sidebar-avatar:hover .portal-sidebar-avatar-overlay { opacity: 1; }

/* --- (dead old layout sections removed: sidebar, overview, properties,
       documents, photos, guides, account, responsive) --- */

/* Sign-* responsive rules */
@media (max-width: 480px) {
  .sign-otp-input {
    width: 42px;
    height: 50px;
    font-size: 1.2rem;
  }
  .sign-type-preview {
    font-size: 1.4rem;
  }
}

/* --- Sign Layout --- */
.sign-shell {
  min-height: calc(100vh - var(--portal-topbar-height));
  background: var(--surface-page);
}

.sign-header {
  background: var(--surface-card);
  padding: 1rem 1.25rem;
  text-align: center;
}

.sign-header-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.sign-header-logo-img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sign-header-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-heading);
  margin: 0;
}

.sign-header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0;
}

.sign-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* --- Sign Steps --- */
.sign-step {
  display: none;
}

.sign-step.active {
  display: block;
}

.sign-step-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
}

.sign-step-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-heading);
}

.sign-step-desc {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- OTP Input --- */
.sign-otp-group {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.sign-otp-input {
  width: 48px;
  height: 56px;
  text-align: center;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-heading);
  background: var(--surface-input);
  border: 2px solid var(--border-input);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s;
}

.sign-otp-input:focus {
  border-color: var(--accent);
  background: var(--surface-card);
}

.sign-otp-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.sign-otp-resend {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sign-otp-resend:hover { color: var(--text-heading); }
.sign-otp-resend:disabled { color: var(--text-muted); cursor: not-allowed; text-decoration: none; }

.sign-otp-timer {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sign-otp-attempts {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--status-danger);
}

/* --- Contract Review --- */
.sign-contract-scroll {
  max-height: 50vh;
  overflow-y: auto;
  padding: 1rem;
  margin-bottom: 1.25rem;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.7;
  color: #111;
}

.sign-contract-scroll h1,
.sign-contract-scroll h2,
.sign-contract-scroll h3 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
  color: #111 !important;
}

.sign-contract-scroll p {
  margin: 0 0 0.75rem;
}

.sign-contract-scroll p,
.sign-contract-scroll li,
.sign-contract-scroll td,
.sign-contract-scroll th,
.sign-contract-scroll span,
.sign-contract-scroll div {
  color: #1f2937 !important;
}

.sign-contract-scroll strong {
  color: #111 !important;
}

.sign-proceed-btn {
  width: 100%;
  padding: 0.75rem;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.sign-proceed-btn:hover { background: var(--accent-hover); }
.sign-proceed-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Signature Tabs --- */
.sign-tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border-subtle);
}

.sign-tab-btn {
  flex: 1;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.sign-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sign-tab-content {
  display: none;
}

.sign-tab-content.active {
  display: block;
}

/* --- Canvas (Draw) --- */
.sign-canvas-wrapper {
  position: relative;
  margin-bottom: 0.75rem;
}

.sign-canvas {
  width: 100%;
  height: 160px;
  border: 2px solid var(--border-input);
  border-radius: 8px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.sign-canvas-clear {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-input);
  border: 1px solid var(--border-input);
  border-radius: 4px;
  cursor: pointer;
}

.sign-canvas-clear:hover { background: var(--surface-card-hover); }

/* --- Type Signature --- */
.sign-type-input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.3rem;
  font-style: italic;
  color: var(--text-heading);
  background: var(--surface-input);
  border: 2px solid var(--border-input);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 0.75rem;
}

.sign-type-input:focus { border-color: var(--accent); }

.sign-type-preview {
  padding: 1rem;
  text-align: center;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.8rem;
  font-style: italic;
  color: var(--text-heading);
  border-bottom: 2px solid var(--text-muted);
  margin-bottom: 1rem;
  min-height: 48px;
}

/* --- Consent --- */
.sign-consent {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 1rem 0;
  padding: 0.75rem;
  background: var(--surface-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

.sign-consent input[type="checkbox"] {
  margin-top: 0.15rem;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.sign-consent-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- Signer Name Confirm --- */
.sign-name-field {
  margin-bottom: 1rem;
}

.sign-name-field label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.sign-name-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-heading);
  background: var(--surface-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}

.sign-name-input:focus { border-color: var(--accent); }

/* --- Submit Signature --- */
.sign-submit-btn {
  width: 100%;
  padding: 0.85rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.sign-submit-btn:hover { background: var(--accent-hover); }
.sign-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Done Step --- */
.sign-done {
  text-align: center;
  padding: 2rem 1rem;
}

.sign-done-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: var(--status-success);
}

.sign-done h2 {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-heading);
}

.sign-done p {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.sign-done-link {
  display: inline-block;
  margin-top: 1.25rem;
  padding: 0.55rem 1.25rem;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.2s;
}

.sign-done-link:hover { background: var(--accent-hover); }

/* --- Error Step --- */
.sign-error {
  text-align: center;
  padding: 2rem 1rem;
}

.sign-error-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: var(--status-danger);
}

.sign-error h2 {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-heading);
}

.sign-error p {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.sign-error-contact {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sign-error-contact a {
  color: var(--accent);
  font-weight: 600;
}

/* --- Push Notifications --- */

.portal-push-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted, #888);
  margin-bottom: 0.75rem;
}

.portal-push-status.portal-push-on {
  color: #22c55e;
}

.portal-push-toggle-btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.85rem;
}

.portal-push-toggle-btn.portal-push-enable {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #f0fdf4;
  border: 1px solid rgba(34,197,94,0.4);
  box-shadow: 0 10px 22px rgba(34, 197, 94, 0.26);
}

.portal-push-toggle-btn.portal-push-enable:hover {
  filter: brightness(1.05);
}

.portal-push-denied {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted, #888);
  margin: 0;
}

/* Install banner — visual styles in Tailwind; CSS handles animation only */
.portal-install-banner {
  animation: install-banner-in 0.3s ease;
}

.portal-install-banner.hiding {
  animation: install-banner-out 0.25s ease forwards;
}

.portal-install-steps {
  margin-top: var(--tc-space-sm);
  padding: var(--tc-space-sm) var(--tc-space-md);
  border: 1px solid var(--border, var(--tc-border-medium));
  border-radius: 8px;
  background: var(--input-bg, rgba(255, 255, 255, 0.03));
}

.portal-install-steps-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.portal-install-step-list {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
}

.portal-install-step-list li {
  margin: 0.2rem 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Tour banner — visual styles in Tailwind; CSS handles animation only */
.portal-tour-banner {
  animation: tour-banner-in 0.3s ease;
}

.portal-tour-banner.hiding {
  animation: tour-banner-out 0.25s ease forwards;
}

@keyframes tour-banner-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tour-banner-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

@keyframes install-banner-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes install-banner-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

.portal-tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: auto;
}

.portal-tour-spotlight {
  position: fixed;
  z-index: 1000;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  transition: all 0.25s ease;
  pointer-events: none;
}

.portal-tour-tooltip {
  position: fixed;
  z-index: 1001;
  max-width: 280px;
  padding: 0.75rem 1rem;
  background: var(--panel, #111);
  color: var(--text, #e2e8f0);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
}

.portal-tour-tooltip::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: rgba(15, 23, 42, 0.88);
}

.portal-tour-step-count {
  font-size: 0.7rem;
  color: var(--tc-text-muted);
  margin: 0 0 0.25rem;
}

.portal-tour-step-text {
  margin: 0;
}

.portal-tour-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.portal-tour-skip {
  font-size: 0.75rem;
  color: var(--tc-text-muted);
  background: none;
  border: none;
  cursor: pointer;
}

.portal-tour-next {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--tc-accent-blue);
  background: none;
  border: none;
  cursor: pointer;
}

/* Banner responsive layout handled by Tailwind classes */

@media (prefers-reduced-motion: reduce) {
  .portal-install-banner,
  .portal-install-banner.hiding,
  .portal-tour-banner,
  .portal-tour-banner.hiding {
    animation: none;
  }

  .portal-tour-spotlight {
    transition: none;
  }
}

/* Push Preferences */
/* Bell push-subscription states (ID selector — bell uses Tailwind base styles) */
#portal-notif-bell.is-subscribed {
  border-color: var(--tc-accent-green) !important;
  color: var(--tc-accent-green) !important;
}
#portal-notif-bell.is-subscribed:hover {
  border-color: var(--tc-accent-green-dark) !important;
}
#portal-notif-bell.is-denied {
  opacity: 0.4;
  cursor: not-allowed;
}

.portal-push-prefs {
  margin-top: 1rem;
  border-top: 1px solid var(--border, var(--tc-border-medium));
  padding-top: 0.75rem;
}

.portal-push-prefs-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text, var(--tc-text-primary));
  margin: 0 0 0.75rem;
}

.portal-push-prefs-loading {
  font-size: 0.85rem;
  color: var(--muted);
}

.portal-push-pref-group {
  margin-bottom: 0.75rem;
}

.portal-push-pref-group-heading {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.35rem;
}

.portal-push-pref-toggle-label {
  display: flex;
  align-items: center;
  padding: 0.4rem 0;
  font-size: 0.85rem;
  color: var(--text, var(--tc-text-primary));
}

.portal-push-pref-name {
  flex: 1;
}

.portal-pref-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 0.35rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.55);
  color: var(--muted, #64748b);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
}

.portal-pref-help::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg, #1e293b);
  color: #f1f5f9;
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.4;
  padding: 0.4rem 0.6rem;
  border-radius: 0.4rem;
  white-space: nowrap;
  max-width: 220px;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 90;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.portal-pref-help:hover::after,
.portal-pref-help:focus::after {
  opacity: 1;
}

:root[data-theme="light"] .portal-pref-help::after,
.portal-light .portal-pref-help::after {
  background: #1e293b;
  color: #f1f5f9;
}

.portal-push-pref-toggles {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.portal-push-pref-channel {
  font-size: 0.7rem;
  color: var(--muted);
  margin-right: 0.2rem;
}

.portal-push-pref-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.portal-push-pref-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.portal-push-pref-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border, #ccc);
  border-radius: 10px;
  transition: background 0.2s;
  cursor: pointer;
}

.portal-push-pref-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--panel, #fff);
  border-radius: 50%;
  transition: transform 0.2s;
}

.portal-push-pref-switch input:checked + .portal-push-pref-slider {
  background: #10b981;
}

.portal-push-pref-switch input:checked + .portal-push-pref-slider::before {
  transform: translateX(16px);
}

/* --- Offline Banner --- */

.offline-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 8px 16px;
  background: var(--panel, #111);
  border: 1px solid #f59e0b;
  color: var(--text, #fff);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  z-index: 9999;
  position: sticky;
  top: 0;
}

.offline-banner svg {
  flex-shrink: 0;
}

/* ===========================================
   LIGHT MODE OVERRIDES (active classes only)
   =========================================== */

/* Float-field focus color override for light mode */
html.light-mode #portal-dashboard-view .float-field input:focus,
html.light-mode #portal-dashboard-view .float-field textarea:focus,
html.light-mode #portal-dashboard-view .float-field select:focus {
  border-bottom-color: #3b82f6;
}

/* Banner light-mode handled by CSS variables (--panel-alert-bg, --panel-alert-border, --text, --muted) */

/* Push pref light-mode handled by CSS variables (--border, --text, --muted) */

@media (prefers-reduced-motion: reduce) {
  html.light-mode #portal-dashboard-view *,
  html.light-mode #portal-dashboard-view *::before,
  html.light-mode #portal-dashboard-view *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ===========================================
   PHASE 5: THEME VIEW TRANSITIONS
   =========================================== */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.3s;
  animation-timing-function: ease-in-out;
}

::view-transition-old(root) {
  animation: none;
  z-index: 1;
}

::view-transition-new(root) {
  animation: portal-theme-reveal 0.3s ease-in-out both;
  z-index: 2;
}

@keyframes portal-theme-reveal {
  from {
    clip-path: var(--transition-clip-from, circle(0px at 50% 0));
  }
  to {
    clip-path: var(--transition-clip-to, circle(150% at 50% 0));
  }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
    clip-path: none !important;
  }
}

/* ===========================================
   MOCKUP PARITY DASHBOARD LAYER (cleaned)
   =========================================== */

#portal-dashboard-view {
  position: relative;
  min-height: calc(100vh - var(--portal-topbar-height));
  min-height: calc(100dvh - var(--portal-topbar-height));
  background: var(--bg);
  color: var(--text);
}

/* Notification footer/toggle/recent-view overrides removed — Tailwind handles styling */

#portal-dashboard-view #portal-push-prompt-slot {
  display: grid;
  gap: 0.75rem;
}

/* Tour/install banner visual overrides removed — Tailwind classes in JS handle all styling */


/* ===========================================
   Dashboard Layout Rules (non-duplicate)
   =========================================== */

#portal-dashboard-view #app-container {
  min-height: calc(100vh - var(--portal-topbar-height));
  min-height: calc(100dvh - var(--portal-topbar-height));
  padding-bottom: calc(var(--portal-bottom-nav-offset) + env(safe-area-inset-bottom, 0px));
}

#portal-dashboard-view .top-header {
  background: transparent;
}

#portal-dashboard-view .bottom-nav .nav-item.active {
  background-color: rgba(96, 165, 250, 0.1);
  color: #60a5fa;
  border-color: #60a5fa;
}
#portal-dashboard-view .bottom-nav .nav-item.active:hover {
  background-color: rgba(96, 165, 250, 0.1);
  color: #60a5fa;
}

/* tab-content, subtabs-container, backdrop-open → system/components.css */

#modal-backdrop.backdrop-open {
  opacity: 1;
  pointer-events: auto;
}

#drawer-property-details .tc-panel {
  translate: 0 100%;
  opacity: 0;
  transition: translate 0.3s ease, scale 0.3s ease, opacity 0.3s ease;
}

@media (min-width: 640px) {
  #drawer-property-details .tc-panel {
    translate: 0 1rem;
    scale: 0.95;
  }
}

#drawer-property-details.drawer-open .tc-panel {
  translate: 0 0;
  scale: 1;
  opacity: 1;
}

#gallery-modal.open {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 768px) {
  #portal-dashboard-view .bottom-nav {
    top: var(--portal-topbar-height);
    left: 0;
    bottom: 0;
    width: 80px;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 1.5rem;
    border-top: none;
    border-right: 1px solid var(--border);
  }

  #portal-dashboard-view #app-container {
    padding-bottom: 0;
    padding-left: 80px;
    width: 100%;
  }

  #portal-dashboard-view .top-header {
    left: 80px;
    width: calc(100% - 80px);
  }
}

/* ===========================================
   AVATAR HOVER-TO-REPLACE
   =========================================== */

.portal-avatar-wrap {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 9999px;
}

.portal-avatar-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.portal-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.portal-avatar-wrap:hover .portal-avatar-overlay,
.portal-avatar-wrap:active .portal-avatar-overlay {
  opacity: 1;
}

/* ===========================================
   LIGHTBOX PREV/NEXT ARROWS
   =========================================== */

.portal-lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 9999px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s, background 0.2s;
  z-index: 10;
}

.portal-lightbox-arrow:hover {
  opacity: 1;
  background: rgba(0,0,0,0.7);
}

.portal-lightbox-arrow--prev { left: 12px; }
.portal-lightbox-arrow--next { right: 12px; }

/* ===========================================
   BREADCRUMB (modal back-to-drawer)
   =========================================== */

.portal-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.75rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.portal-breadcrumb:hover {
  color: var(--text);
}

/* ===========================================
   TOAST STACKING SYSTEM
   =========================================== */

.portal-toast-container {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

@media (min-width: 768px) {
  .portal-toast-container {
    bottom: 1.5rem;
  }
}

.portal-toast-item {
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ref-light-card, #fff);
  background: var(--panel, var(--surface-card));
  border: 1px solid var(--border, var(--border-subtle));
  border-radius: var(--ref-radius-md, 8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  cursor: pointer;
  animation: toast-slide-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.portal-toast-item.error { background: var(--toast-error, #ef4444); }
.portal-toast-item.success { background: var(--toast-success, #10b981); }
.portal-toast-item.warning { background: var(--toast-warning, #f59e0b); }
.portal-toast-item.info { background: var(--toast-info, #3b82f6); }

.portal-toast-item.removing {
  animation: toast-slide-out 0.25s ease forwards;
}

html.light-mode .portal-toast-item,
html.light-mode .portal-toast,
html.light-mode .tc-toast {
  color: #111;
}

html.light-mode .portal-toast-item button {
  color: #111 !important;
  border-color: rgba(17, 24, 39, 0.24) !important;
  background: rgba(17, 24, 39, 0.08) !important;
}

.portal-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  width: 100%;
  animation: toast-countdown linear forwards;
}

@keyframes toast-slide-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-slide-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(10px); }
}

@keyframes toast-countdown {
  from { width: 100%; }
  to { width: 0; }
}

/* ===========================================
   SKELETON LOADING
   =========================================== */

.portal-skeleton {
  background: var(--border-subtle, rgba(255,255,255,0.06));
  border-radius: 6px;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

.portal-skeleton--circle {
  border-radius: 9999px;
}

@keyframes skeleton-shimmer {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ===========================================
   EMPTY STATE (illustrated)
   =========================================== */

.portal-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
  text-align: center;
  gap: 0.75rem;
}

.portal-empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--muted);
  opacity: 0.5;
}

.portal-empty-state p {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.portal-empty-state .portal-empty-cta {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.portal-empty-state .portal-empty-cta:hover {
  opacity: 0.8;
}

/* ============================================
   PORTAL MESSAGING
   ============================================ */

/* Two-pane layout */
.portal-msg-layout {
  --portal-msg-control-height: 42px;
  display: flex;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Full-width messages view — class set by JS, :has() as progressive enhancement */
main.messages-fullview,
main:has(> #tab-messages.active) {
  max-width: none;
  padding: 0;
}

main.messages-fullview ~ .portal-review-fab,
main:has(> #tab-messages.active) ~ .portal-review-fab {
  display: none;
}

#tab-messages {
  margin-top: 0 !important;
  height: calc(100dvh - var(--portal-topbar-height) - var(--portal-header-offset) - var(--portal-bottom-nav-offset));
  min-height: 440px;
}

#tab-messages.active {
  display: flex;
  flex-direction: column;
}

.portal-msg-sidebar {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--tc-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.portal-msg-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--tc-border);
}

.portal-msg-sidebar-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--tc-text);
}

.portal-msg-conversation-list {
  flex: 1;
  overflow-y: auto;
}

.portal-msg-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  color: var(--tc-text);
}

.portal-msg-conv-item:hover,
.portal-msg-conv-item.active {
  background: var(--tc-hover, rgba(0,0,0,0.04));
}

:root.dark .portal-msg-conv-item:hover,
:root.dark .portal-msg-conv-item.active {
  background: rgba(255,255,255,0.06);
}

.portal-msg-conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ref-blue-500, #3b82f6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.portal-msg-conv-info {
  flex: 1;
  min-width: 0;
}

.portal-msg-conv-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.portal-msg-conv-preview {
  font-size: 12px;
  color: var(--tc-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.portal-msg-conv-time {
  font-size: 11px;
  color: var(--tc-muted);
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}

.portal-msg-unread-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ref-blue-500, #3b82f6);
  display: inline-block;
}

.portal-msg-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.portal-msg-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tc-border);
}

.portal-msg-back-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--tc-text);
  border-radius: 6px;
}

.portal-msg-back-btn:hover {
  background: var(--tc-hover, rgba(0,0,0,0.04));
}

.portal-msg-chat-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--tc-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Shared avatar component --- */
.portal-msg-avatar {
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--ref-blue-500, #3b82f6) 15%, transparent);
  color: var(--ref-blue-500, #3b82f6);
  font-weight: 700;
}
.portal-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.portal-msg-avatar-sm { width: 24px; height: 24px; font-size: 0.55rem; }
.portal-msg-avatar-md { width: 32px; height: 32px; font-size: 0.65rem; }
.portal-msg-avatar-lg { width: 40px; height: 40px; font-size: 14px; }

/* --- Chat header enrichment --- */
.portal-msg-chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.portal-msg-chat-header-status {
  font-size: 11px;
  color: var(--tc-muted);
}
.portal-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  vertical-align: middle;
}
.portal-status-dot.online { background: #22c55e; }
.portal-status-dot.offline { background: var(--tc-muted); }

/* --- Admin avatar row in message thread --- */
.portal-msg-admin-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.portal-msg-bubble-wrap.is-theirs .portal-msg-bubble-meta {
  margin-left: 32px;
}

.portal-msg-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px;
}

/* Mobile: sidebar full-width, toggle to chat */
@media (max-width: 768px) {
  #tab-messages {
    height: calc(100dvh - var(--portal-topbar-height) - var(--portal-header-offset) - var(--portal-bottom-nav-offset));
    min-height: 360px;
  }

  .portal-msg-sidebar {
    width: 100%;
    min-width: unset;
  }

  .portal-msg-chat {
    display: none;
  }

  .portal-msg-layout.chat-active .portal-msg-sidebar {
    display: none;
  }

  .portal-msg-layout.chat-active .portal-msg-chat {
    display: flex;
  }

  .portal-msg-layout.chat-active .portal-msg-back-btn {
    display: block;
  }
}

@media (min-width: 768px) {
  #tab-messages {
    height: calc(100dvh - var(--portal-topbar-height) - var(--portal-header-offset) - 3rem);
  }
}

.portal-msg-date-sep {
  text-align: center;
  padding: 8px 0;
}

.portal-msg-date-sep span {
  font-size: 11px;
  color: var(--tc-muted);
  background: var(--tc-panel);
  padding: 2px 12px;
  border-radius: 10px;
  border: 1px solid var(--tc-border);
}

.portal-msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.portal-msg-bubble-wrap.is-mine {
  align-self: flex-end;
  align-items: flex-end;
}

.portal-msg-bubble-wrap.is-theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.portal-msg-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.portal-msg-bubble-wrap.is-mine .portal-msg-bubble {
  background: var(--tc-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.portal-msg-bubble-wrap.is-theirs .portal-msg-bubble {
  background: rgba(0, 0, 0, 0.05);
  color: var(--tc-text);
  border-bottom-left-radius: 4px;
}

:root.dark .portal-msg-bubble-wrap.is-theirs .portal-msg-bubble {
  background: rgba(255, 255, 255, 0.08);
}

.portal-msg-bubble.is-deleted {
  font-style: italic;
  opacity: 0.5;
}

.portal-msg-bubble-meta {
  font-size: 10px;
  color: var(--tc-muted);
  margin-top: 2px;
  display: flex;
  gap: 6px;
}

.portal-msg-bubble-wrap.is-mine .portal-msg-bubble-meta {
  justify-content: flex-end;
}

/* Message Status Icons */
.portal-msg-status {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.portal-msg-status-sending { color: var(--tc-muted); }
.portal-msg-status-sent { color: var(--tc-muted); }
.portal-msg-status-read { color: var(--ref-blue-400, #60a5fa); }
.portal-msg-status-failed {
  color: var(--ref-red-400, #f87171);
  font-weight: 700;
  font-size: 12px;
}
.portal-msg-retry-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--ref-red-400, #f87171);
  background: transparent;
  border: 1px solid var(--ref-red-400, #f87171);
  border-radius: 4px;
  cursor: pointer;
}
.portal-msg-retry-btn:hover {
  background: var(--ref-red-400, #f87171);
  color: #fff;
}

/* Unread Dot on Nav */
.portal-msg-unread-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ref-blue-500, #3b82f6);
}

.portal-msg-input-wrap {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--tc-border);
  background: var(--tc-panel);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.portal-msg-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.portal-msg-input-row textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: var(--portal-msg-control-height);
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--tc-border) 88%, transparent);
  border-radius: 12px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--tc-panel) 94%, #fff 6%),
    var(--tc-panel)
  );
  color: var(--tc-text);
  font-size: 16px;
  line-height: 1.4;
  font-family: inherit;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 12%, transparent);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.portal-msg-input-row textarea::placeholder {
  color: color-mix(in srgb, var(--tc-muted) 85%, transparent);
}

.portal-msg-input-row textarea:hover {
  border-color: color-mix(in srgb, var(--tc-blue) 30%, var(--tc-border));
}

.portal-msg-input-row textarea:focus {
  outline: none;
  border-color: var(--tc-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tc-blue) 22%, transparent);
}

.portal-msg-input-row textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.portal-msg-send-btn {
  height: var(--portal-msg-control-height);
  padding: 0 16px;
  min-width: 64px;
  border: none;
  border-radius: 10px;
  background: var(--tc-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.portal-msg-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.portal-msg-reply-preview {
  padding: 6px 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--tc-blue);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 0 6px 6px 0;
  font-size: 12px;
  color: var(--tc-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

:root.dark .portal-msg-reply-preview {
  background: rgba(255, 255, 255, 0.05);
}

.portal-msg-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  color: var(--tc-muted);
  gap: 12px;
  text-align: center;
}

.portal-msg-empty svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

/* --- Phase 3: Interaction Menu, Reactions, Reply --- */

.portal-msg-bubble-container {
  position: relative;
}

/* Action Bar */
.portal-msg-action-bar {
  position: absolute;
  top: -52px;
  display: flex;
  gap: 2px;
  background: var(--tc-panel);
  border: 1px solid var(--tc-border);
  border-radius: 8px;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 10;
  white-space: nowrap;
}
.portal-msg-action-bar.is-mine {
  right: 0;
}
.portal-msg-action-bar.is-theirs {
  left: 0;
}
.portal-msg-action-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.portal-msg-action-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}
:root.dark .portal-msg-action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Emoji Picker */
.portal-msg-emoji-picker {
  position: absolute;
  top: -104px;
  display: flex;
  gap: 2px;
  background: var(--tc-panel);
  border: 1px solid var(--tc-border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 11;
}
.portal-msg-action-bar.is-mine + .portal-msg-emoji-picker,
.portal-msg-action-bar.is-mine ~ .portal-msg-emoji-picker {
  right: 0;
}
.portal-msg-action-bar.is-theirs + .portal-msg-emoji-picker,
.portal-msg-action-bar.is-theirs ~ .portal-msg-emoji-picker {
  left: 0;
}
.portal-msg-emoji-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.portal-msg-emoji-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: scale(1.2);
}

/* Reaction Pills */
.portal-msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.portal-msg-reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  font-size: 13px;
  border: 1px solid var(--tc-border);
  border-radius: 12px;
  background: var(--tc-panel);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.portal-msg-reaction-pill:hover {
  background: rgba(0, 0, 0, 0.05);
}
:root.dark .portal-msg-reaction-pill:hover {
  background: rgba(255, 255, 255, 0.08);
}
.portal-msg-reaction-pill.is-mine {
  border-color: var(--ref-blue-400, #60a5fa);
  background: rgba(59, 130, 246, 0.08);
}

/* Reply Block */
.portal-msg-reply-block {
  padding: 4px 8px;
  margin-bottom: 4px;
  border-left: 3px solid var(--ref-blue-400, #60a5fa);
  border-radius: 0 4px 4px 0;
  background: rgba(0, 0, 0, 0.04);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
:root.dark .portal-msg-reply-block {
  background: rgba(255, 255, 255, 0.06);
}
.portal-msg-reply-sender {
  font-weight: 600;
  color: var(--ref-blue-500, #3b82f6);
}
.portal-msg-reply-body {
  color: var(--tc-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Reply in own bubble */
.portal-msg-bubble-wrap.is-mine .portal-msg-reply-block {
  background: rgba(255, 255, 255, 0.15);
}
.portal-msg-bubble-wrap.is-mine .portal-msg-reply-sender {
  color: rgba(255, 255, 255, 0.9);
}
.portal-msg-bubble-wrap.is-mine .portal-msg-reply-body {
  color: rgba(255, 255, 255, 0.7);
}

/* Reply cancel */
.portal-msg-reply-cancel {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tc-muted);
  font-size: 16px;
  padding: 0 4px;
}

/* Highlight for scroll-to-reply */
.portal-msg-highlight {
  animation: portal-msg-flash 1.5s ease;
}
@keyframes portal-msg-flash {
  0%, 100% { background: transparent; }
  30% { background: rgba(59, 130, 246, 0.12); }
}

/* Typing indicator in chat */
.portal-msg-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  background: var(--tc-hover, rgba(0,0,0,0.04));
  border-radius: 12px 12px 12px 4px;
  margin: 4px 0 4px 0;
  align-self: flex-start;
}

:root.dark .portal-msg-typing-indicator {
  background: rgba(255,255,255,0.08);
}

.portal-msg-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tc-muted);
  animation: portal-msg-typing-bounce 1.2s infinite;
}

.portal-msg-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.portal-msg-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes portal-msg-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Typing preview in sidebar */
.portal-msg-typing-preview {
  font-style: italic;
  color: var(--ref-blue-500, #3b82f6);
}

/* GIF button */
.portal-msg-gif-btn {
  width: 44px;
  height: var(--portal-msg-control-height);
  border: 1px solid var(--tc-border);
  border-radius: 10px;
  background: var(--tc-panel);
  color: var(--tc-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.portal-msg-gif-btn:hover,
.portal-msg-gif-btn.active {
  border-color: var(--ref-blue-500, #3b82f6);
  color: var(--ref-blue-500, #3b82f6);
}

/* GIF picker panel */
.portal-msg-gif-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  height: 300px;
  background: var(--tc-panel);
  border-top: 1px solid var(--tc-border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.portal-msg-gif-picker-header {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--tc-border);
}

.portal-msg-gif-search-input {
  flex: 1;
  border: 1px solid var(--tc-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--tc-bg);
  color: var(--tc-text);
  outline: none;
}

.portal-msg-gif-search-input:focus {
  border-color: var(--ref-blue-500, #3b82f6);
}

.portal-msg-gif-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--tc-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.portal-msg-gif-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px;
}

.portal-msg-gif-thumb {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.portal-msg-gif-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portal-msg-gif-thumb:hover {
  opacity: 0.8;
}

.portal-msg-gif-attribution {
  text-align: center;
  font-size: 10px;
  color: var(--tc-muted);
  padding: 4px;
  border-top: 1px solid var(--tc-border);
}

/* GIF in chat bubble */
.portal-msg-gif {
  max-width: 240px;
  border-radius: 8px;
  display: block;
}

.portal-msg-gif-caption {
  margin-top: 4px;
  font-size: 13px;
}
