* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #eef1f4;
    color: #111;
}

/* Top Bar */

.topbar {
    height: 56px;
    background: #075e54;
    color: white;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 18px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar a {
    color: white;
    margin-left: auto;
    text-decoration: none;
}

/* Layout */

.layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

.side {
    width: 230px;
    background: #fff;
    border-right: 1px solid #ddd;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.side a {
    padding: 11px 12px;
    border-radius: 8px;
    color: #111;
    text-decoration: none;
    white-space: nowrap;
}

.side a:hover {
    background: #e8f5e9;
}

.main {
    flex: 1;
    padding: 22px;
    overflow: auto;
    max-width: 100%;
}

/* Forms */

.login {
    max-width: 420px;
    margin: 80px auto;
    background: #fff;
    padding: 28px;
    border-radius: 16px;
    box-shadow: 0 5px 20px #0001;
}

.login input,
.gridForm input,
.panel input,
.panel textarea,
.sendForm textarea,
select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 10px;
    margin: 6px 0;
    font-size: 14px;
    outline: none;
}

.login input:focus,
.gridForm input:focus,
.panel input:focus,
.panel textarea:focus,
.sendForm textarea:focus,
select:focus {
    border-color: #075e54;
}

button,
.btn {
    background: #075e54;
    color: white;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    text-decoration: none;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
}

button:hover,
.btn:hover {
    opacity: 0.92;
}

button:disabled,
textarea:disabled,
input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.alert {
    background: #ffe1e1;
    color: #8a0000;
    padding: 12px;
    border-radius: 10px;
    margin: 10px 0;
}

.notice {
    background: #dcf8c6;
    padding: 12px;
    border-radius: 10px;
    margin: 10px 0;
}

/* Cards / Panels */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.card,
.panel {
    background: white;
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 2px 10px #0000000d;
}

.card b {
    font-size: 32px;
    display: block;
}

.card span {
    color: #666;
}

/* Tables */

.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 14px;
    overflow: hidden;
}

.table th,
.table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: top;
}

.table th {
    background: #f7f7f7;
    font-size: 13px;
    color: #555;
}

.badge {
    background: #25d366;
    color: white;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 12px;
    display: inline-block;
}

/* Chat Header */

.chatHead {
    background: white;
    border-radius: 14px;
    padding: 15px;
    margin-bottom: 10px;
    box-shadow: 0 1px 5px #0000000d;
}

.chatHead h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.chatHead p {
    margin: 0;
    color: #555;
    font-size: 14px;
    line-height: 1.5;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.actions form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.actions select {
    min-width: 190px;
    margin: 0;
}

/* Chat Box */

.chatBox {
    height: 58vh;
    overflow: auto;
    background: #efeae2;
    border-radius: 14px;
    padding: 18px;
    background-image:
        radial-gradient(circle at 25px 25px, rgba(0,0,0,0.025) 2%, transparent 0%),
        radial-gradient(circle at 75px 75px, rgba(0,0,0,0.02) 2%, transparent 0%);
    background-size: 100px 100px;
}

.msg {
    display: flex;
    margin: 8px 0;
}

.msg.sent {
    justify-content: flex-end;
}

.msg.recv {
    justify-content: flex-start;
}

.bubble {
    max-width: 68%;
    padding: 9px 12px;
    border-radius: 9px;
    background: white;
    box-shadow: 0 1px 2px #0001;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
}

.recv .bubble {
    border-top-left-radius: 2px;
}

.sent .bubble {
    background: #d9fdd3;
    border-top-right-radius: 2px;
}

.bubble small {
    display: block;
    color: #777;
    margin-top: 6px;
    text-align: right;
    font-size: 11px;
}

/* Media Preview */

.mediaBox {
    margin-bottom: 7px;
}

.chatImage {
    max-width: 280px;
    max-height: 280px;
    width: auto;
    height: auto;
    border-radius: 10px;
    display: block;
    object-fit: cover;
}

.chatVideo {
    max-width: 320px;
    max-height: 280px;
    width: 100%;
    border-radius: 10px;
    display: block;
    background: #000;
}

.chatAudio {
    width: 270px;
    max-width: 100%;
}

.documentBox {
    background: rgba(255,255,255,0.7);
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 14px;
    border: 1px solid rgba(0,0,0,0.08);
}

.documentBox a {
    color: #075e54;
    font-weight: bold;
    text-decoration: none;
    word-break: break-word;
}

/* Send Form */

.sendForm {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
    background: #f0f2f5;
    border-radius: 14px;
    padding: 10px;
    position: relative;
}

.sendForm textarea {
    height: 48px;
    min-height: 48px;
    max-height: 130px;
    resize: vertical;
    margin: 0;
    border-radius: 22px;
    padding: 13px 15px;
    flex: 1;
}

.sendForm button[type="submit"],
.sendForm > button:not(.emojiBtn) {
    border-radius: 22px;
    min-width: 78px;
    height: 44px;
}

.emojiBtn,
.attachBtn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #ffffff;
    color: #555;
    border: 1px solid #ddd;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    font-size: 20px;
    text-decoration: none;
}

