* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #111827;
    color: #ffffff;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 22px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.logo-circle {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 800;
}

h1 {
    margin: 0 0 8px;
    font-size: 32px;
    color: #a78bfa;
}

.subtitle {
    margin: 0 0 28px;
    color: #d1d5db;
}

form {
    text-align: left;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #e5e7eb;
    font-weight: 700;
}

input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid #4b5563;
    background: #111827;
    color: #ffffff;
    font-size: 16px;
    outline: none;
}

input:focus {
    border-color: #8b5cf6;
}

button {
    width: 100%;
    margin-top: 16px;
    padding: 14px 16px;
    border: none;
    border-radius: 14px;
    background: #7c3aed;
    color: white;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

button:hover {
    background: #6d28d9;
}

.error {
    margin-top: 16px;
    color: #fca5a5;
    font-weight: 700;
}

.hint {
    margin-top: 22px;
    color: #9ca3af;
    font-size: 14px;
}

.chat-page {
    min-height: 100vh;
    background: #111827;
    color: #ffffff;
    display: flex;
    justify-content: center;
    padding: 24px;
}

.chat-shell {
    width: 100%;
    max-width: 900px;
    height: calc(100vh - 48px);
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid #374151;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.chat-header h1 {
    margin: 0;
    font-size: 28px;
    color: #a78bfa;
}

.chat-header p {
    margin: 6px 0 0;
    color: #cbd5e1;
}

.user-box {
    background: #111827;
    border: 1px solid #374151;
    border-radius: 16px;
    padding: 12px 16px;
    text-align: right;
    color: #cbd5e1;
}

.user-box span {
    display: block;
    font-size: 13px;
    color: #9ca3af;
}

.user-box b {
    color: #ffffff;
}

.online-panel {
    padding: 12px 20px;
    border-bottom: 1px solid #374151;
    background: #172033;
}

.online-title {
    font-size: 14px;
    font-weight: 800;
    color: #c4b5fd;
    margin-bottom: 8px;
}

.online-users {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: #9ca3af;
    font-size: 14px;
}

.online-user {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: #111827;
    border: 1px solid #374151;
    color: #e5e7eb;
}

.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.system-message {
    align-self: center;
    background: #111827;
    border: 1px solid #374151;
    color: #9ca3af;
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 14px;
}

.message-form {
    padding: 16px;
    border-top: 1px solid #374151;
    display: flex;
    gap: 12px;
    background: #1f2937;
}

.message-form input {
    flex: 1;
    margin: 0;
}

.message-form button {
    width: auto;
    min-width: 140px;
    margin: 0;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.mine {
    justify-content: flex-end;
}

.message-row.other {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 14px 10px;
    border-radius: 18px;
    line-height: 1.35;
}

.message-row.mine .message-bubble {
    background: #7c3aed;
    color: #ffffff;
    border-bottom-right-radius: 6px;
}

.message-row.other .message-bubble {
    background: #111827;
    color: #ffffff;
    border: 1px solid #374151;
    border-bottom-left-radius: 6px;
}

.message-name {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #ddd6fe;
}

.message-text {
    font-size: 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-time {
    margin-top: 6px;
    font-size: 12px;
    text-align: right;
    color: #c4b5fd;
}

.message-row.other .message-time {
    color: #9ca3af;
}

.admin-page {
    min-height: 100vh;
    background: #111827;
    color: #ffffff;
    padding: 24px;
}

.admin-shell {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.admin-header {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 22px;
    padding: 24px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}

.admin-header h1 {
    margin: 0;
    color: #a78bfa;
    font-size: 32px;
}

.admin-header p {
    margin: 8px 0 0;
    color: #cbd5e1;
}

.admin-actions {
    display: flex;
    gap: 12px;
}

.admin-actions a {
    color: #ffffff;
    background: #7c3aed;
    padding: 10px 14px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 700;
}

.admin-actions a:hover {
    background: #6d28d9;
}

.admin-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.admin-stat-card {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 18px;
    padding: 18px;
}

.admin-stat-card span {
    display: block;
    color: #9ca3af;
    font-size: 14px;
    margin-bottom: 8px;
}

.admin-stat-card b {
    display: block;
    color: #ffffff;
    font-size: 30px;
}

.admin-online-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-online-list span {
    display: inline-flex;
    padding: 7px 11px;
    border-radius: 999px;
    background: #111827;
    border: 1px solid #374151;
    color: #e5e7eb;
    font-size: 14px;
}

.admin-online-list p {
    margin: 0;
    color: #9ca3af;
}

.admin-block {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 22px;
    padding: 22px;
    margin-bottom: 24px;
    overflow: hidden;
}

.admin-block h2 {
    margin: 0 0 18px;
    color: #ffffff;
    font-size: 24px;
}

.admin-table-wrap {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
}

.admin-table {
    width: 100%;
    min-width: 1100px;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th,
.admin-table td {
    padding: 10px 9px;
    border-bottom: 1px solid #374151;
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    color: #c4b5fd;
    font-weight: 800;
    white-space: nowrap;
}

.admin-table td {
    color: #e5e7eb;
}

.admin-table code {
    background: #111827;
    border: 1px solid #374151;
    padding: 4px 6px;
    border-radius: 8px;
    color: #93c5fd;
    white-space: nowrap;
    font-size: 13px;
}

.deleted-row {
    opacity: 0.45;
}

button.small {
    width: auto;
    min-width: 110px;
    margin: 0 0 6px 0;
    padding: 9px 12px;
    font-size: 14px;
    border-radius: 10px;
}

button.danger {
    background: #dc2626;
}

button.danger:hover {
    background: #b91c1c;
}

.admin-table form {
    margin: 0;
}

.admin-create-form {
    display: flex;
    gap: 12px;
    margin-bottom: 22px;
}

.admin-create-form input {
    flex: 1;
    margin: 0;
}

.admin-create-form button {
    width: auto;
    min-width: 150px;
    margin: 0;
}

.admin-block > form {
    margin-bottom: 18px;
}

.admin-block > form button {
    width: auto;
    min-width: 180px;
}

.clear-history-button {
    width: auto;
    min-width: 220px;
    margin-top: 0;
    margin-bottom: 18px;
}

.clear-history-form {
    display: inline-block;
    width: auto;
    margin-bottom: 18px;
}

.clear-history-form .clear-history-button {
    display: inline-block;
    width: auto;
    min-width: 220px;
    max-width: 260px;
    margin: 0;
}

@media (max-width: 900px) {
    .chat-page {
        padding: 0;
    }

    .chat-shell {
        height: 100vh;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-box {
        width: 100%;
        text-align: left;
    }

    .message-form {
        flex-direction: column;
    }

    .message-form button {
        width: 100%;
    }

    .message-bubble {
        max-width: 88%;
    }

    .admin-page {
        padding: 10px;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-actions {
        width: 100%;
        flex-direction: column;
    }

    .admin-actions a {
        text-align: center;
    }

    .admin-stats {
        grid-template-columns: repeat(2, minmax(130px, 1fr));
    }

    .admin-create-form {
        flex-direction: column;
    }

    .admin-create-form button {
        width: 100%;
    }

    .admin-table {
        font-size: 13px;
        min-width: 1050px;
    }
}

/* Admin table usability fix */

.admin-shell {
    max-width: 96vw;
}

.admin-table-wrap {
    max-height: 70vh;
    overflow: auto;
    border: 1px solid #374151;
    border-radius: 14px;
}

.admin-table th {
    position: sticky;
    top: 0;
    background: #1f2937;
    z-index: 5;
}

.admin-table th:last-child,
.admin-table td:last-child {
    position: sticky;
    right: 0;
    background: #1f2937;
    z-index: 6;
    min-width: 140px;
    box-shadow: -8px 0 12px rgba(0, 0, 0, 0.25);
}

.admin-table th:last-child {
    z-index: 8;
}

.admin-table td:nth-child(3) code {
    display: inline-block;
    max-width: 120px;
    white-space: normal;
    word-break: break-word;
}

.admin-table td {
    white-space: nowrap;
}

.admin-table td:nth-child(2),
.admin-table td:nth-child(3),
.admin-table td:nth-child(7),
.admin-table td:nth-child(8),
.admin-table td:nth-child(10) {
    white-space: normal;
}

/* Mobile chat input like messenger */

@media (max-width: 700px) {
    .message-form {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 10px;
    }

    .message-form input {
        flex: 1;
        min-width: 0;
        height: 52px;
        padding: 12px 14px;
        border-radius: 18px;
        font-size: 16px;
    }

    .message-form button {
        width: 52px;
        min-width: 52px;
        height: 52px;
        padding: 0;
        margin: 0;
        border-radius: 18px;
        font-size: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .message-form button::before {
        content: "?";
        font-size: 24px;
        line-height: 1;
    }
}
/* Mobile compact chat layout */

@media (max-width: 700px) {
    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    .chat-page {
        height: 100dvh;
        min-height: 100dvh;
        padding: 0;
        overflow: hidden;
    }

    .chat-shell {
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        padding: 12px 16px;
        gap: 10px;
    }

    .chat-header h1 {
        font-size: 30px;
        line-height: 1.1;
    }

    .chat-header p {
        font-size: 16px;
        margin-top: 4px;
    }

    .user-box {
        padding: 10px 12px;
        border-radius: 14px;
        font-size: 15px;
    }

    .user-box span {
        font-size: 13px;
    }

    .online-panel {
        padding: 10px 16px;
    }

    .online-title {
        margin-bottom: 8px;
        font-size: 15px;
    }

    .online-users {
        gap: 6px;
    }

    .online-user {
        padding: 5px 10px;
        font-size: 14px;
    }

    .messages {
        min-height: 0;
        flex: 1;
        padding: 14px 12px;
        gap: 10px;
    }

    .message-bubble {
        max-width: 88%;
        padding: 11px 13px 9px;
        font-size: 15px;
    }

    .message-text {
        font-size: 17px;
    }

    .system-message {
        font-size: 13px;
        padding: 8px 12px;
    }

    .message-form {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
        background: #1f2937;
        border-top: 1px solid #374151;
    }

    .message-form input {
        flex: 1;
        min-width: 0;
        height: 48px;
        padding: 10px 14px;
        border-radius: 17px;
        font-size: 16px;
    }

    .message-form button {
        width: 48px;
        min-width: 48px;
        height: 48px;
        padding: 0;
        margin: 0;
        border-radius: 17px;
        font-size: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .message-form button::before {
        content: "";
        width: 17px;
        height: 17px;
        border-top: 3px solid white;
        border-right: 3px solid white;
        transform: rotate(45deg);
        margin-left: -4px;
    }

    .message-form button::after {
        content: "";
        width: 17px;
        height: 3px;
        background: white;
        margin-left: -15px;
    }
}

/* PWA Android viewport fix */

@media (max-width: 700px) {
    .chat-page {
        height: var(--app-height, 100dvh);
        min-height: var(--app-height, 100dvh);
        overflow: hidden;
        padding: 0;
    }

    .chat-shell {
        height: var(--app-height, 100dvh);
        max-height: var(--app-height, 100dvh);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-radius: 0;
        border: none;
    }

    .messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding-bottom: 12px;
    }

    .message-form {
        flex-shrink: 0;
        position: relative;
        z-index: 20;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: #1f2937;
    }
}