/* Globally disable visual scrollbars across all browsers */
* { box-sizing: border-box; margin: 0; padding: 0; scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { display: none; }

body, html { 
    width: 100%; height: 100%; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background-color: #0d1117; background-image: url('../backgrounds/bg1.jpg');
    background-size: cover; background-position: center; background-attachment: fixed;
    background-repeat: no-repeat; color: #c9d1d9; overflow: hidden; 
}
canvas { position: fixed; top: 0; left: 0; z-index: 1; width: 100vw; height: 100vh; pointer-events: none; }

.active-view { display: flex !important; }
.hidden-view, .hidden { display: none !important; }

#door-container { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10;
}
.door-box { background: rgba(22, 27, 34, 0.85); padding: 40px; border-radius: 15px; border: 1px solid #30363d; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.door-box h1 { margin-bottom: 20px; font-size: 1.5rem; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.8); }
input[type="text"], input[type="email"], input[type="password"] { padding: 12px; border-radius: 6px; border: 1px solid #30363d; background: #0d1117; color: #fff; margin-bottom: 10px; width: 100%; font-size: 1rem; }
button { padding: 12px 24px; border: none; border-radius: 6px; background: #58a6ff; color: #0d1117; font-weight: bold; cursor: pointer; transition: background 0.2s; width: 100%; font-size: 1rem; }
button:hover { background: #79c0ff; }
.error-text { color: #f85149; margin-top: 10px; font-size: 0.9rem; }

/* 1000px Max Height Constraint & Perfect Centering */
#dashboard-container { 
    position: fixed; 
    top: 50%; left: 50%; transform: translate(-50%, -50%); 
    width: 100vw; height: 100vh; 
    max-width: 1200px; max-height: 1000px; 
    padding: 20px; display: flex; flex-direction: column; overflow: hidden; z-index: 10;
}

header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid #30363d; margin-bottom: 20px; background: rgba(22, 27, 34, 0.85); border-radius: 10px; backdrop-filter: blur(4px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); flex-shrink: 0; }
.room-heading { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-width: 0; }
header h1 { color: #58a6ff; text-shadow: 0 2px 4px rgba(0,0,0,0.8); line-height: 1.05; }
.room-sub-link { width: fit-content; margin-left: 2px; color: #c1c1c1; font-size: 13px; line-height: 1.2; font-weight: 600; text-decoration: none; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.room-sub-link:hover { color: #ffffff; text-decoration: none; }
header button { width: auto; background: #21262d; color: #c9d1d9; border: 1px solid #30363d; }
header button:hover { background: #30363d; }

.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; flex: 1; min-height: 0; overflow: hidden; }
@media(max-width: 768px) { .content-grid { grid-template-columns: 1fr; overflow-y: auto; } }

/* Columns and Panels become flexible containers to trap scrollable elements */
.column { display: flex; flex-direction: column; gap: 20px; min-height: 0; flex: 1; }
.panel { background: rgba(22, 27, 34, 0.85); border: 1px solid #30363d; border-radius: 10px; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); backdrop-filter: blur(4px); flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel h2 { margin-bottom: 15px; font-size: 1.2rem; border-bottom: 1px solid #30363d; padding-bottom: 10px; flex-shrink: 0; }

/* Scrollable News Grid */
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); grid-auto-rows: max-content; gap: 15px; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; align-content: start; align-items: start; }
.news-card { background: #161b22; border: 1px solid #30363d; border-radius: 8px; overflow: hidden; cursor: pointer; transition: transform 0.2s, border-color 0.2s; display: flex; flex-direction: column; box-shadow: 0 4px 6px rgba(0,0,0,0.3); min-width: 0; align-self: start; }
.news-card:hover { transform: translateY(-3px); border-color: #58a6ff; }
.news-card.active { border-color: #ff69b4; box-shadow: 0 0 10px rgba(255,105,180,0.4); }
.news-thumb { height: 90px; min-height: 90px; width: 100%; background: #000; object-fit: cover; flex: 0 0 90px; }
.news-text-break { grid-column: 1 / -1; background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 18px 20px; color: #c9d1d9; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 4px 6px rgba(0,0,0,0.2); align-self: start; }
.news-caption { padding: 10px; min-height: 36px; font-size: 0.85rem; color: #c9d1d9; text-align: center; white-space: nowrap; overflow: hidden; font-weight: bold; display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; flex: 0 0 auto; }
.news-caption-type { flex: 0 0 auto; font-size: 0.8rem; line-height: 1; }
.news-caption-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Scrollable Chat Panel */
.chat-panel { flex: 1; min-height: 0; }
.chat-input-area { display: flex; gap: 10px; margin-bottom: 20px; flex-shrink: 0; }
.chat-input-area input { margin-bottom: 0; flex: 1; }
.chat-input-area button { width: auto; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; display: flex; flex-direction: column; gap: 15px; padding-right: 5px; }
.message { display: flex; flex-direction: column; max-width: 80%; flex-shrink: 0; }
.message.self { align-self: flex-end; }
.message.other { align-self: flex-start; }
.message .meta { font-size: 0.8rem; color: #8b949e; margin-bottom: 4px; padding: 0 10px; }
.message.self .meta { text-align: right; }
.message .bubble { padding: 12px 16px; border-radius: 18px; line-height: 1.4; word-wrap: break-word; }
.message.self .bubble { background: #238636; color: #fff; border-bottom-right-radius: 4px; }
.message.other .bubble { background: #21262d; border: 1px solid #30363d; color: #c9d1d9; border-bottom-left-radius: 4px; }

.modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.8); z-index: 100; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-content { background: #161b22; padding: 40px; border-radius: 15px; border: 1px solid #30363d; width: 90%; max-width: 400px; text-align: center; }
.modal-content h2 { margin-bottom: 10px; }
.modal-content p { color: #8b949e; font-size: 0.9rem; margin-bottom: 20px; }
.modal-content .forgot-link { margin-top: 15px; margin-bottom: 20px; font-size: 0.85rem; }
.modal-content a { color: #58a6ff; text-decoration: none; }

#mascot { position: fixed !important; bottom: -60px !important; right: -60px !important; left: auto !important; width: 250px; height: auto; z-index: 9999; transform: rotate(-45deg); filter: drop-shadow(-4px 4px 10px rgba(0,0,0,0.8)); transition: all 0.3s ease; pointer-events: auto; }
#mascot:hover { bottom: -40px !important; right: -40px !important; transform: rotate(-35deg) scale(1.05); cursor: pointer; }

/* Independent, scrollbar-free room columns */
.column {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.column::-webkit-scrollbar,
.news-grid::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.admin-tab-panel::-webkit-scrollbar,
.admin-content-list::-webkit-scrollbar,
.admin-content-order-list::-webkit-scrollbar,
.admin-user-table-wrap::-webkit-scrollbar {
    display: none;
}

/* News preview floats above the feed so opening media never changes feed scroll position. */
.news-panel { overflow: hidden; }
.news-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #30363d;
    padding-bottom: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
}
.news-panel-header h2 {
    margin: 0;
    padding: 0;
    border: none;
}
.news-hide-media {
    width: 118px;
    flex: 0 0 118px;
    box-sizing: border-box;
    white-space: nowrap;
    padding: 6px 8px;
    border: 1px solid rgba(121, 192, 255, 0.82);
    background: rgba(33, 38, 45, 0.94);
    color: #d9f2ff;
    font-size: 0.78rem;
    display: grid;
    grid-template-columns: 14px 1fr;
    align-items: center;
    justify-items: center;
    column-gap: 3px;
    box-shadow: 0 0 10px rgba(88, 166, 255, 0.28), inset 0 0 8px rgba(121, 192, 255, 0.08);
}
.news-hide-media:hover {
    background: #30363d;
    border-color: #c5e8ff;
    box-shadow: 0 0 14px rgba(121, 192, 255, 0.48), inset 0 0 8px rgba(121, 192, 255, 0.12);
}
.news-hide-media-x {
    display: inline-block;
    width: 14px;
    color: #c9efff;
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1;
    transform-origin: center;
    animation: frost-hide-x-breathe 1.55s ease-in-out infinite;
}
@keyframes frost-hide-x-breathe {
    0%, 100% {
        opacity: 0;
        transform: scale(0.55);
        text-shadow: 0 0 0 rgba(168, 220, 255, 0);
    }
    45%, 55% {
        opacity: 1;
        transform: scale(1.28);
        color: #ffffff;
        text-shadow: 0 0 5px rgba(210, 242, 255, 1), 0 0 12px rgba(88, 166, 255, 0.95);
    }
}
.news-content-area { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.news-content-area .news-grid { height: 100%; min-height: 0; padding-right: 2px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; }
.main-display-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    padding: 10px;
    border: 1px solid rgba(88, 166, 255, 0.35);
    border-radius: 10px;
    background: rgba(13, 17, 23, 0.68);
    box-shadow: 0 10px 30px rgba(0,0,0,0.55);
    backdrop-filter: blur(9px);
    -webkit-backdrop-filter: blur(9px);
}
.main-display-overlay img,
.main-display-overlay video {
    display: block;
    width: 100%;
    max-height: min(48vh, 430px);
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Second-stage full-browser image viewer. */
.main-display-overlay .news-preview-image {
    cursor: zoom-in;
}
.main-display-overlay .news-preview-image:focus-visible {
    outline: 2px solid #79c0ff;
    outline-offset: 3px;
}
.news-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(2, 6, 15, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.news-lightbox-image {
    display: block;
    width: auto;
    height: auto;
    max-width: calc(100vw - 56px);
    max-height: calc(100vh - 56px);
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid rgba(121, 192, 255, 0.42);
    background: #000;
    box-shadow: 0 14px 55px rgba(0,0,0,0.72), 0 0 28px rgba(88,166,255,0.15);
}
.news-lightbox-close {
    position: fixed;
    top: 18px;
    right: 22px;
    z-index: 12001;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(168, 220, 255, 0.65);
    background: rgba(13, 17, 23, 0.86);
    color: #e7f7ff;
    font-size: 2rem;
    font-weight: 400;
    line-height: 44px;
    box-shadow: 0 0 16px rgba(88,166,255,0.28);
}
.news-lightbox-close:hover {
    background: rgba(48, 54, 61, 0.95);
    color: #fff;
    box-shadow: 0 0 20px rgba(121,192,255,0.55);
}

@media (prefers-reduced-motion: reduce) {
    .news-hide-media-x { animation: none; opacity: 1; transform: none; }
}

/* Admin dashboard: fixed tabs with independently scrollable tab content. */
#admin-grid {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
}
.admin-panel {
    overflow: hidden;
    flex: 1;
}
.admin-dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid #30363d;
    padding-bottom: 12px;
    margin-bottom: 10px;
    flex-shrink: 0;
}
.admin-dashboard-header h2 { margin: 0; padding: 0; border: none; }
.admin-tabs {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-bottom: 14px;
}
.admin-tab-btn {
    width: auto;
    min-width: 105px;
    padding: 9px 18px;
    background: #161b22;
    color: #8b949e;
    border: 1px solid #30363d;
    border-radius: 7px;
}
.admin-tab-btn:hover { background: #21262d; color: #c9d1d9; }
.admin-tab-btn.active {
    background: #21262d;
    color: #fff;
    border-color: #58a6ff;
    box-shadow: inset 0 -2px 0 #58a6ff;
}
.admin-tab-panels {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.admin-tab-panel {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-right: 2px;
}
.admin-section {
    background: rgba(13, 17, 23, 0.46);
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 18px;
}
.admin-section:last-child { margin-bottom: 0; }
.admin-section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 14px;
}
.admin-section-heading h3 { color: #fff; margin-bottom: 4px; }
.admin-section-heading p { color: #8b949e; font-size: 0.86rem; line-height: 1.4; }
.admin-user-setting {
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
    padding-bottom: 2px;
}
.admin-room-picker { color: #c9d1d9; font-size: 0.85rem; min-width: 160px; }
.admin-room-picker select {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 9px 10px;
    border-radius: 6px;
    border: 1px solid #30363d;
    background: #0d1117;
    color: #fff;
}
.admin-content-status {
    margin: 0 0 12px;
    padding: 9px 11px;
    border-radius: 6px;
    background: rgba(35, 134, 54, 0.16);
    border: 1px solid rgba(35, 134, 54, 0.45);
    color: #9be9a8;
    font-size: 0.85rem;
}
.admin-content-status.error {
    background: rgba(248, 81, 73, 0.12);
    border-color: rgba(248, 81, 73, 0.45);
    color: #ff9b96;
}
.admin-content-columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}
.admin-content-box {
    min-width: 0;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 12px;
}
.admin-content-box h4 { color: #fff; margin-bottom: 10px; }
.admin-content-box input[type="file"] {
    display: block;
    width: 100%;
    color: #8b949e;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.admin-content-box input[type="file"]::file-selector-button {
    border: 1px solid #30363d;
    border-radius: 5px;
    background: #21262d;
    color: #c9d1d9;
    padding: 6px 9px;
    margin-right: 8px;
    cursor: pointer;
}
.admin-content-box textarea {
    width: 100%;
    resize: vertical;
    min-height: 105px;
    max-height: 240px;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 6px;
    border: 1px solid #30363d;
    background: #0d1117;
    color: #fff;
    font: inherit;
    line-height: 1.4;
}
.admin-content-box button { padding: 9px 12px; font-size: 0.86rem; }
.admin-content-list {
    max-height: 235px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-top: 11px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.admin-content-empty { color: #6e7681; font-size: 0.82rem; padding: 8px 2px; }
.admin-content-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px;
    border: 1px solid #30363d;
    border-radius: 6px;
    background: #0d1117;
}
.admin-content-item-info { min-width: 0; flex: 1; }
.admin-content-item-name {
    display: block;
    color: #c9d1d9;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.admin-content-item-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-wrap;
    color: #c9d1d9;
    font-size: 0.8rem;
    line-height: 1.35;
}
.admin-content-item-time { display: block; color: #6e7681; font-size: 0.7rem; margin-top: 3px; }
.admin-content-remove {
    flex: 0 0 auto;
    width: auto;
    padding: 5px 8px !important;
    font-size: 0.72rem !important;
    background: #6e1b1b;
    color: #fff;
}
.admin-content-remove:hover { background: #9b2c2c; }

/* Unified room-content ordering */
.admin-order-heading { align-items: center; }
.admin-save-order-btn {
    width: auto;
    min-width: 110px;
    flex: 0 0 auto;
    padding: 9px 14px;
}
.admin-save-order-btn:disabled {
    cursor: default;
    opacity: 0.45;
    background: #21262d;
    color: #8b949e;
}
.admin-content-order-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 330px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.admin-order-item {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid #30363d;
    border-radius: 7px;
    background: #0d1117;
    transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}
.admin-order-item.dragging { opacity: 0.45; }
.admin-order-item.drag-over {
    border-color: #58a6ff;
    background: #161b22;
}
.admin-order-handle {
    color: #6e7681;
    font-size: 1.3rem;
    line-height: 1;
    cursor: grab;
    user-select: none;
}
.admin-order-item:active .admin-order-handle { cursor: grabbing; }
.admin-order-type { font-size: 0.95rem; }
.admin-order-info { min-width: 0; }
.admin-order-name {
    display: block;
    color: #c9d1d9;
    font-size: 0.86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.admin-order-meta {
    display: block;
    margin-top: 2px;
    color: #6e7681;
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.admin-order-controls { display: flex; gap: 5px; }
.admin-order-move {
    width: 32px;
    height: 30px;
    padding: 0;
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
    font-size: 1rem;
    line-height: 1;
}
.admin-order-move:hover:not(:disabled) { background: #30363d; }
.admin-order-move:disabled { opacity: 0.3; cursor: default; }

.admin-search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #30363d;
    background: #0d1117;
    color: #fff;
    margin-bottom: 15px !important;
}
.admin-user-table-wrap {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.admin-user-table { width: 100%; color: #c9d1d9; border-collapse: collapse; text-align: left; min-width: 760px; }
.admin-user-table th { padding: 10px; border-bottom: 1px solid #30363d; }
.admin-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
    border-top: 1px solid #30363d;
    padding-top: 15px;
}
.admin-pagination button {
    width: auto;
    padding: 8px 16px;
    background: #21262d;
    border: 1px solid #30363d;
    color: #c9d1d9;
}
.admin-pagination span { color: #8b949e; font-size: 0.9rem; text-align: center; }

@media(max-width: 900px) {
    .admin-content-columns { grid-template-columns: 1fr; }
    .admin-content-list { max-height: 180px; }
}

@media(max-width: 768px) {
    .admin-section-heading { align-items: stretch; flex-direction: column; }
    .admin-room-picker { width: 100%; }
    .admin-tabs { width: 100%; }
    .admin-tab-btn { flex: 1; min-width: 0; }
    .admin-order-heading { align-items: stretch; }
    .admin-save-order-btn { width: 100%; }
    .main-display-overlay img,
    .main-display-overlay video { max-height: 42vh; }
}
