/* === Watermark === */
#watermark {
    position: fixed;
    bottom: 10px;
    right: 14px;
    font-size: 10px;
    color: #2a2a2a;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    pointer-events: none;
    z-index: 9999;
    letter-spacing: 0.05em;
}

/* === Utility === */
.hidden {
    display: none !important;
}

/* === Load animations === */
@keyframes emerge-down {
    from {
        opacity: 0;
        transform: translateY(-10px);
        filter: blur(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

@keyframes emerge-up {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    background-color: #0f0f0f;
    color: #9a9a9a;
}

body.chat-mode {
    display: block;
    padding: 0;
    overflow: hidden;
    height: 100vh;
}

/* === Login View === */
#login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 48px;
    animation: emerge-down 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.logo {
    height: 60px;
    width: auto;
    filter: brightness(0) invert(1);
}

h1 {
    color: #c8c8c8;
    font-size: 42px;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-weight: normal;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    text-align: center;
    margin: 0;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    max-width: 380px;
}

#login-error {
    font-size: 11px;
    color: #7a3a3a;
    text-align: center;
    letter-spacing: 0.08em;
    min-height: 16px;
    margin-bottom: 6px;
}

.contact-unread {
    font-size: 10px;
    color: #4a7a6a;
    margin-left: auto;
}

#username {
    animation: emerge-up 0.55s cubic-bezier(0.16, 1, 0.3, 1) both 0.45s;
}

#password {
    animation: emerge-up 0.55s cubic-bezier(0.16, 1, 0.3, 1) both 0.6s;
}

#username,
#password {
    padding: 10px 4px;
    font-size: 16px;
    border: none;
    border-bottom: 1px solid #2a2a2a;
    border-radius: 0;
    background-color: transparent;
    color: #b0b0b0;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    outline: none;
    margin-bottom: 18px;
    text-align: center;
    transition: border-color 0.2s;
}

#username:focus,
#password:focus {
    border-bottom-color: #666;
    caret-color: #c8c8c8;
    caret-shape: block;
}

#username::placeholder,
#password::placeholder {
    color: #525252;
}

#login-btn {
    animation: emerge-up 0.55s cubic-bezier(0.16, 1, 0.3, 1) both 0.77s;
    margin-top: 10px;
    padding: 10px 0;
    font-size: 14px;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    letter-spacing: 0.2em;
    background: none;
    color: #7a8a9a;
    border: none;
    outline: none;
    text-align: center;
    transition: color 0s;
}

#login-btn .bracket {
    display: inline-block;
    transition: transform 0.15s linear;
}

#login-btn:hover {
    color: #ffffff;
}

#login-btn:hover .bracket.left {
    transform: translateX(-4px);
}

#login-btn:hover .bracket.right {
    transform: translateX(4px);
}

#login-btn .cursor {
    opacity: 0;
}

#login-btn:hover .cursor {
    opacity: 1;
    animation: terminal-blink 0.6s steps(2, start) infinite;
}

@keyframes terminal-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@media (max-width: 768px) {
    h1 {
        font-size: 30px;
    }

    .logo {
        height: 48px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 22px;
    }

    .logo {
        height: 40px;
    }

    .site-header {
        margin-bottom: 30px;
        gap: 12px;
    }

    #login-form {
        max-width: 100%;
    }
}

/* ========================================
   CHAT VIEW
   ======================================== */

#chat-view {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* === Sidebar === */
#chat-sidebar {
    width: 190px;
    min-width: 140px;
    background: #0a0a0a;
    border-right: 1px solid #1c1c1c;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 14px 14px;
    font-size: 11px;
    letter-spacing: 0.12em;
    color: #383838;
    border-bottom: 1px solid #181818;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo {
    height: 18px;
    width: auto;
    filter: brightness(0) invert(0.22);
}

#self-info {
    border-top: 1px solid #181818;
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
    margin-top: auto;
}

#self-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#self-info .status-dot {
    position: static;
    top: unset;
    flex-shrink: 0;
}

#self-username {
    font-size: 11px;
    letter-spacing: 0.1em;
    color: #505050;
}

#self-status-text {
    font-size: 10px;
    letter-spacing: 0.06em;
    color: #3a7a5a;
    padding-left: 16px;
    display: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#logout-btn {
    background: none;
    border: none;
    border-top: 1px solid #181818;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: #303030;
    cursor: pointer;
    padding: 11px 14px;
    text-align: left;
    width: 100%;
    transition: color 0.15s;
    flex-shrink: 0;
}

#logout-btn:hover {
    color: #888;
}

#logout-btn .bracket {
    display: inline-block;
    transition: transform 0.15s;
}

#logout-btn:hover .bracket.left {
    transform: translateX(-3px);
}

#logout-btn:hover .bracket.right {
    transform: translateX(3px);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.contact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 13px;
    color: #484848;
}

.contact:hover {
    background: #111;
    color: #7a7a7a;
}

.contact.active {
    background: #111;
    color: #b8b8b8;
}

.status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: #3a7a5a;
    box-shadow: 0 0 5px #3a7a5a88;
}

.status-dot.offline {
    background: #2a2a2a;
}

.contact-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-badge {
    font-size: 10px;
    color: #2a5a45;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.contact-badge.off {
    color: #282828;
}

/* Channel entry in sidebar */
.contact.channel-entry .contact-name {
    color: #4a7a6a;
}

.contact.channel-entry.active .contact-name {
    color: #6aaa8a;
}

.contact.channel-entry .contact-badge {
    color: #3a5a4a;
}

