  :root {
    --primary: #0078d4; --primary-hover: #106ebe; --primary-dark: #005a9e;
    --bg: #f3f2f1; --sidebar-bg: #faf9f8; --panel-bg: #ffffff;
    --border: #e1dfdd; --border-light: #edebe9;
    --text-primary: #252423; --text-secondary: #605e5c; --text-muted: #a19f9d;
    --online: #92c353; --away: #f8d22a; --offline: #a19f9d;
    --danger: #d13438; --success: #107c10;
    --msg-self: #e3f2fd; --msg-other: #ffffff;
    --shadow: 0 1.6px 3.6px rgba(0,0,0,.132), 0 .3px .9px rgba(0,0,0,.108);
    --shadow-md: 0 3.2px 7.2px rgba(0,0,0,.132), 0 .6px 1.8px rgba(0,0,0,.108);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 14px; background: var(--bg); color: var(--text-primary); height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .titlebar { padding-top: env(safe-area-inset-top); }
  .status-bar { padding-bottom: env(safe-area-inset-bottom); }

  /* LOGIN */
  #login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
  .login-card { background: var(--panel-bg); border: 1px solid var(--border); box-shadow: var(--shadow-md); padding: 40px 48px; width: 400px; border-radius: 2px; }
  .login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
  .login-logo-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 4px; display: flex; align-items: center; justify-content: center; color: white; font-size: 18px; }
  .login-logo-text { font-size: 20px; font-weight: 600; }
  .login-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
  .login-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }

  /* FORMS */
  .form-field { margin-bottom: 16px; }
  .form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
  .form-label .req { color: var(--danger); }
  .form-input, .form-select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 2px; font-size: 14px; font-family: inherit; outline: none; background: white; transition: border-color .15s; }
  .form-input:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
  .form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

  /* BUTTONS */
  .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 16px; border: 1px solid transparent; border-radius: 2px; font-size: 14px; font-family: inherit; cursor: pointer; transition: all .1s; white-space: nowrap; }
  .btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
  .btn-primary:hover { background: var(--primary-hover); }
  .btn-secondary { background: white; color: var(--text-primary); border-color: var(--border); }
  .btn-secondary:hover { background: var(--bg); }
  .btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
  .btn-full { width: 100%; }
  .btn-sm { padding: 4px 10px; font-size: 12px; }

  /* ALERTS */
  .alert { padding: 8px 12px; border-radius: 2px; font-size: 13px; margin-bottom: 12px; display: none; }
  .alert.show { display: block; }
  .alert-error { background: #fde7e9; border: 1px solid #f4b8bc; color: var(--danger); }
  .alert-warn { background: #fff4ce; border: 1px solid #f8d22a; color: #7a5c00; }
  .alert-success { background: #dff6dd; border: 1px solid #92c353; color: var(--success); }

  /* FAKE GOOGLE */
  #fake-google { display: none; position: fixed; inset: 0; z-index: 9999; background: white; flex-direction: column; align-items: center; justify-content: center; }
  #fake-google.show { display: flex; }
  .g-logo { font-size: 72px; font-weight: 700; letter-spacing: -2px; margin-bottom: 24px; }
  .g-logo span:nth-child(1){color:#4285f4}.g-logo span:nth-child(2){color:#ea4335}.g-logo span:nth-child(3){color:#fbbc05}.g-logo span:nth-child(4){color:#4285f4}.g-logo span:nth-child(5){color:#34a853}.g-logo span:nth-child(6){color:#ea4335}
  .g-search { display: flex; align-items: center; border: 1px solid #dfe1e5; border-radius: 24px; padding: 10px 20px; width: 560px; gap: 12px; box-shadow: 0 1px 6px rgba(32,33,36,.28); }
  .g-search input { flex: 1; border: none; outline: none; font-size: 16px; font-family: arial,sans-serif; }
  .g-btns { display: flex; gap: 12px; margin-top: 28px; }
  .g-btn { background: #f8f9fa; border: 1px solid #f8f9fa; color: #3c4043; padding: 9px 23px; border-radius: 4px; font-size: 14px; cursor: default; }
  .g-btn:hover { border-color: #dadce0; }

  /* APP */
  #app { display: none; flex-direction: column; height: 100vh; }
  #app.show { display: flex; }

  /* TITLEBAR */
  .titlebar { background: var(--primary); color: white; height: 48px; display: flex; align-items: center; padding: 0 16px; gap: 8px; flex-shrink: 0; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
  .tb-logo { width: 24px; height: 24px; background: rgba(255,255,255,.2); border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
  .tb-title { font-size: 15px; font-weight: 600; flex: 1; }
  .tb-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
  .tb-avatar { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.3); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
  .tb-btn { background: rgba(255,255,255,.1); border: none; color: white; padding: 5px 10px; border-radius: 2px; font-size: 12px; font-family: inherit; cursor: pointer; }
  .tb-btn:hover { background: rgba(255,255,255,.2); }
  .tb-select { appearance: none; -webkit-appearance: none; max-width: 160px; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, white 50%), linear-gradient(135deg, white 50%, transparent 50%); background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 22px; }
  .tb-more { position: relative; display: none; }
  .tb-more-menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 160px; background: white; border: 1px solid var(--border); border-radius: 2px; box-shadow: var(--shadow-md); z-index: 800; padding: 4px 0; }
  .tb-more-item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: none; background: none; font-size: 13px; font-family: inherit; cursor: pointer; color: var(--text-primary); }
  .tb-more-item:hover { background: var(--bg); }
  .status-dd { position: fixed; min-width: 200px; background: white; border: 1px solid var(--border); border-radius: 2px; box-shadow: var(--shadow-md); z-index: 1200; padding: 4px 0; }
  .status-dd-item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: none; background: none; font-size: 13px; font-family: inherit; cursor: pointer; color: var(--text-primary); }
  .status-dd-item:hover { background: var(--bg); }
  .tb-sep { width: 1px; height: 20px; background: rgba(255,255,255,.2); }

  /* LAYOUT */
  .main-layout { display: flex; flex: 1; overflow: hidden; }

  /* SIDEBAR */
  .sidebar { width: 260px; background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
  .sb-tabs { display: flex; border-bottom: 1px solid var(--border); }
  .sb-tab { flex: 1; padding: 10px; border: none; background: none; font-size: 12px; font-family: inherit; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; }
  .sb-tab:hover { color: var(--text-primary); background: var(--border-light); }
  .sb-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
  .sb-search { padding: 8px 10px; border-bottom: 1px solid var(--border-light); }
  .sb-search input { width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 2px; font-size: 13px; font-family: inherit; outline: none; }
  .sb-search input:focus { border-color: var(--primary); }
  .sb-list { flex: 1; overflow-y: auto; }
  .sb-bottom { border-top: 1px solid var(--border); padding: 8px 10px; }

  /* CONTACT ITEMS */
  .c-item { display: flex; align-items: center; gap: 10px; padding: 7px 14px; cursor: pointer; transition: background .1s; }
  .c-item:hover { background: var(--border-light); }
  .c-item.active { background: #deecf9; }
  .c-av { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: white; flex-shrink: 0; position: relative; }
  .s-dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--sidebar-bg); position: absolute; bottom: 0; right: 0; }
  .s-online{background:var(--online)}.s-away{background:var(--away)}.s-offline{background:var(--offline)}.s-unavailable{background:var(--danger)}
  .c-info { flex: 1; min-width: 0; }
  .c-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-prev { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-badge { background: var(--primary); color: white; border-radius: 10px; font-size: 10px; font-weight: 600; padding: 1px 6px; }

  /* CHAT */
  .chat-area { flex: 1; display: flex; flex-direction: column; background: var(--panel-bg); overflow: hidden; }
  .chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 12px; }
  .chat-header { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; box-shadow: var(--shadow); }
  .ch-av { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; color: white; flex-shrink: 0; }
  .ch-info { flex: 1; }
  .ch-name { font-size: 15px; font-weight: 600; }
  .ch-status { font-size: 12px; color: var(--text-secondary); }
  .chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
  .msg-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
  .msg-group.self { align-items: flex-end; }
  .msg-group.other { align-items: flex-start; }
  .msg-sender { font-size: 11px; color: var(--text-secondary); padding: 0 10px; font-weight: 500; }
  .msg-bubble { max-width: 65%; padding: 8px 12px; border-radius: 4px; font-size: 14px; line-height: 1.5; word-break: break-word; }
  .msg-group.self .msg-bubble { background: var(--msg-self); border: 1px solid #bbdefb; }
  .msg-group.other .msg-bubble { background: var(--msg-other); border: 1px solid var(--border); box-shadow: var(--shadow); }
  .msg-time { font-size: 10px; color: var(--text-muted); padding: 0 10px; }
  .msg-date-sep { text-align: center; font-size: 11px; color: var(--text-muted); margin: 12px 0; display: flex; align-items: center; gap: 8px; }
  .msg-date-sep::before,.msg-date-sep::after { content:''; flex:1; border-top: 1px solid var(--border); }
  .msg-bubble a { color: var(--primary); text-decoration: underline; }

  /* TYPING */
  .typing-ind { display: flex; align-items: center; gap: 4px; padding: 4px 16px; font-size: 12px; color: var(--text-muted); font-style: italic; min-height: 22px; }
  .t-dots { display: flex; gap: 3px; }
  .t-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: tb 1.2s infinite; }
  .t-dot:nth-child(2){animation-delay:.2s}.t-dot:nth-child(3){animation-delay:.4s}
  @keyframes tb{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}

  /* INPUT */
  .chat-input-area { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
  .input-box { border: 1px solid var(--border); border-radius: 3px; overflow: visible; }
  .input-box:focus-within { border-color: var(--primary); }
  .input-toolbar { display: flex; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--border-light); background: var(--bg); overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .t-btn { background: none; border: none; padding: 3px 6px; border-radius: 2px; cursor: pointer; font-size: 14px; color: var(--text-secondary); position: relative; }
  .t-btn:hover { background: var(--border); }
  .input-row { display: flex; align-items: flex-end; gap: 8px; padding: 8px; }
  .chat-input { flex: 1; border: none; outline: none; font-size: 14px; font-family: inherit; resize: none; max-height: 120px; min-height: 24px; line-height: 1.5; background: transparent; }
  .send-btn { background: var(--primary); color: white; border: none; border-radius: 2px; padding: 6px 12px; font-size: 13px; font-family: inherit; cursor: pointer; font-weight: 500; flex-shrink: 0; }
  .send-btn:hover { background: var(--primary-hover); }

  /* EMOJI */
  .emoji-picker { display: none; position: fixed; background: white; border: 1px solid var(--border); border-radius: 4px; box-shadow: var(--shadow-md); padding: 8px; width: 280px; z-index: 9999; }
  .emoji-picker.show { display: block; }
  .emoji-grid { display: grid; grid-template-columns: repeat(8,1fr); gap: 2px; }
  .emoji-btn { background: none; border: none; font-size: 20px; padding: 4px; border-radius: 3px; cursor: pointer; }
  .emoji-btn:hover { background: var(--bg); }

  /* STATUS BAR */
  .status-bar { height: 24px; background: var(--bg); border-top: 1px solid var(--border); display: flex; align-items: center; padding: 0 12px; gap: 16px; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
  .svc-ind { display: flex; align-items: center; gap: 4px; }
  .svc-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); }
  .svc-dot.error { background: var(--danger); }
  .svc-dot.warn { background: var(--away); }
  .mute-toggle { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; padding: 2px 6px; border-radius: 12px; border: 1px solid var(--border); background: white; font-size: 11px; color: var(--text-secondary); }

  /* MODAL */
  .modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1000; align-items: center; justify-content: center; }
  .modal-overlay.show { display: flex; }
  .modal { background: white; border-radius: 2px; box-shadow: var(--shadow-md); width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
  .modal-sm { width: 360px; }
  .modal-lg { width: 640px; }
  .modal-header { padding: 16px 20px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: white; z-index: 1; }
  .modal-title { font-size: 16px; font-weight: 600; }
  .modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); padding: 2px 6px; border-radius: 2px; }
  .modal-close:hover { background: var(--bg); }
  .modal-body { padding: 20px; }
  .modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: white; }

  /* ADMIN TABLE */
  .u-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .u-table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; }
  .u-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
  .u-table tr:hover td { background: var(--bg); }
  .u-inactive td { opacity: .5; }
  .admin-tabs { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
  .admin-tab { padding: 8px 12px; border: none; background: none; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit; }
  .admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
  .ws-admin-name { font-weight: 600; }
  .ws-admin-meta { font-size: 12px; color: var(--text-secondary); }
  .badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
  .b-master { background: #e9d7f7; color: #5c2e91; }
  .b-user { background: #dff6dd; color: var(--success); }
  .b-off { background: var(--border); color: var(--text-muted); }

  /* MEMBER LIST */
  .member-list { max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 2px; }
  .member-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; }
  .member-item:hover { background: var(--bg); }
  .member-item label { cursor: pointer; font-size: 13px; }

  /* AVATAR COLORS */
  .av-blue{background:#0078d4}.av-teal{background:#038387}.av-green{background:#107c10}.av-orange{background:#ca5010}.av-red{background:#d13438}.av-purple{background:#5c2e91}.av-pink{background:#bf0077}.av-darkblue{background:#003966}
  .group-icon { background: #5c2e91 !important; border-radius: 4px !important; }

  ::-webkit-scrollbar{width:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--border);border-radius:3px}::-webkit-scrollbar-thumb:hover{background:var(--text-muted)}

  /* MOBILE */
  @media (max-width: 768px) {
    body { font-size: 15px; height: 100dvh; }
    .login-card { width: 100%; max-width: 100%; margin: 12px; padding: 24px 20px; box-sizing: border-box; }
    .titlebar { padding: 0 10px; gap: 4px; min-height: 48px; padding-left: 48px; position: relative; }
    .tb-title { font-size: 14px; }
    .tb-user span { display: none; }
    .tb-btn { padding: 8px 10px; min-height: 44px; font-size: 11px; }
    .tb-select { min-height: 44px; max-width: 130px; font-size: 11px; }
    .tb-sep { display: none; }
    #btn-status { padding: 8px 6px; }
    #btn-mypwd, #btn-admin { display: none !important; }
    .tb-more { display: block; }
    .main-layout { position: relative; flex: 1; min-height: 0; }
    .main-layout:not(.mobile-chat-on) .chat-area { display: none !important; }
    .main-layout.mobile-chat-on .sidebar { display: none !important; }
    .main-layout.mobile-chat-on .chat-area { display: flex !important; flex: 1; flex-direction: column; min-height: 0; }
    .sidebar { position: relative; width: 100vw; max-width: 100vw; transform: none; z-index: 1; flex: 1; min-height: 0; padding-top: 0; box-shadow: none; }
    .sidebar.open { transform: none; }
    .sidebar-overlay { display: none !important; }
    .chat-area { min-width: 0; }
    .chat-header { padding: 10px 12px; gap: 8px; }
    .chat-header .btn { min-height: 40px; padding: 8px 10px; }
    .msg-bubble { max-width: 85%; padding: 10px 14px; font-size: 15px; }
    .chat-input-area { padding: 10px 12px; }
    .input-row { padding: 10px; }
    .chat-input { font-size: 16px; min-height: 44px; }
    .send-btn { min-height: 44px; padding: 10px 16px; }
    .t-btn { min-width: 44px; min-height: 44px; padding: 10px; font-size: 18px; }
    .modal { width: 95vw; max-height: 85vh; margin: 10px; }
    .modal-sm { width: 95vw; }
    .modal-lg { width: 95vw; }
    .status-bar { font-size: 10px; padding: 0 8px; gap: 8px; }
    #active-svc { display: none; }
    #btn-toggle-sidebar { display: none !important; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); min-width: 40px; min-height: 40px; align-items: center; justify-content: center; z-index: 2; }
    .main-layout.mobile-chat-on #btn-toggle-sidebar { display: flex !important; }
    #btn-back-list { display: flex !important; min-height: 40px; padding: 8px 12px; }
    #btn-back-list .btn-label { display: inline; }
  }
  @media (min-width: 769px) {
    #btn-toggle-sidebar { display: none !important; }
    #btn-back-list { display: none !important; }
    .tb-more { display: none !important; }
  }
