/* ============================================================
   chatWS — base.css
   Design tokens (CSS custom properties) and global resets.
   Load FIRST — all other CSS files depend on these variables.
============================================================ */

/* ==========================================================
   chatWS — CLEAN RESPONSIVE DESIGN
   Mobile-first, progressively enhanced for desktop
   Load AFTER all other CSS files
========================================================== */

/* ==========================================================
   CSS CUSTOM PROPERTIES (Design Tokens)
========================================================== */
:root {
    /* Colors */
    --bg-primary: #050505;
    --bg-secondary: #0b0b0b;
    --bg-tertiary: #141414;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(255, 255, 255, 0.08);

    /* Text */
    --text-primary: #ffffff;
    --text-secondary: #e5e5e5;
    --text-muted: #a3a3a3;
    --text-disabled: #6b7280;

    /* Accents */
    --accent-blue: #b8964f;
    --accent-blue-hover: #957637;
    --accent-orange: #ff8a4a;
    --accent-danger: #dc2626;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.15);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;

    /* Sizing */
    --topbar-height: 56px;
    --topbar-height-mobile: 52px;
    --sidebar-width: 58px;
    --sidebar-width-mobile: 52px;
    --input-height: 44px;
    --input-height-mobile: 40px;

    /* Effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 999px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-medium: 0.25s ease;
    --transition-slow: 0.35s ease;

    /* Viewport fix */
    --vh: 1vh;
}

/* ==========================================================
   BASE STYLES (Mobile First)
========================================================== */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

#app {
    height: calc(var(--vh) * 100);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================
   TOP BAR
========================================================== */
.topbar {
    height: var(--topbar-height-mobile);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 100;
}

.brand {
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.top-user {
    display: none;
}

.top-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.top-avatar:hover {
    transform: scale(1.05);
}

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

/* ==========================================================
   MAIN LAYOUT
========================================================== */
.layout-shell {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ============ LEFT SIDEBAR ============ */
.side-left {
    width: var(--sidebar-width-mobile);
    min-width: var(--sidebar-width-mobile);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-sm) var(--space-xs);
    gap: var(--space-xs);
    flex-shrink: 0;
}

.side-left-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-orange), #ffc857);
    margin-bottom: var(--space-xs);
}

.side-left-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.side-left-btn:hover,
.side-left-btn.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.side-left-btn:active {
    transform: scale(0.92);
}

/* Notification badge */
.side-left-btn[data-badge]::after {
    content: attr(data-badge);
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--accent-danger);
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.side-left-spacer {
    flex: 1;
}

/* ==========================================================
   CHAT CENTER
========================================================== */
.chat-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
    position: relative;
}

/* Room Header */
.chat-header {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.room-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    cursor: pointer;
    border: 1px solid var(--border-subtle);
}

.room-title {
    flex: 1;
    min-width: 0;
}

.room-title h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-rank {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ==========================================================
   MESSAGES
========================================================== */
.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

/* Message row */
.message {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-start;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    overflow: hidden;
    background: var(--bg-tertiary);
    cursor: pointer;
}

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

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-xs);
    margin-bottom: 2px;
    flex-wrap: wrap;
}

