    *,
    *::before,
    *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0
    }

    :root {
      --bg: #0b0e14;
      --surface: #131720;
      --surface2: #1a2030;
      --border: #1e2535;
      --accent: #4f8ef7;
      --success: #22c55e;
      --danger: #ef4444;
      --text: #e2e8f0;
      --muted: #64748b;
      --r: 14px
    }

    [data-theme="light"] {
      --bg: #f8fafc;
      --surface: #ffffff;
      --surface2: #f1f5f9;
      --border: #e2e8f0;
      --accent: #3b82f6;
      --text: #0f172a;
      --muted: #64748b
    }

    html,
    body {
      height: 100%;
      overflow: hidden
    }

    body {
      font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
      background: var(--bg);
      color: var(--text);
      display: flex;
      flex-direction: column
    }

    /* Buttons & Inputs */
    .btn {
      padding: 10px 16px;
      background: var(--accent);
      border: 1px solid transparent;
      border-radius: 10px;
      color: #fff;
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: all .15s
    }

    .btn:hover {
      opacity: .9
    }

    .btn:disabled {
      opacity: .5;
      cursor: not-allowed
    }

    .btn-ghost {
      background: transparent;
      color: var(--muted);
      border: 1px solid transparent
    }

    .btn-ghost:hover {
      color: var(--text);
      background: var(--surface2)
    }

    .input {
      width: 100%;
      padding: 10px 14px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 10px;
      color: var(--text);
      font-family: inherit;
      font-size: 13px;
      outline: none;
      transition: border-color .2s
    }

    .input:focus {
      border-color: var(--accent)
    }

    /* Login Screen */
    /* Scrolls when a step is taller than the screen (the one-time TOTP secret after creating a
       workspace). The card centers with margin:auto rather than align-items:center, so an overflowing
       card starts at the top instead of being clipped at both ends. */
    #view-login {
      flex: 1;
      display: flex;
      min-height: 0;
      overflow-y: auto
    }

    .login-card {
      width: 380px;
      margin: auto;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--r);
      padding: 40px;
      box-shadow: 0 24px 80px rgba(0, 0, 0, .5)
    }

    .login-logo {
      text-align: center;
      margin-bottom: 32px
    }

    .login-logo .icon {
      width: 52px;
      height: 52px;
      background: var(--accent);
      border-radius: 14px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 26px;
      color: #fff;
      margin-bottom: 12px
    }

    .login-logo h1 {
      font-size: 22px;
      font-weight: 700
    }

    .login-logo p {
      font-size: 13px;
      color: var(--muted);
      margin-top: 4px
    }

    .form-group {
      margin-bottom: 16px
    }

    .form-group label {
      display: block;
      font-size: 12px;
      font-weight: 500;
      color: var(--muted);
      margin-bottom: 6px;
      text-transform: uppercase;
      letter-spacing: .5px
    }

    .err-msg {
      background: rgba(239, 68, 68, .12);
      border: 1px solid rgba(239, 68, 68, .3);
      color: #fca5a5;
      border-radius: 10px;
      padding: 10px 14px;
      font-size: 13px;
      margin-bottom: 16px;
      display: none
    }

    body.is-resizing * {
      pointer-events: none !important;
      transition: none !important;
      animation: none !important;
    }

    /* Portal Screen */
    #view-portal {
      flex: 1;
      display: none;
      flex-direction: row;
      height: 100%
    }

    /* Sidebar */
    .sidebar {
      /* width: 280px; */
      width: 320px;
      background: var(--surface);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      flex-shrink: 0
    }

    .sidebar-head {
      padding: 16px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between
    }

    .sidebar-head h2 {
      font-size: 14px;
      font-weight: 700;
      color: var(--accent)
    }

    .chat-actions {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .chat-actions button {
      background: var(--surface2);
      border: 1px solid var(--border);
      color: var(--text);
      border-radius: 8px;
      padding: 0 12px;
      height: 32px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      transition: all 0.15s ease;
    }

    .chat-actions button:hover {
      background: var(--border);
      color: var(--text);
    }

    .chat-list {
      flex: 1;
      overflow-y: auto
    }

    .chat-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 16px;
      cursor: pointer;
      border-bottom: 1px solid var(--border);
      transition: background .15s
    }

    .chat-item:hover {
      background: var(--surface2)
    }

    .chat-item.active {
      background: rgba(79, 142, 247, .1);
      border-left: 3px solid var(--accent)
    }

    .chat-item .av {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: var(--accent);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 15px;
      font-weight: 700;
      color: #fff;
      flex-shrink: 0
    }

    .chat-item .info {
      flex: 1;
      min-width: 0
    }

    .chat-item .name {
      font-size: 13.5px;
      font-weight: 600;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    .chat-item .sub {
      font-size: 11.5px;
      color: var(--muted);
      margin-top: 3px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    .sidebar-foot {
      padding: 12px 16px;
      border-top: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between
    }

    .user-info {
      font-size: 12px
    }

    .user-info b {
      display: block;
      font-weight: 600
    }

    .user-info span {
      color: var(--muted);
      font-size: 11px
    }

    /* Main Chat Area */
    .main {
      flex: 1;
      display: flex;
      flex-direction: column;
      background: var(--bg);
      height: 100%;
      overflow: hidden;
      position: relative;
    }

    .main-empty {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: var(--muted)
    }

    .main-empty .icon {
      font-size: 48px;
      margin-bottom: 16px;
      opacity: .5
    }

    .chat-header {
      padding: 14px 20px;
      border-bottom: 1px solid var(--border);
      background: var(--surface);
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
      flex-grow: 0
    }

    .chat-header .header-info {
      display: flex;
      align-items: center;
      gap: 12px
    }

    .chat-header .av {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: var(--accent);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      font-weight: 700;
      color: #fff
    }

    .chat-header h3 {
      font-size: 15px;
      font-weight: 600
    }

    .chat-header p {
      font-size: 11px;
      color: var(--muted)
    }

    .messages {
      flex: 1 1 0%;
      min-height: 0;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
      touch-action: pan-y;
      padding: 20px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      contain: style;
    }

    /* Chat body layout: an optional topics sidebar to the left of the messages+input column.
       .chat-body-row sits below .chat-header and fills the rest of .main's height; .chat-body-col
       carries position:relative so #scroll-down-btn (position:absolute) anchors to the messages
       column specifically, not the full width including the topics sidebar. */
    .chat-body-row {
      flex: 1 1 0%;
      min-height: 0;
      height: 100%;
      display: flex;
      overflow: hidden;
    }

    .chat-body-col {
      flex: 1 1 0%;
      min-width: 0;
      min-height: 0;
      height: 100%;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      position: relative;
    }

    .topics-sidebar {
      width: 200px;
      flex-shrink: 0;
      background: var(--surface);
      border-right: 1px solid var(--border);
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      padding: 10px;
      gap: 2px;
    }

    .topics-sidebar .topic-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 9px 10px;
      border-radius: 8px;
      border: none;
      background: transparent;
      color: var(--text);
      font-size: 13px;
      font-family: inherit;
      text-align: left;
      cursor: pointer;
      width: 100%;
    }

    .topics-sidebar .topic-item:hover {
      background: var(--surface2);
    }

    .topics-sidebar .topic-item.active {
      background: var(--accent);
      color: #fff;
    }

    .topics-sidebar .topic-item .topic-name {
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .topics-sidebar .topic-unread-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--accent);
      flex-shrink: 0;
    }

    .topics-sidebar .topic-item.active .topic-unread-dot {
      background: #fff;
    }

    .topics-sidebar .btn-new-topic {
      margin-top: 6px;
      padding: 9px 10px;
      border-radius: 8px;
      border: 1px dashed var(--border);
      background: transparent;
      color: var(--accent);
      font-size: 12px;
      font-weight: 600;
      font-family: inherit;
      cursor: pointer;
      text-align: left;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .topics-sidebar .btn-new-topic:hover {
      background: var(--surface2);
    }

    /* At phone width, a permanently-docked vertical sidebar leaves too little room for the
       messages column -- verified in-browser: bubble timestamps wrapped one character per line.
       The main chat sidebar avoids this by becoming a toggled overlay; a second overlay just for
       topics would be a lot of new UI for a secondary feature, so instead this reuses the exact
       same .topic-item/.btn-new-topic markup and turns it into a horizontal scrolling strip
       above the messages -- same pattern the old topic tab-row used, kept only at this breakpoint. */
    @media (max-width: 768px) {
      .chat-body-row {
        flex-direction: column;
      }

      .topics-sidebar {
        width: 100%;
        max-height: 46px;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 6px 10px;
        gap: 6px;
        scrollbar-width: none;
      }

      .topics-sidebar::-webkit-scrollbar {
        display: none;
      }

      .topics-sidebar .topic-item {
        width: auto;
        flex-shrink: 0;
        padding: 6px 12px;
        border-radius: 20px;
        background: var(--surface2);
      }

      .topics-sidebar .btn-new-topic {
        width: auto;
        flex-shrink: 0;
        margin-top: 0;
        white-space: nowrap;
      }
    }

    .msg-row {
      display: flex;
      align-items: flex-end;
      gap: 10px;
    }

    .msg-row.out {
      flex-direction: row-reverse
    }

    .msg-av {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background: var(--surface2);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 600;
      color: var(--accent);
      flex-shrink: 0
    }

    .msg-row.out .msg-av {
      background: var(--accent);
      color: #fff
    }

    .bubble {
      max-width: 65%;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px 12px 12px 4px;
      padding: 10px 14px;
      position: relative;
      overflow-wrap: anywhere;
      word-break: break-word;
    }

    .msg-row.out .bubble {
      background: rgba(79, 142, 247, .15);
      border-color: rgba(79, 142, 247, .3);
      border-radius: 12px 12px 4px 12px
    }

    .sender-name {
      font-size: 11px;
      font-weight: 700;
      color: var(--accent);
      margin-bottom: 4px;
      display: block
    }

    .msg-text {
      font-size: 13.5px;
      line-height: 1.5;
      white-space: pre-wrap;
      word-break: break-word;
      overflow-wrap: anywhere;
    }

    .msg-time {
      font-size: 10px;
      color: var(--muted);
      margin-top: 6px;
      text-align: right
    }

    .file-box {
      display: flex;
      align-items: center;
      gap: 10px;
      background: var(--surface2);
      padding: 10px;
      border-radius: 8px;
      margin-bottom: 6px;
      border: 1px solid var(--border);
      max-width: 100%;
      min-width: 0;
    }

    .file-box a.file-link {
      color: var(--accent);
      font-size: 13px;
      font-weight: 500;
      text-decoration: none;
      display: flex;
      min-width: 0;
      flex: 1;
    }

    .file-box .file-name-part {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      min-width: 0;
      flex: 0 1 auto;
    }

    .file-box .file-ext-part {
      white-space: nowrap;
      flex-shrink: 0;
    }

    .file-box a:hover {
      text-decoration: underline
    }

    /* Input Area */
    .input-area {
      padding: 16px 20px;
      background: var(--surface);
      border-top: 1px solid var(--border);
      flex-shrink: 0;
      flex-grow: 0
    }

    .input-row {
      display: flex;
      gap: 12px;
      align-items: flex-end
    }

    .input-row textarea {
      flex: 1;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 16px;
      color: var(--text);
      font-family: inherit;
      font-size: 14px;
      resize: none;
      outline: none;
      max-height: 120px;
      line-height: 1.5;
      transition: border-color .2s
    }

    .input-row textarea:focus {
      border-color: var(--accent)
    }

    .send-btn {
      width: 47px;
      height: 47px;
      border-radius: 12px;
      background: var(--accent);
      color: #fff;
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      flex-shrink: 0
    }

    .send-btn:hover {
      opacity: .9
    }

    .attach-btn {
      width: 47px;
      height: 47px;
      border-radius: 12px;
      background: var(--bg);
      border: 1px solid var(--border);
      color: var(--muted);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      flex-shrink: 0
    }

    .attach-btn:hover {
      color: var(--text);
      border-color: var(--text)
    }

    /* Modals */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, .6);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 1100;
      backdrop-filter: blur(2px)
    }

    .modal-overlay.open {
      display: flex
    }

    .modal {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px 24px 16px 24px;
      width: 400px;
      max-width: 90vw
    }

    .modal h3 {
      font-size: 16px;
      font-weight: 700;
      margin-bottom: 14px
    }

    .modal-actions {
      display: flex;
      gap: 10px;
      justify-content: flex-end;
      margin-top: 14px
    }

    .user-search-list {
      max-height: 200px;
      overflow-y: auto;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 8px;
      margin-top: 10px
    }

    .user-search-item {
      padding: 10px 14px;
      font-size: 13px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 10px;
      cursor: pointer
    }

    .user-search-item:last-child {
      border-bottom: none
    }

    .user-search-item:hover {
      background: var(--surface2)
    }

    .user-search-item input {
      width: 16px;
      height: 16px;
      accent-color: var(--accent)
    }

    /* Scrollbars */
    ::-webkit-scrollbar {
      width: 6px
    }

    ::-webkit-scrollbar-track {
      background: transparent
    }

    ::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 6px
    }

    /* Lightbox */
    .lightbox {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.92);
      z-index: 1200;
      display: none;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      backdrop-filter: blur(5px)
    }

    .lightbox.show {
      display: flex
    }

    .lightbox img {
      max-width: 90%;
      max-height: calc(100vh - 160px);
      border-radius: 8px;
      box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
      object-fit: contain
    }

    .lightbox-actions {
      position: absolute;
      top: 20px;
      right: 20px;
      display: flex;
      gap: 12px
    }

    .lightbox-btn {
      background: rgba(255, 255, 255, 0.1);
      border: 1px solid rgba(255, 255, 255, 0.2);
      color: #fff;
      width: 44px;
      height: 44px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.2s;
      backdrop-filter: blur(10px)
    }

    .lightbox-btn:hover {
      background: var(--accent);
      border-color: var(--accent)
    }

    .media-img {
      width: auto;
      height: auto;
      max-width: min(440px, 100%);
      border-radius: 14px;
      cursor: pointer;
      max-height: 400px;
      object-fit: cover;
      display: block;
      margin-bottom: 0;
      transition: transform 0.2s;
    }

    .media-img:hover {
      transform: scale(1.015);
    }

    .media-video {
      width: auto;
      height: auto;
      max-width: min(440px, 100%);
      max-height: 400px;
      border-radius: 14px;
      display: block;
      object-fit: cover;
    }

    /* OCR */
    .ocr-result-area {
      display: none;
      position: absolute;
      bottom: 40px;
      left: 50%;
      transform: translateX(-50%);
      width: 90%;
      max-width: 800px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 16px;
      box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
      z-index: 100
    }

    .ocr-result-area.show {
      display: flex;
      flex-direction: column;
      gap: 12px
    }

    .ocr-result-area textarea {
      width: 100%;
      height: 120px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text);
      padding: 10px;
      font-size: 13px;
      resize: none;
      outline: none
    }

    .ocr-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      cursor: move
    }

    .ocr-header h4 {
      font-size: 14px;
      color: var(--accent);
      pointer-events: none
    }

    .ocr-loader {
      display: none;
      align-items: center;
      gap: 10px;
      font-size: 13px;
      color: var(--accent);
      margin-top: 10px
    }

    .ocr-loader.show {
      display: flex
    }

    @keyframes spin {
      to {
        transform: rotate(360deg)
      }
    }

    .ocr-spinner {
      width: 16px;
      height: 16px;
      border: 2px solid rgba(79, 142, 247, .3);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin .8s linear infinite
    }

    .ocr-overlay {
      position: absolute;
      top: 0;
      left: 0;
      pointer-events: none;
      z-index: 50;
      user-select: text
    }

    .ocr-overlay .word {
      position: absolute;
      color: transparent;
      background: rgba(79, 142, 247, 0);
      cursor: text;
      pointer-events: auto;
      white-space: nowrap;
      line-height: 1
    }

    .ocr-overlay .word::selection {
      background: rgba(79, 142, 247, 0.3);
      color: transparent
    }

    .btn-ocr {
      border: none;
      border-radius: 6px;
      padding: 6px 12px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      transition: all .2s;
      font-family: inherit
    }

    .btn-ocr-primary {
      background: var(--accent);
      color: #fff
    }

    .btn-ocr-primary:hover {
      opacity: 0.9;
      transform: translateY(-1px)
    }

    .btn-ocr-ghost {
      background: none;
      color: var(--muted);
      border: 1px solid var(--border)
    }

    .btn-ocr-ghost:hover {
      color: var(--text);
      border-color: var(--muted)
    }

    /* Mobile Responsiveness */
    .mobile-menu-btn {
      display: none;
      background: none;
      border: none;
      color: var(--text);
      font-size: 20px;
      cursor: pointer;
      padding: 4px
    }

    .sidebar-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.5);
      z-index: 999;
      backdrop-filter: blur(2px)
    }

    .sidebar-overlay.open {
      display: block
    }

    .mobile-header {
      display: none;
      padding: 14px 20px;
      border-bottom: 1px solid var(--border);
      align-items: center;
      background: var(--surface)
    }

    .mobile-back-btn {
      display: none;
    }

    @media (max-width: 1024px) {
      #view-portal.chat-open .sidebar {
        display: none !important;
      }

      #view-portal.chat-open .main {
        display: flex !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        overflow: hidden !important;
      }

      #view-portal:not(.chat-open) .sidebar {
        display: flex !important;
        width: 100% !important;
      }

      #view-portal:not(.chat-open) .main {
        display: none !important;
      }

      .chat-body-row {
        flex: 1 1 0% !important;
        min-height: 0 !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
      }

      .topics-sidebar {
        width: 100% !important;
        max-height: 44px !important;
        min-height: 44px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap !important;
        padding: 6px 12px !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
        -webkit-overflow-scrolling: touch !important;
      }

      .topics-sidebar .topic-item {
        width: auto !important;
        flex-shrink: 0 !important;
        padding: 4px 10px !important;
        font-size: 12px !important;
      }

      .topics-sidebar .btn-new-topic {
        flex-shrink: 0 !important;
        margin-top: 0 !important;
        padding: 4px 10px !important;
        font-size: 11px !important;
      }

      .chat-body-col {
        flex: 1 1 0% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        height: 100% !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
      }

      .sidebar {
        position: static;
        height: 100%;
        transform: none;
        transition: none;
        z-index: auto;
      }

      .sidebar.open {
        transform: none;
      }

      .sidebar-overlay {
        display: none !important;
      }

      .mobile-menu-btn {
        display: none !important;
      }

      .mobile-back-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--text);
        cursor: pointer;
        padding: 4px;
      }

      .chat-header {
        padding: 10px 16px;
        flex-shrink: 0 !important;
      }

      .mobile-header {
        display: none !important;
      }

      .messages {
        flex: 1 1 0% !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain !important;
        touch-action: pan-y !important;
        padding: 16px 12px !important;
      }

      .bubble {
        max-width: 82%;
      }

      .bubble.media-only,
      .bubble.media-with-caption {
        width: fit-content !important;
        max-width: min(280px, 75vw) !important;
        display: inline-flex !important;
        flex-direction: column;
      }

      .bubble.media-only .media-wrapper {
        max-width: 100% !important;
        width: fit-content !important;
        min-width: 0 !important;
        min-height: 0 !important;
        background: transparent !important;
        border-radius: 14px !important;
      }

      .bubble.media-with-caption .media-wrapper {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        background: #000 !important;
        border-radius: 0 !important;
      }

      .bubble.media-only .media-img,
      .bubble.media-only .media-video {
        border-radius: 14px !important;
        width: auto !important;
        height: auto !important;
        max-width: min(260px, 75vw) !important;
        max-height: 220px !important;
        display: block !important;
        object-fit: contain !important;
        background: transparent !important;
      }

      .bubble.media-with-caption .media-img,
      .bubble.media-with-caption .media-video {
        border-radius: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 200px !important;
        display: block !important;
        object-fit: cover !important;
        background: #000 !important;
      }

      .media-img,
      .media-video {
        max-width: min(260px, 100%) !important;
        max-height: 200px !important;
      }

      .input-area {
        padding: 10px 12px;
        flex-shrink: 0 !important;
      }

      .login-card {
        width: 90%;
        padding: 24px;
      }
    }

    @media (max-width: 768px) {
      .desktop-search-container {
        display: none !important;
      }

      .mobile-search-trigger {
        display: block !important;
      }

      .chat-header {
        padding: 8px 12px;
      }

      .chat-header .header-info {
        gap: 6px !important;
      }

      .chat-header h3 {
        font-size: 13.5px;
        max-width: 110px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .chat-header p {
        font-size: 10px;
      }

      .chat-header .btn-ghost {
        padding: 6px 8px !important;
        font-size: 10.5px !important;
      }
    }

    @media (max-width: 480px) {
      .chat-header h3 {
        max-width: 80px;
      }
    }

    .unread-dot {
      width: 8px;
      height: 8px;
      background-color: var(--accent);
      border-radius: 50%;
      box-shadow: 0 0 8px var(--accent);
      margin-left: 8px;
      align-self: center;
      flex-shrink: 0;
    }

    /* Mentions Styling */
    .mention-tag {
      background: rgba(79, 142, 247, 0.15);
      color: var(--accent);
      padding: 2px 6px;
      border-radius: 4px;
      font-weight: 500;
      display: inline-block;
    }

    .mention-dropdown {
      position: absolute;
      bottom: 100%;
      left: 60px;
      right: 60px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 10px;
      box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
      max-height: 180px;
      overflow-y: auto;
      z-index: 10;
      display: none;
    }

    .mention-item {
      padding: 10px 14px;
      font-size: 13px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid var(--border);
      color: var(--text);
    }

    .mention-item:last-child {
      border-bottom: none;
    }

    .mention-item:hover,
    .mention-item.active {
      background: var(--surface2);
      color: var(--accent);
    }

    /* Reply Styling */
    .reply-input-banner {
      display: none;
      align-items: center;
      justify-content: space-between;
      background: var(--surface2);
      border-left: 4px solid var(--accent);
      padding: 8px 16px;
      font-size: 12px;
      border-bottom: 1px solid var(--border);
    }

    .reply-input-banner .reply-cancel {
      cursor: pointer;
      color: var(--danger);
      font-weight: 600;
    }

    .reply-bubble-preview {
      background: rgba(255, 255, 255, 0.04);
      border-left: 3px solid var(--accent);
      padding: 6px 10px;
      border-radius: 4px;
      font-size: 11px;
      margin-bottom: 6px;
      color: var(--muted);
      cursor: pointer;
      transition: background 0.2s;
    }

    .reply-bubble-preview:hover {
      background: rgba(255, 255, 255, 0.08);
    }

    .reply-bubble-preview .reply-sender {
      font-weight: 600;
      color: var(--accent);
      display: block;
      margin-bottom: 2px;
    }



    .msg-actions-trigger {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      display: none;
      gap: 6px;
      z-index: 5;
    }

    .msg-row:not(.out) .msg-actions-trigger {
      right: -45px;
    }

    .msg-row.out .msg-actions-trigger {
      left: -45px;
    }

    .msg-row:hover .msg-actions-trigger {
      display: flex;
    }

    .btn-msg-action {
      background: var(--surface2);
      border: 1px solid var(--border);
      color: var(--muted);
      width: 26px;
      height: 26px;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 11px;
      transition: all 0.15s;
    }

    .btn-msg-action:hover {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
    }

    /* Highlight class for scrolled target message */
    .msg-row.highlight-blink .bubble {
      animation: blink-highlight 1.5s ease-out;
    }

    @keyframes blink-highlight {
      0% {
        box-shadow: 0 0 0 0px var(--accent);
        background: var(--surface2);
      }

      30% {
        box-shadow: 0 0 0 4px var(--accent);
        background: rgba(79, 142, 247, 0.15);
      }

      100% {
        box-shadow: 0 0 0 0px var(--accent);
      }
    }

    .sidebar-nav {
      display: flex;
      border-top: 1px solid var(--border);
      background: var(--surface);
      height: 48px;
      flex-shrink: 0;
    }

    .nav-tab {
      flex: 1;
      background: transparent;
      border: none;
      color: var(--muted);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 4px;
      font-family: inherit;
      font-size: 10px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.15s;
    }

    .nav-tab:hover {
      color: var(--text);
      background: var(--surface2);
    }

    .nav-tab.active {
      color: var(--accent);
    }

    .nav-tab svg {
      width: 18px;
      height: 18px;
    }

    /* Modern Toggle Switches */
    .switch-container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 14px 16px;
      background: var(--surface2);
      border-radius: 10px;
      border: 1px solid var(--border);
      transition: all 0.2s ease;
    }

    .switch-container:hover {
      border-color: rgba(79, 142, 247, 0.4);
    }

    .switch-label-group {
      display: flex;
      flex-direction: column;
      gap: 3px;
    }

    .switch-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
    }

    .switch-desc {
      font-size: 11px;
      color: var(--muted);
    }

    .custom-switch {
      position: relative;
      display: inline-block;
      width: 40px;
      height: 22px;
      flex-shrink: 0;
    }

    .custom-switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: var(--border);
      transition: .25s ease;
      border-radius: 34px;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 16px;
      width: 16px;
      left: 3px;
      bottom: 3px;
      background-color: #fff;
      transition: .25s ease;
      border-radius: 50%;
    }

    input:checked+.slider {
      background-color: var(--accent);
    }

    input:checked+.slider:before {
      transform: translateX(18px);
    }

    /* Media loading spinner animation styles */
    .media-wrapper {
      position: relative;
      display: inline-block;
      min-width: 120px;
      min-height: 120px;
      width: fit-content;
      max-width: min(440px, 100%);
      border-radius: 14px;
      overflow: hidden;
      background: var(--surface2);
      vertical-align: middle;
    }

    .media-wrapper::before {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      width: 24px;
      height: 24px;
      margin: -12px 0 0 -12px;
      border: 2px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: media-spinner 0.6s linear infinite;
      z-index: 1;
      transition: opacity 0.25s ease;
    }

    .media-wrapper.loaded::before {
      opacity: 0;
      pointer-events: none;
    }

    .media-wrapper img,
    .media-wrapper video {
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    .media-wrapper.loaded img,
    .media-wrapper.loaded video {
      opacity: 1;
    }

    /* Hide native webkit video loading spinner to prevent duplicate loaders */
    .media-wrapper video::-webkit-media-controls-loading-indicator {
      display: none !important;
    }

    @keyframes media-spinner {
      to {
        transform: rotate(360deg);
      }
    }

    .dropdown-item-hover {
      transition: background 0.15s ease, color 0.15s ease;
    }

    .dropdown-item-hover:hover {
      background: var(--surface2) !important;
      color: var(--accent) !important;
    }

    /* Folder Tabs Styling */
    .folder-tab {
      padding: 6px 12px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 20px;
      color: var(--muted);
      font-size: 11.5px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s ease;
      display: inline-block;
      user-select: none;
    }

    .folder-tab:hover {
      color: var(--text);
      border-color: var(--muted);
    }

    .folder-tab.active {
      background: rgba(79, 142, 247, 0.15);
      border-color: var(--accent);
      color: var(--accent);
    }

    .btn-folder-settings {
      background: transparent;
      border: none;
      color: var(--muted);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      padding: 6px;
      border-radius: 50%;
      transition: all 0.2s ease;
      flex-shrink: 0;
    }

    .btn-folder-settings:hover {
      color: var(--text);
      background: var(--surface2);
    }

    /* Folder tabs: "All" and the settings gear stay put; only this inner row scrolls, with a
       mask-image edge fade (not a background-color gradient, so it works unmodified in both
       themes) showing which direction has more to scroll to. */
    .folder-tabs-scroll {
      display: flex;
      align-items: center;
      gap: 8px;
      flex: 1 1 auto;
      min-width: 0;
      overflow-x: auto;
      scrollbar-width: none;
      -ms-overflow-style: none;
    }

    .folder-tabs-scroll::-webkit-scrollbar {
      display: none;
    }

    .folder-tabs-scroll.fade-right:not(.fade-left) {
      mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
      -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
    }

    .folder-tabs-scroll.fade-left:not(.fade-right) {
      mask-image: linear-gradient(to left, #000 calc(100% - 24px), transparent 100%);
      -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 24px), transparent 100%);
    }

    .folder-tabs-scroll.fade-left.fade-right {
      mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
      -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
    }

    #sidebar-folder-tabs .folder-tab-all {
      flex-shrink: 0;
    }

    /* List item for folders edit view */
    .folder-list-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 10px;
      margin-bottom: 8px;
    }
    .folder-list-item:last-child {
      margin-bottom: 0;
    }

    .folder-list-item-info {
      display: flex;
      flex-direction: column;
      gap: 2px;
      text-align: left;
    }

    .folder-list-item-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
    }

    .folder-list-item-actions {
      display: flex;
      gap: 6px;
    }

    /* New Chat Dropdown Menu */
    .new-chat-dropdown {
      position: absolute;
      top: 100%;
      right: 0;
      margin-top: 8px;
      width: 220px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
      z-index: 1000;
      padding: 6px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      animation: dropdownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes dropdownFadeIn {
      from {
        opacity: 0;
        transform: translateY(-8px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    .dropdown-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 12px;
      border-radius: 8px;
      cursor: pointer;
      transition: background 0.15s;
    }

    .dropdown-item:hover {
      background: var(--surface2);
    }

    .dropdown-item svg {
      color: var(--accent);
      flex-shrink: 0;
    }

    .dropdown-text {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      min-width: 0;
    }

    .dropdown-text .title {
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
      line-height: 1.2;
    }

    .dropdown-text .desc {
      font-size: 10.5px;
      color: var(--muted);
      margin-top: 2px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 100%;
    }

    /* Per-chat context menu (right-click / long-press on a sidebar row). Unlike
       .new-chat-dropdown, which is position:absolute anchored to a fixed corner of its button,
       this needs position:fixed because showChatContextMenu() places it at the click/touch
       point, which can be anywhere in the sidebar. Reuses .dropdown-item for the menu item
       itself so it looks and behaves like every other menu in this app. */
    .chat-context-menu {
      position: fixed;
      width: 180px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 10px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
      z-index: 1400;
      padding: 6px;
    }

    .chat-context-menu .dropdown-item.disabled {
      opacity: 0.45;
      cursor: default;
      pointer-events: none;
    }

    .btn-mark-all-read {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text);
      width: 32px;
      height: 32px;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      flex-shrink: 0;
      box-sizing: border-box;
      transition: all 0.15s ease;
    }

    .btn-mark-all-read svg {
      width: 16px;
      height: 16px;
      stroke-width: 2.2;
      flex-shrink: 0;
    }

    .btn-mark-all-read:hover {
      color: var(--accent);
      border-color: var(--accent);
      background: var(--border);
    }

    /* Scroll Down Floating Action Button */
    .scroll-down-btn {
      position: absolute;
      bottom: 85px; /* just above input-area */
      right: 24px;
      width: 42px;
      height: 42px;
      border-radius: 50%;
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--muted);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
      z-index: 99;
      transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
      opacity: 0;
      transform: scale(0.8);
      pointer-events: none;
      padding: 0;
    }

    .scroll-down-btn.show {
      opacity: 1;
      transform: scale(1);
      pointer-events: auto;
    }

    .scroll-down-btn:hover {
      background: var(--surface2);
      color: var(--text);
      transform: scale(1.05);
    }

    .scroll-down-btn:active {
      transform: scale(0.95);
    }

    .scroll-down-badge {
      position: absolute;
      top: -4px;
      right: -4px;
      background: var(--accent);
      color: #ffffff;
      font-size: 10px;
      font-weight: 700;
      min-width: 18px;
      height: 18px;
      border-radius: 9px;
      padding: 0 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px solid var(--surface);
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    }

    /*
      #toast and .no-scrollbar used to have a second, later definition inline in index.html's
      <head> that silently won the cascade over this one (identical selectors, later in
      source order beats z-index/specificity). This block has been updated to match exactly
      what was actually rendering -- the higher z-index here previously, the missing mobile
      #toast position, and the missing desktop .no-scrollbar override were all dead code that
      never took visible effect. Nothing below is a behavior change; it is the inline
      overrides folded into their real selectors so there is one definition to read instead of
      two competing ones 1,500 lines apart in different files.
    */
    #toast {
      position: fixed;
      bottom: 24px;
      right: 24px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px 20px;
      font-size: 13px;
      color: var(--text);
      opacity: 0;
      transform: translateY(10px);
      transition: all .2s;
      pointer-events: none;
      z-index: 1300;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    #toast.show {
      opacity: 1;
      transform: translateY(0);
    }
    #toast.success {
      border-color: rgba(34, 197, 94, 0.4) !important;
      color: var(--success) !important;
      background: rgba(34, 197, 94, 0.1) !important;
    }
    #toast.error {
      border-color: rgba(239, 68, 68, 0.4) !important;
      color: var(--danger) !important;
      background: rgba(239, 68, 68, 0.1) !important;
    }
    @media (max-width: 768px) {
      #toast {
        bottom: 80px !important;
        right: 16px !important;
        left: 16px !important;
        text-align: center;
      }
    }

    .no-scrollbar {
      scrollbar-width: none !important; /* Firefox */
      -ms-overflow-style: none !important;  /* IE and Edge */
    }
    .no-scrollbar::-webkit-scrollbar {
      display: none !important; /* Chrome, Safari, and Opera */
    }
    @media (min-width: 1025px) {
      .no-scrollbar {
        scrollbar-width: auto !important;
        -ms-overflow-style: auto !important;
      }
      .no-scrollbar::-webkit-scrollbar {
        display: block !important;
        width: 6px !important;
      }
    }

    /* App-wide loading spinner animation (moved from index.html's inline <style>) */
    .app-spinner {
      display: inline-block;
      width: 14px;
      height: 14px;
      border: 2px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: app-spin 0.6s linear infinite;
      vertical-align: middle;
    }
    .app-spinner-lg {
      width: 28px;
      height: 28px;
      border-width: 3px;
    }
    .app-spinner-sm {
      width: 11px;
      height: 11px;
      border-width: 1.5px;
    }
    @keyframes app-spin {
      to { transform: rotate(360deg); }
    }

    .search-input-wrapper {
      position: relative;
      display: flex;
      align-items: center;
      width: 100%;
    }
    .search-spinner {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      pointer-events: none;
      display: none;
    }

    /* Sidebar resizing and compact mode styles */
    .sidebar-resizer {
      width: 14px;
      height: 100% !important;
      cursor: col-resize;
      background: transparent;
      flex-shrink: 0;
      transition: background 0.15s;
      z-index: 15;
      margin-left: -7px;
      margin-right: -7px;
      position: relative;
      align-self: stretch;
      pointer-events: auto !important;
      touch-action: none;
      user-select: none;
      -webkit-user-select: none;
    }
    .sidebar-resizer:hover::after, .sidebar-resizer.dragging::after {
      content: '';
      position: absolute;
      left: 6px;
      top: 0;
      bottom: 0;
      width: 2px;
      background: var(--accent);
    }
    @media (max-width: 768px) {
      .sidebar-resizer {
        display: none !important;
      }
    }

    /* Compact sidebar overrides (Desktop Only) */
    @media (min-width: 769px) {
      .sidebar.sidebar-compact {
        width: 72px !important;
        transition: width 0.1s ease;
      }
      .sidebar.sidebar-compact .sidebar-head {
        justify-content: center;
        padding: 16px 0;
      }
      .sidebar.sidebar-compact #sidebar-title,
      .sidebar.sidebar-compact .chat-actions,
      .sidebar.sidebar-compact #sidebar-search-container,
      .sidebar.sidebar-compact #sidebar-folder-tabs,
      .sidebar.sidebar-compact #sidebar-sync-status,
      .sidebar.sidebar-compact #password-reminder-banner,
      .sidebar.sidebar-compact .sidebar-nav {
        display: none !important;
      }
      .sidebar.sidebar-compact .chat-item {
        justify-content: center;
        padding: 12px 0;
      }
      .sidebar.sidebar-compact .chat-item .info,
      .sidebar.sidebar-compact .chat-item .msg-meta,
      .sidebar.sidebar-compact .chat-item .badge,
      .sidebar.sidebar-compact .chat-item .unread-badge,
      .sidebar.sidebar-compact .chat-item .sub,
      .sidebar.sidebar-compact .chat-item .name {
        display: none !important;
      }
      .sidebar.sidebar-compact .chat-item .av {
        margin: 0 !important;
      }
    }

    @media (min-width: 769px) {
      .main {
        min-width: 40% !important;
      }
    }

    /* Bot User Permissions List Responsiveness */
    #bot-users-permissions-list {
      container-type: inline-size;
    }

    .bot-perm-user-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px;
      background: var(--surface2);
      border-radius: 10px;
      border: 1px solid var(--border);
      gap: 16px;
    }

    .bot-perm-user-username {
      font-weight: 600;
      font-size: 13px;
      color: var(--text);
      flex: 1;
      min-width: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .bot-perm-user-toggles {
      display: flex;
      gap: 12px;
      align-items: center;
      flex-shrink: 0;
    }

    @container (max-width: 440px) {
      .bot-perm-user-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
      }
      .bot-perm-user-username {
        width: 100%;
        flex: none;
        min-width: auto;
        margin-bottom: 2px;
        white-space: normal;
        word-break: break-all;
      }
      .bot-perm-user-toggles {
        width: 100%;
        justify-content: space-between;
      }
    }

    /* Fallback media query for mobile screens */
    @media (max-width: 480px) {
      .bot-perm-user-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
      }
      .bot-perm-user-username {
        width: 100%;
        flex: none;
        min-width: auto;
        margin-bottom: 2px;
        white-space: normal;
        word-break: break-all;
      }
      .bot-perm-user-toggles {
        width: 100%;
        justify-content: space-between;
      }
    }

    /* Responsive adjustments for Pin Settings & TG Clients rename row */
    @media (max-width: 768px) {
      .settings-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
      }
      .settings-card-header button {
        width: 100% !important;
        justify-content: center !important;
      }
      .settings-tg-client-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
      }
      .settings-tg-client-row .settings-rename-group {
        width: 100% !important;
        justify-content: space-between !important;
      }
      .settings-tg-client-row .settings-rename-group input {
        flex: 1 !important;
        width: auto !important;
        max-width: none !important;
        max-height: none !important;
      }
    }

    /* ==========================================================================
       Media-Only & Media-With-Caption Messages (Telegram-Style Flush Layout)
       ========================================================================== */
    .bubble.media-only {
      background: transparent !important;
      border: none !important;
      padding: 0 !important;
      box-shadow: none !important;
      border-radius: 14px !important;
      position: relative;
      width: fit-content !important;
      max-width: min(380px, 65%) !important;
      display: inline-flex !important;
      flex-direction: column;
    }

    .msg-row.out .bubble.media-only {
      background: transparent !important;
      border-color: transparent !important;
    }

    .bubble.media-only .media-wrapper {
      border-radius: 14px;
      display: flex !important;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      position: relative;
      background: transparent !important;
      width: fit-content !important;
      max-width: 100% !important;
      min-width: 0 !important;
      min-height: 0 !important;
    }

    .bubble.media-only .media-img,
    .bubble.media-only .media-video {
      border-radius: 14px !important;
      width: auto !important;
      height: auto !important;
      max-width: min(380px, 100%) !important;
      max-height: 320px !important;
      display: block !important;
      object-fit: contain !important;
      background: transparent !important;
    }

    .bubble.media-only .msg-time {
      position: absolute;
      bottom: 8px;
      right: 8px;
      background: rgba(0, 0, 0, 0.45);
      color: rgba(255, 255, 255, 0.95);
      padding: 2px 8px;
      border-radius: 12px;
      font-size: 11px;
      font-weight: 500;
      backdrop-filter: blur(6px);
      -webkit-backdrop-filter: blur(6px);
      z-index: 5;
      margin: 0;
      pointer-events: none;
      display: flex;
      align-items: center;
      gap: 4px;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    }

    .bubble.media-only .msg-time span {
      color: rgba(255, 255, 255, 0.95) !important;
    }

    .bubble.media-only .msg-time .delivery-status svg {
      stroke: #fff !important;
      opacity: 0.95;
    }

    .bubble.media-only .sender-name {
      position: absolute;
      top: 8px;
      left: 8px;
      background: rgba(0, 0, 0, 0.45);
      color: #fff;
      padding: 2px 8px;
      border-radius: 8px;
      font-size: 11px;
      backdrop-filter: blur(4px);
      -webkit-backdrop-filter: blur(4px);
      z-index: 5;
      margin-bottom: 0;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    }

    /* Media With Caption Messages */
    .bubble.media-with-caption {
      padding: 0 !important;
      overflow: hidden !important;
      width: fit-content !important;
      max-width: min(440px, 68%) !important;
      border-radius: 14px !important;
      display: flex;
      flex-direction: column;
    }

    .bubble.media-with-caption .media-caption-sender {
      padding: 6px 12px 2px 12px;
      margin-bottom: 0;
    }

    .bubble.media-with-caption .media-wrapper {
      width: 100% !important;
      max-width: 100% !important;
      min-width: 220px;
      margin: 0 !important;
      padding: 0 !important;
      border-radius: 0 !important;
      background: #000;
      display: block;
      overflow: hidden;
    }

    .bubble.media-with-caption .media-img,
    .bubble.media-with-caption .media-video {
      width: 100% !important;
      max-width: 100% !important;
      max-height: 380px !important;
      border-radius: 0 !important;
      margin: 0 !important;
      display: block;
      object-fit: cover;
      background: #000;
    }

    .bubble.media-with-caption .bubble-caption-wrap {
      padding: 7px 12px 6px 12px;
      display: flex;
      flex-direction: column;
      gap: 3px;
      width: 100%;
      box-sizing: border-box;
    }

    .bubble.media-with-caption .bubble-caption-wrap .msg-text {
      font-size: 13.5px;
      line-height: 1.45;
      color: var(--text);
      word-break: break-word;
    }

    .bubble.media-with-caption .bubble-caption-wrap .msg-time {
      margin-top: 1px;
      font-size: 10.5px;
      color: var(--muted);
    }



    /* Context Menu */
    .chat-context-menu {
      position: fixed;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
      z-index: 1500;
      padding: 4px;
      min-width: 160px;
    }
    .chat-context-menu .dropdown-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 12px;
      border-radius: 6px;
      cursor: pointer;
      font-size: 13px;
      color: var(--text);
    }
    .chat-context-menu .dropdown-item:hover {
      background: var(--surface2);
    }
    .chat-context-menu .dropdown-item.disabled {
      opacity: 0.4;
      pointer-events: none;
    }

    .topic-unread-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--accent);
      flex-shrink: 0;
    }
    .topic-item.active .topic-unread-dot {
      background: #fff;
    }
    .btn-new-topic {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 6px 10px;
      border-radius: 6px;
      border: 1px dashed var(--border);
      background: transparent;
      color: var(--accent);
      font-size: 12px;
      cursor: pointer;
      margin-top: 4px;
    }
    .btn-new-topic:hover {
      background: var(--surface2);
    }

    /* Toast Notifications */
    #toast {
      position: fixed;
      bottom: 24px;
      right: 24px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px 20px;
      font-size: 13px;
      color: var(--text);
      opacity: 0;
      transform: translateY(10px);
      transition: all .2s;
      pointer-events: none;
      z-index: 1300;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    #toast.show {
      opacity: 1;
      transform: translateY(0);
    }
    #toast.success {
      border-color: rgba(34, 197, 94, 0.4) !important;
      color: var(--success) !important;
      background: rgba(34, 197, 94, 0.1) !important;
    }
    #toast.error {
      border-color: rgba(239, 68, 68, 0.4) !important;
      color: var(--danger) !important;
      background: rgba(239, 68, 68, 0.1) !important;
    }
    @media (max-width: 768px) {
      #toast {
        bottom: 80px !important;
        right: 16px !important;
        left: 16px !important;
        text-align: center;
      }
    }

    /* App-wide Loading Spinner Animation */
    .app-spinner {
      display: inline-block;
      width: 14px;
      height: 14px;
      border: 2px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: app-spin 0.6s linear infinite;
      vertical-align: middle;
    }
    .app-spinner-lg {
      width: 28px;
      height: 28px;
      border-width: 3px;
    }
    .app-spinner-sm {
      width: 11px;
      height: 11px;
      border-width: 1.5px;
    }
    @keyframes app-spin {
      to { transform: rotate(360deg); }
    }

    .search-input-wrapper {
      position: relative;
      display: flex;
      align-items: center;
      width: 100%;
    }
    .search-spinner {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      pointer-events: none;
      display: none;
    }
    .no-scrollbar {
      scrollbar-width: none !important;
      -ms-overflow-style: none !important;
    }
    .no-scrollbar::-webkit-scrollbar {
      display: none !important;
    }

    /* Background sync status + quick/deep search UI */
    .search-status {
      position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
      padding: 9px 16px; font-size: 11px; color: var(--text); background: var(--surface2);
      border-bottom: 1px solid var(--border);
    }
    .search-status .search-status-dot {
      width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
      animation: search-status-pulse 1s ease-in-out infinite;
    }
    .search-status.idle { color: var(--muted); background: var(--surface); }
    @keyframes search-status-pulse {
      0%, 100% { opacity: 0.25; transform: scale(0.8); }
      50% { opacity: 1; transform: scale(1.15); }
    }
    .sidebar-sync-status {
      position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 16px;
      font-size: 11px; color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--border);
      min-height: 33px; box-sizing: border-box;
    }
    .sidebar-sync-status .sync-dot {
      width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
      animation: search-status-pulse 1.4s ease-in-out infinite;
    }
    .sidebar-sync-status.done .sync-dot { animation: none; background: var(--success); }
    .sidebar-sync-status.paused .sync-dot {
      width: 9px; height: 10px; border-radius: 1px; background: transparent;
      border-left: 3px solid var(--muted); border-right: 3px solid var(--muted); animation: none;
    }
    .sync-help {
      order: 10; margin-left: 8px; display: inline-block; width: 14px; height: 14px; border-radius: 50%;
      border: 1px solid var(--border); color: var(--muted); font-size: 9px; line-height: 12px;
      text-align: center; cursor: help; flex-shrink: 0; user-select: none; position: relative;
    }
    .sync-help:hover { color: var(--text); border-color: var(--accent); }
    .sync-help::after {
      content: attr(data-tip); position: absolute; top: calc(100% + 8px); right: 0; width: 260px;
      padding: 10px 12px; background: var(--surface2); color: var(--text); border: 1px solid var(--border);
      border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); font-size: 11px; line-height: 1.45;
      text-align: left; white-space: normal; opacity: 0; visibility: hidden; transition: opacity 0.12s ease;
      z-index: 50; pointer-events: none;
    }
    .sync-help::before { content: ''; position: absolute; top: 100%; right: 0; width: 40px; height: 12px; opacity: 0; visibility: hidden; }
    .sync-help:hover::after, .sync-help:hover::before { opacity: 1; visibility: visible; }
    .sidebar-sync-status .sync-apply {
      order: 9; margin-left: 8px; background: var(--accent); color: #fff; border: none; border-radius: 6px;
      padding: 3px 10px; font-size: 11px; cursor: pointer; flex-shrink: 0;
    }
    .sidebar-sync-status .sync-apply:hover { filter: brightness(1.1); }
    .sync-warn {
      order: 8; margin-left: 0; width: 14px; height: 14px; border-radius: 50%; border: 1px solid #f59e0b;
      color: #f59e0b; font-size: 9px; font-weight: 700; line-height: 12px; text-align: center; cursor: help;
      flex-shrink: 0; position: relative;
    }
    .sync-warn + .sync-help { margin-left: 6px; }
    .sync-warn::after {
      content: attr(data-tip); position: absolute; top: calc(100% + 8px); right: -20px; width: 250px;
      padding: 10px 12px; background: var(--surface2); color: var(--text); border: 1px solid #f59e0b;
      border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); font-size: 11px; font-weight: 400;
      line-height: 1.45; text-align: left; white-space: normal; opacity: 0; visibility: hidden;
      transition: opacity 0.12s ease; z-index: 51; pointer-events: none;
    }
    .sync-warn:hover::after { opacity: 1; visibility: visible; }
    .search-input-wrapper .input { padding-right: 52px; }
    .search-clear {
      display: none;
      position: absolute; right: 29px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px;
      align-items: center; justify-content: center; border-radius: 50%; color: var(--muted); font-size: 10px;
      line-height: 1; cursor: pointer; user-select: none; z-index: 2; transition: background 0.12s, color 0.12s;
    }
    .search-clear:hover { background: var(--border); color: var(--text); }
    .search-hint { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); margin-left: 0; background: var(--surface); z-index: 2; }
    .search-hint::after { right: -6px; }
    #sidebar-sync-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .search-more {
      padding: 10px 16px; font-size: 11px; color: var(--accent); cursor: pointer; text-align: center;
      border-top: 1px solid var(--border); user-select: none;
    }
    .search-more:hover { background: var(--surface2); }

    /* Settings tab (sidebar): the account, its sessions and, for the owner, the workspace sections */
    .settings-panel { padding: 20px 16px 24px; display: flex; flex-direction: column; gap: 20px; }
    .settings-me { display: flex; align-items: center; gap: 14px; }
    .settings-me .av {
      width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff; display: flex;
      align-items: center; justify-content: center; font-size: 20px; font-weight: 700; flex-shrink: 0;
    }
    .settings-me-info { min-width: 0; }
    .settings-me-name { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
    .settings-me-login {
      font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .settings-me-status {
      font-size: 11.5px; color: var(--success); font-weight: 600; display: flex; align-items: center; gap: 6px; margin-top: 4px;
    }
    .settings-me-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
    .settings-group { display: flex; flex-direction: column; gap: 8px; }
    .settings-group-title {
      font-size: 11.5px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .5px;
      margin-bottom: 2px;
    }
    .settings-nav-item {
      display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border);
      border-radius: 10px; background: var(--surface2); cursor: pointer; transition: border-color .15s, background .15s;
    }
    .settings-nav-item:hover { border-color: var(--accent); }
    .settings-nav-item.active { border-color: var(--accent); background: rgba(79, 142, 247, .12); }
    .settings-nav-icon {
      width: 34px; height: 34px; border-radius: 9px; background: rgba(79, 142, 247, .15); color: var(--accent);
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .settings-nav-text { min-width: 0; }
    .settings-nav-name { font-size: 13px; font-weight: 600; }
    .settings-nav-hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
    .settings-info {
      background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
      font-size: 12.5px; display: flex; flex-direction: column; gap: 8px;
    }
    .settings-info b { color: var(--muted); font-weight: 600; }
    .settings-btn { width: 100%; padding: 8px 12px; font-size: 12px; border: 1px solid var(--border); border-radius: 8px; }
    .settings-btn.settings-btn-danger { border-color: var(--danger); color: var(--danger); }
    .settings-row { display: flex; gap: 10px; }
    .settings-row .settings-btn { flex: 1; }

    /* Workspace administration (Settings > Workspace), in the main area */
    .ws-content {
      flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 32px; display: flex; flex-direction: column;
      gap: 16px;
    }
    .ws-empty {
      color: var(--muted); font-size: 13px; text-align: center; padding: 28px 12px; display: flex;
      flex-direction: column; align-items: center; gap: 12px;
    }
    .ws-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
    .ws-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
    .ws-stat-val { font-size: 26px; font-weight: 700; }
    .ws-stat-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
    .ws-danger { color: var(--danger); }
    .ws-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
    .ws-card-head {
      display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px;
      border-bottom: 1px solid var(--border);
    }
    .ws-card-head h4 { font-size: 13px; font-weight: 600; }
    .ws-toolbar { display: flex; gap: 10px; align-items: center; }
    .ws-search { flex: 1; min-width: 0; }
    .ws-btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; white-space: nowrap; }
    .btn-ghost.ws-outline, .ws-row-actions .btn-ghost, .ws-card-head .btn-ghost, .ws-empty .btn-ghost { border-color: var(--border); }
    .btn-ghost.ws-danger-btn { color: var(--danger); }
    .ws-list {
      display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
      border-radius: 12px; overflow: hidden;
    }
    .ws-card .ws-list { border: none; border-radius: 0; }
    .ws-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
    .ws-row:last-child { border-bottom: none; }
    .ws-row .av {
      width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: flex;
      align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0;
    }
    .ws-row-main { flex: 1; min-width: 0; }
    .ws-row-title { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
    .ws-row-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ws-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; font-size: 11px; }
    .ws-chip { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; color: var(--text); }
    .ws-chip-more { color: var(--muted); cursor: help; }
    .ws-muted { color: var(--muted); font-style: italic; font-weight: 400; }
    .ws-badge {
      font-size: 10px; font-weight: 700; border-radius: 5px; padding: 1px 6px; text-transform: uppercase;
      letter-spacing: .3px; font-style: normal;
    }
    .ws-badge-owner { color: #f59e0b; background: rgba(245, 158, 11, .12); }
    .ws-badge-blocked { color: var(--danger); background: rgba(239, 68, 68, .12); }
    .ws-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

    /* Workspace dialogs */
    .modal.ws-modal { width: 480px; max-height: 90vh; overflow-y: auto; }
    .ws-hint { font-size: 11.5px; color: var(--muted); line-height: 1.45; margin-top: 6px; }
    .ws-hint b { color: var(--accent); font-weight: 600; }
    .ws-owner-note {
      background: rgba(245, 158, 11, .1); border: 1px solid rgba(245, 158, 11, .3); color: #f59e0b;
      border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.45; margin-bottom: 14px;
    }
    .ws-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
    .ws-check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
    /* the permission boxes sit in a .form-group, whose labels are small uppercase headings */
    .form-group .ws-check {
      display: flex; margin: 0; font-size: 13px; font-weight: 400; color: var(--text); text-transform: none;
      letter-spacing: normal;
    }
    .ws-check input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
    .ws-actions-end { display: flex; justify-content: flex-end; margin-top: 10px; }
    .ws-inline { display: flex; gap: 8px; align-items: center; }
    .ws-inline .input { flex: 1; min-width: 0; }
    .ws-inline-text .ws-hint { flex: 1; margin-top: 0; }
    .ws-mono { font-family: monospace; }
    #ws-user-token-usage { word-break: break-all; }
    .ws-choices {
      display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto;
      border: 1px solid var(--border); border-radius: 8px; padding: 10px;
    }

    @media (max-width: 600px) {
      .ws-content { padding: 16px 12px 24px; }
      .ws-row { flex-wrap: wrap; }
      .ws-row-actions { width: 100%; justify-content: flex-end; }
      .ws-checks { grid-template-columns: 1fr; }
    }