.emojiBtn:hover,
.attachBtn:hover {
    background: #e8f5e9;
    opacity: 1;
}

.selectedFileName {
    margin: 7px 0 0;
    color: #075e54;
    font-size: 13px;
    background: #fff;
    display: inline-block;
    padding: 7px 10px;
    border-radius: 8px;
}

/* Emoji Panel */

.emojiPanel {
    display: none;
    position: fixed;
    bottom: 92px;
    left: 280px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 14px;
    padding: 10px;
    width: 300px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.18);
    z-index: 100;
}

.emojiPanel span {
    cursor: pointer;
    font-size: 23px;
    padding: 6px;
    display: inline-block;
    border-radius: 8px;
}

.emojiPanel span:hover {
    background: #f1f1f1;
}

/* Grid */

.gridForm {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

/* Tablet */

@media (max-width: 1024px) {
    .side {
        width: 205px;
    }

    .main {
        padding: 16px;
    }

    .bubble {
        max-width: 76%;
    }

    .chatImage {
        max-width: 240px;
        max-height: 240px;
    }
}

/* Mobile */

@media (max-width: 800px) {
    .topbar {
        height: auto;
        min-height: 56px;
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 10px;
    }

    .topbar a {
        margin-left: 0;
    }

    .layout {
        display: block;
        min-height: calc(100vh - 56px);
    }

    .side {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 10px;
        gap: 6px;
        border-right: 0;
        border-bottom: 1px solid #ddd;
        position: sticky;
        top: 56px;
        z-index: 40;
    }

    .side a {
        padding: 9px 11px;
        font-size: 13px;
        background: #f7f7f7;
    }

    .main {
        padding: 12px;
    }

    .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .card,
    .panel {
        padding: 14px;
        border-radius: 14px;
    }

    .card b {
        font-size: 25px;
    }

    .table {
        font-size: 13px;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .chatHead {
        padding: 12px;
    }

    .chatHead h1 {
        font-size: 20px;
    }

    .chatHead p {
        font-size: 12px;
    }

    .actions {
        flex-direction: column;
        gap: 7px;
    }

    .actions form {
        width: 100%;
        flex-wrap: wrap;
    }

    .actions button,
    .actions select {
        width: 100%;
    }

    .chatBox {
        height: calc(100vh - 320px);
        min-height: 380px;
        padding: 12px;
        border-radius: 12px;
    }

    .bubble {
        max-width: 88%;
        font-size: 14px;
    }

    .sendForm {
        gap: 6px;
        padding: 8px;
        border-radius: 12px;
        position: sticky;
        bottom: 0;
        z-index: 30;
    }

    .sendForm textarea {
        min-height: 44px;
        height: 44px;
        padding: 11px 13px;
        font-size: 14px;
    }

    .sendForm button[type="submit"],
    .sendForm > button:not(.emojiBtn) {
        min-width: 62px;
        height: 42px;
        padding: 9px 12px;
    }

    .emojiBtn,
    .attachBtn {
        width: 40px;
        min-width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .emojiPanel {
        left: 10px;
        right: 10px;
        bottom: 78px;
        width: auto;
        max-width: none;
    }

    .chatImage {
        max-width: 220px;
        max-height: 220px;
    }

    .chatVideo {
        max-width: 240px;
        max-height: 220px;
    }

    .chatAudio {
        width: 220px;
    }
}

/* Small Mobile */

@media (max-width: 520px) {
    .login {
        margin: 35px 12px;
        padding: 22px;
    }

    .main {
        padding: 10px;
    }

    .cards {
        grid-template-columns: 1fr;
    }

    .chatBox {
        height: calc(100vh - 300px);
        min-height: 340px;
        padding: 10px;
    }

    .bubble {
        max-width: 93%;
        padding: 8px 10px;
    }

    .chatImage {
        max-width: 190px;
        max-height: 190px;
    }

    .chatVideo {
        max-width: 205px;
        max-height: 190px;
    }

    .chatAudio {
        width: 190px;
    }

    .sendForm {
        display: grid;
        grid-template-columns: 40px 40px 1fr 62px;
        align-items: center;
    }

    .sendForm textarea {
        width: 100%;
    }

    .selectedFileName {
        display: block;
        font-size: 12px;
    }
}