.message-user {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

.message-rank {
    font-size: 10px;
    padding: 1px 5px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text a {
    color: var(--accent-blue);
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

/* System messages */
.message.system {
    justify-content: center;
    padding: var(--space-xs) var(--space-md);
}

.message.system .message-text {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 2px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ==========================================================
   INPUT BAR
========================================================== */
.chat-input {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-input input {
    flex: 1;
    min-width: 0;
    height: var(--input-height-mobile);
    padding: 0 var(--space-md);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-input input:focus {
    border-color: var(--accent-blue);
}

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

.chat-attach-btn,
.chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-attach-btn:hover,
.chat-send-btn:hover {
    background: var(--accent-blue);
    color: white;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

/* ==========================================================
   RIGHT PANEL (Overlay)
========================================================== */
.right-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 85vw;
    max-width: 380px;
    height: 100%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform var(--transition-medium);
    display: flex;
    flex-direction: column;
    z-index: 200;
}

.right-panel.open {
    transform: translateX(0);
}

.right-panel-header {
    height: var(--topbar-height-mobile);
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.right-panel-title {
    font-size: 15px;
    font-weight: 600;
}

.right-panel-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: background var(--transition-fast);
}

.right-panel-close:hover {
    background: var(--bg-hover);
}

.right-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
    -webkit-overflow-scrolling: touch;
}

/* Panel backdrop */
.panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.panel-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================
   ROOM LIST (Panel Content)
========================================================== */
.room-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.room-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    border: 1px solid transparent;
}

.room-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-subtle);
}

.room-item.active {
    background: rgba(41, 98, 255, 0.1);
    border-color: rgba(41, 98, 255, 0.3);
}

.room-item-image {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.room-item-info {
    flex: 1;
    min-width: 0;
}

.room-item-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-item-desc {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-item-count {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

/* Create room button */
.create-room-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-md);
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast);
    margin-bottom: var(--space-sm);
}

.create-room-btn:hover {
    background: var(--accent-blue-hover);
}

/* ==========================================================
   USER LIST
========================================================== */
.user-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.user-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-item:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    font-size: 14px;
}

.user-status {
    font-size: 12px;
    color: var(--text-muted);
}

.user-rank {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

/* ==========================================================
   FORMS (Panel Forms)
========================================================== */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: var(--space-xs);
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition-fast);
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent-blue);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.btn {
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-blue-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-block {
    width: 100%;
}

/* ==========================================================
   ELEMENT BOX (Modal)
========================================================== */
.element-box {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    padding: var(--space-md);
}

.element-box.visible {
    display: flex;
}

.element-box-inner {
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.element-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.element-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.element-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

.element-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.element-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    -webkit-overflow-scrolling: touch;
}

.element-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-sm);
}

/* ==========================================================
   PROFILE BOX
========================================================== */
.profileBox {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    padding: var(--space-md);
}

.profileBox.visible {
    display: flex;
}

.profileBoxInner {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.profileHeaderArea {
    position: relative;
    height: 120px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-orange));
}

.profileBanner {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profileAvatar {
    position: absolute;
    bottom: -30px;
    left: var(--space-lg);
    width: 80px;
    height: 80px;
    border-radius: var(--radius-md);
    border: 3px solid var(--bg-secondary);
    object-fit: cover;
    box-shadow: var(--shadow-md);
}

.profileContent {
    padding: var(--space-xl) var(--space-lg) var(--space-lg);
}

.profileName {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

.profileRank {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

.profileBio {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.profileActions {
    display: flex;
    gap: var(--space-sm);
    padding: 0 var(--space-lg) var(--space-lg);
}

/* ==========================================================
   PM BOX
========================================================== */
#pmBox {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    width: min(380px, calc(100vw - var(--space-lg) * 2));
    max-height: 60vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-subtle);
    display: none;
    flex-direction: column;
    z-index: 500;
    overflow: hidden;
}

#pmBox.visible {
    display: flex;
}

.pmHeader {
    height: 48px;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
    cursor: grab;
}

.pmHeader:active {
    cursor: grabbing;
}

.pmTitle {
    font-weight: 600;
    font-size: 14px;
}

.pmMessages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-height: 200px;
    max-height: 400px;
}

.pmInputBar {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm);
    border-top: 1px solid var(--border-subtle);
}

.pmInputBar input {
    flex: 1;
    height: 36px;
    padding: 0 var(--space-sm);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.pmInputBar button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent-blue);
    color: white;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.pmInputBar button:hover {
    background: var(--accent-blue-hover);
}

/* ==========================================================
   DESKTOP STYLES (768px and up)
========================================================== */