.contact-status {
    display: block;
    font-size: 10px;
    color: #2a5040;
    letter-spacing: 0.05em;
    margin-left: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-separator {
    height: 1px;
    background: #1c1c1c;
    margin: 4px 14px;
}

/* === Chat Main === */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#chat-header {
    padding: 13px 20px;
    border-bottom: 1px solid #181818;
    font-size: 13px;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

#chat-with-label {
    color: #c8c8c8;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    vertical-align: middle;
    position: relative;
    top: -1px;
    flex-shrink: 0;
}

.status-dot.online-dot {
    background-color: #3a7a5a;
    box-shadow: 0 0 6px #3a7a5a;
}

.status-dot.offline-dot {
    background-color: #333;
    box-shadow: none;
}

#chat-status-label {
    font-size: 11px;
    letter-spacing: 0.1em;
}

#chat-status-label.online-label {
    color: #3a7a5a;
}

#chat-status-label.offline-label {
    color: #383838;
}

/* === Message Feed === */
#message-feed {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: #1e1e1e transparent;
}

#message-feed::-webkit-scrollbar {
    width: 3px;
}

#message-feed::-webkit-scrollbar-thumb {
    background: #222;
    border-radius: 2px;
}

.message {
    font-size: 13px;
    line-height: 1.6;
    animation: emerge-up 0.2s ease both;
}

.message .msg-time {
    color: #2e2e2e;
}

.message .msg-sender {
    color: #585858;
    margin-left: 4px;
}

.message.self .msg-sender {
    color: #4a6a8a;
}

.msg-admin-tag {
    font-size: 10px;
    color: #7a4a4a;
    margin-left: 5px;
    letter-spacing: 0.06em;
}

.message .msg-sep {
    color: #2a2a2a;
    margin: 0 5px;
}

.message .msg-text {
    color: #d1d5db;
}

.message.self .msg-text {
    color: #e5e7eb;
}

.system-msg {
    font-size: 11px;
    color: #2a5040;
    letter-spacing: 0.1em;
    padding: 6px 0 10px;
    animation: emerge-up 0.3s ease both;
}

/* === Typing Indicator === */
#typing-indicator {
    padding: 2px 22px 8px;
    font-size: 12px;
    color: #2a5040;
    letter-spacing: 0.05em;
    min-height: 22px;
    flex-shrink: 0;
}

.blink-cursor {
    animation: terminal-blink 0.6s steps(2, start) infinite;
}

/* === Input Area === */
#input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 20px;
    border-top: 1px solid #181818;
    flex-shrink: 0;
}

.input-prefix {
    color: #3a7a5a;
    font-size: 14px;
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 14px;
    color: #c8c8c8;
    caret-color: #c8c8c8;
    min-width: 0;
}

#send-btn {
    background: none;
    border: none;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 12px;
    color: #304a5a;
    cursor: pointer;
    letter-spacing: 0.15em;
    padding: 4px 0;
    transition: color 0.15s;
    flex-shrink: 0;
}

#send-btn:hover {
    color: #c8c8c8;
}

#send-btn .bracket {
    display: inline-block;
    transition: transform 0.15s;
}

#send-btn:hover .bracket.left {
    transform: translateX(-3px);
}

#send-btn:hover .bracket.right {
    transform: translateX(3px);
}

.SoundBtn {
    background: none;
    border: none;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 12px;
    color: #304a5a;
    cursor: pointer;
    letter-spacing: 0.15em;
    padding: 4px 0;
    transition: color 0.15s;
    flex-shrink: 0;
}


/* === Sidebar Toggle Button (hidden on desktop) === */
#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: 14px;
    color: #505050;
    cursor: pointer;
    padding: 4px 0;
    flex-shrink: 0;
    transition: color 0.15s;
}

#sidebar-toggle:hover {
    color: #c8c8c8;
}

#sidebar-toggle .bracket {
    display: inline-block;
    transition: transform 0.15s;
}

#sidebar-toggle:hover .bracket.left {
    transform: translateX(-3px);
}

#sidebar-toggle:hover .bracket.right {
    transform: translateX(3px);
}

/* === Sidebar Backdrop (hidden by default) === */
#sidebar-backdrop {
    display: none;
}

/* === Mobile Responsive (≤ 600px) === */
@media (max-width: 600px) {

    /* Show toggle button — large tap target */
    #sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 56px;
        min-height: 56px;
        font-size: 24px;
        color: #7a8a9a;
        margin: -14px -4px -14px -10px;
    }

    /* Sidebar becomes fixed overlay */
    #chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        height: 100dvh;
        width: 260px;
        min-width: 260px;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    body.sidebar-open #chat-sidebar {
        transform: translateX(0);
    }

    /* Backdrop */
    body.sidebar-open #sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

    /* Chat main takes full width */
    #chat-main {
        width: 100%;
    }

    /* Use dvh for full viewport on iOS */
    #chat-view {
        height: 100vh;
        height: 100dvh;
    }

    /* Larger touch targets for contacts */
    .contact {
        padding: 12px 16px;
        min-height: 44px;
    }

    /* Chat header — tall and easy to interact with, safe-area for notch/dynamic island */
    #chat-header {
        padding: 16px 18px;
        padding-top: max(22px, env(safe-area-inset-top));
        gap: 10px;
        font-size: 13px;
        min-height: 54px;
    }

    #chat-status-label {
        font-size: 10px;
    }

    /* Message feed */
    #message-feed {
        padding: 12px;
    }

    .message {
        font-size: 12px;
        word-break: break-word;
    }

    .message .msg-time {
        font-size: 11px;
    }

    .message .msg-sender {
        font-size: 11px;
    }

    .msg-admin-tag {
        font-size: 9px;
    }

    /* Input area — safe area padding for iPhone home indicator */
    #input-area {
        padding: 10px 14px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    #message-input {
        min-height: 44px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    /* Hide watermark on mobile */
    #watermark {
        display: none;
    }
}
