:root {
    --navy: #18355b;
    --navy-dark: #0b213f;
    --blue: #2d6da3;
    --green: #33ad52;
    --silver: #c8c8c8;
    --panel: #ece9d8;
    --border-light: #ffffff;
    --border-mid: #8b8b8b;
    --border-dark: #3b3b3b;
    --text: #111111;
    --muted: #606060;
    --unread: #fff2a8;
    --danger: #8f1b1b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: Tahoma, Verdana, Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 10% 10%, rgba(255,255,255,.25), transparent 28%),
        linear-gradient(145deg, #376b9e, #102d50);
}

button, input, textarea { font: inherit; }

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.retro-window {
    background: var(--panel);
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    box-shadow: 5px 6px 0 rgba(0, 0, 0, .28);
}

.auth-window {
    width: min(430px, 100%);
}

.titlebar {
    min-height: 31px;
    padding: 5px 7px;
    display: flex;
    align-items: center;
    gap: 7px;
    color: white;
    background: linear-gradient(90deg, var(--navy-dark), #3476ad);
}

.window-buttons {
    margin-left: auto;
    letter-spacing: 5px;
    font-weight: bold;
}

.tiny-logo { width: 20px; height: 20px; }

.auth-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px 24px 16px;
}

.auth-hero h1 { margin: 0 0 4px; font-size: 30px; }
.auth-hero p { margin: 0; color: var(--muted); }
.hero-logo { width: 72px; height: 72px; }

.tabs {
    display: flex;
    margin: 0 20px;
    border-bottom: 1px solid var(--border-mid);
}

.tab {
    padding: 8px 15px;
    border: 1px solid var(--border-mid);
    border-bottom: 0;
    background: #d8d6ca;
    cursor: pointer;
}

.tab.active {
    position: relative;
    top: 1px;
    background: var(--panel);
    font-weight: bold;
}

.form-panel {
    display: none;
    padding: 20px;
}

.form-panel.active { display: grid; gap: 14px; }

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: bold;
}

input, textarea {
    width: 100%;
    padding: 9px 10px;
    border: 2px solid;
    border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
    border-radius: 0;
    background: white;
    color: var(--text);
    outline: none;
}

input:focus, textarea:focus { box-shadow: inset 0 0 0 2px #96c8ff; }

.retro-button {
    min-height: 36px;
    padding: 7px 14px;
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    background: #d8d6ca;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.retro-button:active {
    border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
}

.retro-button.primary {
    background: linear-gradient(#4a8bc0, #245b8a);
    color: white;
    font-weight: bold;
}

.block { display: block; width: 100%; }

.error-box, .dialog-error {
    color: white;
    background: var(--danger);
    margin: 0 20px 4px;
    padding: 9px 10px;
    font-size: 13px;
}

.dialog-error:empty { display: none; }

.welcome-card {
    padding-bottom: 22px;
    text-align: center;
}

.welcome-card > :not(.titlebar) { margin-left: 24px; margin-right: 24px; }
.welcome-icon {
    width: 66px;
    height: 66px;
    display: grid;
    place-items: center;
    margin: 24px auto 10px !important;
    border-radius: 50%;
    color: white;
    background: var(--green);
    font-size: 38px;
    font-weight: bold;
}

.big-uin {
    margin: 12px 0;
    padding: 12px;
    border: 2px inset #aaa;
    background: white;
    font: bold 34px "Courier New", monospace;
    letter-spacing: 3px;
}

.messenger-shell {
    width: min(1050px, 100%);
    height: min(780px, 100vh);
    margin: auto;
    display: grid;
    grid-template-columns: 330px 1fr;
    background: var(--panel);
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    box-shadow: 5px 6px 0 rgba(0,0,0,.25);
}

.contacts-pane {
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 2px groove #aaa;
}

.app-header, .chat-header {
    min-height: 65px;
    display: flex;
    align-items: center;
    padding: 9px 11px;
    color: white;
    background: linear-gradient(90deg, var(--navy-dark), #3476ad);
}

.brand-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-row > div { min-width: 0; }
.brand-row strong, .chat-user strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-row small, .chat-user small { display: block; margin-top: 3px; opacity: .88; }
.app-logo { width: 42px; height: 42px; }
.icon-button {
    margin-left: auto;
    border: 1px solid rgba(255,255,255,.6);
    background: rgba(255,255,255,.13);
    color: white;
    min-width: 39px;
    min-height: 34px;
    cursor: pointer;
}

.contact-tools { padding: 9px; border-bottom: 1px solid #aaa; }

.contact-list {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.contact-item {
    width: 100%;
    display: grid;
    grid-template-columns: 15px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 10px 9px;
    border: 0;
    border-bottom: 1px solid #d0d0d0;
    background: white;
    text-align: left;
    cursor: pointer;
}

.contact-item:hover, .contact-item.active { background: #dcecff; }
.contact-item.has-unread { background: var(--unread); }
.contact-main { min-width: 0; }
.contact-main strong, .contact-main small {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.contact-main small { margin-top: 3px; color: var(--muted); }
.unread-badge {
    min-width: 22px;
    padding: 3px 6px;
    border-radius: 10px;
    background: var(--navy);
    color: white;
    text-align: center;
    font-size: 12px;
}
.status-dot {
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #909090;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.6);
}
.status-dot.online { background: #35c552; }

.contacts-footer {
    min-height: 39px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 9px;
    border-top: 1px solid #aaa;
    background: #d8d6ca;
}

.link-button {
    padding: 4px;
    border: 0;
    background: transparent;
    color: #154f88;
    text-decoration: underline;
    cursor: pointer;
}

.chat-pane {
    min-width: 0;
    background: #f3f1e5;
}

.chat-placeholder {
    height: 100%;
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 24px;
    text-align: center;
    color: var(--muted);
}
.chat-placeholder h2 { margin: 14px 0 5px; color: var(--text); }
.chat-placeholder p { margin: 0; }
.placeholder-logo { width: 90px; height: 90px; opacity: .8; }

.chat-content {
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
}

.chat-header { gap: 9px; }
.back-button {
    display: none;
    border: 0;
    background: transparent;
    color: white;
    font-size: 33px;
    cursor: pointer;
}
.chat-user { min-width: 0; }

.message-list {
    overflow-y: auto;
    padding: 15px;
    background:
        linear-gradient(rgba(255,255,255,.76), rgba(255,255,255,.76)),
        repeating-linear-gradient(0deg, #dfe9f2 0, #dfe9f2 1px, transparent 1px, transparent 23px);
}

.message-row { display: flex; margin: 5px 0; }
.message-row.mine { justify-content: flex-end; }

.message-bubble {
    max-width: min(78%, 520px);
    padding: 8px 10px 6px;
    border: 1px solid #7f7f7f;
    background: #fff;
    box-shadow: 2px 2px 0 rgba(0,0,0,.1);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.message-row.mine .message-bubble { background: #dff3d8; }

.message-meta {
    display: block;
    margin-top: 4px;
    color: #666;
    font-size: 10px;
    text-align: right;
}

.typing-line {
    min-height: 22px;
    padding: 4px 12px;
    color: var(--muted);
    font-size: 12px;
}

.composer {
    display: grid;
    grid-template-columns: 1fr 48px;
    gap: 7px;
    padding: 9px;
    border-top: 2px groove #aaa;
    background: var(--panel);
}
.composer textarea {
    max-height: 115px;
    min-height: 42px;
    resize: none;
}
.send-button {
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    background: var(--blue);
    color: white;
    font-size: 22px;
    cursor: pointer;
}
.send-button:active {
    border-color: var(--border-dark) var(--border-light) var(--border-light) var(--border-dark);
}

.empty-state {
    padding: 24px 18px;
    text-align: center;
    color: var(--muted);
}

.retro-dialog {
    width: min(390px, calc(100% - 24px));
    padding: 0;
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    background: var(--panel);
    box-shadow: 5px 6px 0 rgba(0,0,0,.3);
}
.retro-dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-close {
    margin-left: auto;
    border: 1px solid white;
    background: #bb3131;
    color: white;
    cursor: pointer;
}
.dialog-body { display: grid; gap: 13px; padding: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 720px) {
    body { background: var(--panel); }
    .messenger-shell {
        height: 100dvh;
        width: 100%;
        display: block;
        border: 0;
        box-shadow: none;
    }
    .contacts-pane, .chat-pane { height: 100%; }
    .chat-pane {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 5;
    }
    .messenger-shell.chat-open .contacts-pane { display: none; }
    .messenger-shell.chat-open .chat-pane { display: block; }
    .back-button { display: block; }
    .message-bubble { max-width: 86%; }
}

/* Hidden must always win over component display styles */
[hidden] {
    display: none !important;
}
