:root {
    --ink: #071526;
    --panel: #0d2238;
    --panel-2: #132d47;
    --line: rgba(159, 205, 230, .18);
    --text: #f6fbff;
    --muted: #9fb5c9;
    --cyan: #18b8d9;
    --yellow: #ffca3a;
    --green: #35d07f;
    --red: #ff6577;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--ink); color-scheme: dark; }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: "Barlow", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 12% 0%, rgba(24, 184, 217, .16), transparent 30rem),
        radial-gradient(circle at 100% 100%, rgba(255, 202, 58, .1), transparent 28rem),
        var(--ink);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
    width: min(1180px, 100%);
    min-height: 100vh;
    margin: auto;
    padding: 18px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 15px 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(13, 34, 56, .88);
    box-shadow: 0 18px 55px rgba(0, 0, 0, .22);
}

.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--yellow);
    color: var(--ink);
    font-weight: 900;
    font-size: 19px;
}
.brand strong { display: block; font-size: 18px; }
.brand span { display: block; color: var(--muted); font-size: 12px; }

.btn {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    background: var(--panel-2);
    color: var(--text);
    font-weight: 800;
    text-decoration: none;
}
.btn.primary { background: var(--cyan); color: #03131d; border-color: transparent; }
.btn.warn { background: var(--yellow); color: #201900; border-color: transparent; }
.btn.success { background: var(--green); color: #052317; border-color: transparent; }
.btn.danger { background: rgba(255, 101, 119, .12); color: #ff9eaa; border-color: rgba(255, 101, 119, .35); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.card {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(13, 34, 56, .88);
    box-shadow: 0 22px 70px rgba(0, 0, 0, .2);
}

.form-card {
    width: min(720px, 100%);
    margin: 30px auto;
    padding: clamp(20px, 5vw, 38px);
}
.form-card h1 { margin: 0 0 8px; font-size: clamp(28px, 5vw, 46px); line-height: 1; }
.form-card > p { color: var(--muted); line-height: 1.6; }
.field { margin-top: 16px; }
.field label { display: block; margin-bottom: 7px; color: #cfe0ee; font-size: 13px; font-weight: 800; }
.field input, .field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    background: rgba(3, 15, 28, .7);
    outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(24, 184, 217, .12); }
.field textarea { min-height: 125px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.notice { margin: 16px 0; padding: 12px 14px; border-radius: 12px; background: rgba(255, 202, 58, .09); color: #ffe491; border: 1px solid rgba(255, 202, 58, .25); }
.resume-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 14px 0; }
.resume-notice > div { min-width: 0; }
.resume-notice strong, .resume-notice span { display: block; }
.resume-notice span { margin-top: 3px; color: #eadba7; font-size: 12px; line-height: 1.35; }
.resume-notice .btn { flex: 0 0 auto; padding: 8px 11px; font-size: 12px; }
.error { margin-top: 12px; color: #ff9eaa; font-weight: 700; }

.chat-layout {
    display: grid;
    grid-template-columns: 350px minmax(0, 1fr);
    gap: 14px;
    height: calc(100vh - 114px);
    margin-top: 14px;
}
.sidebar, .chat { min-height: 0; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.tab { border: 0; border-radius: 10px; padding: 10px; color: var(--muted); background: rgba(255,255,255,.035); font-weight: 800; }
.tab.active { color: var(--ink); background: var(--yellow); }
.list { padding: 10px; overflow: auto; }
.ticket {
    width: 100%;
    margin-bottom: 8px;
    border: 1px solid transparent;
    border-radius: 13px;
    padding: 12px;
    text-align: left;
    color: var(--text);
    background: rgba(255, 255, 255, .04);
}
.ticket:hover, .ticket.active { border-color: var(--cyan); background: rgba(24, 184, 217, .08); }
.ticket strong { display: flex; justify-content: space-between; gap: 10px; }
.ticket p { margin: 7px 0; color: #c6d7e5; line-height: 1.3; }
.ticket small { color: var(--muted); }
.count { min-width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 99px; background: var(--red); color: white; font-size: 11px; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }

.chat { display: flex; flex-direction: column; }
.chat-head { padding: 14px 17px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.mobile-back {
    display: none;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 28px;
    line-height: 1;
}
.chat-head h2 { margin: 0; font-size: 18px; }
.chat-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: min(78%, 680px); padding: 11px 13px; border-radius: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.usuario { align-self: flex-start; background: #183b59; border-bottom-left-radius: 4px; }
.message.operador { align-self: flex-end; background: #087f9a; border-bottom-right-radius: 4px; }
.message.sistema { align-self: center; max-width: 90%; color: #f9dd81; background: rgba(255, 202, 58, .08); font-size: 12px; text-align: center; }
.message small { display: block; margin-top: 5px; color: rgba(255,255,255,.62); font-size: 10px; }
.composer { display: flex; gap: 9px; padding: 12px; border-top: 1px solid var(--line); }
.compose-input { flex: 1; min-width: 0; }
.composer textarea { width: 100%; min-height: 46px; max-height: 130px; resize: vertical; border: 1px solid var(--line); border-radius: 13px; padding: 11px; background: rgba(3,15,28,.72); color: var(--text); }
.attach-button { min-width: 74px; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; align-self: flex-start; border: 1px solid var(--line); border-radius: 13px; padding: 9px; color: var(--text); background: var(--panel-2); font-weight: 800; cursor: pointer; }
.attach-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.attach-button span:first-of-type { font-size: 21px; line-height: 1; color: var(--yellow); }
.file-name { display: block; max-width: 100%; padding: 3px 4px 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.file-name:empty { display: none; }
.message-attachment { display: block; margin-top: 8px; color: inherit; }
.message-attachment img { display: block; width: auto; max-width: min(100%, 420px); max-height: 360px; border-radius: 10px; object-fit: contain; background: rgba(0,0,0,.2); }

.user-chat { width: min(820px, 100%); height: calc(100vh - 36px); margin: 18px auto; display: flex; flex-direction: column; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border-radius: 99px; color: var(--muted); background: rgba(255,255,255,.05); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); }
.status-dot.assigned { background: var(--green); }

@media (max-width: 560px) {
    .resume-notice { align-items: stretch; flex-direction: column; gap: 8px; }
    .resume-notice .btn { width: 100%; }
}

@media (max-width: 780px) {
    body.operator-page { height: 100dvh; min-height: 100dvh; overflow: hidden; }
    .operator-page .shell {
        height: 100dvh;
        min-height: 0;
        padding: 7px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .operator-page .topbar {
        flex: 0 0 auto;
        min-height: 62px;
        padding: 9px 10px;
        border-radius: 14px;
    }
    .operator-page .brand { min-width: 0; gap: 8px; }
    .operator-page .brand-mark { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
    .operator-page .brand strong { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
    .operator-page .brand span { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
    .operator-page .top-actions { gap: 4px; flex-wrap: nowrap; }
    .operator-page .top-actions .btn { padding: 7px 8px; border-radius: 9px; font-size: 10px; }
    .operator-page .chat-layout {
        flex: 1 1 auto;
        min-height: 0;
        display: block;
        height: auto;
        margin-top: 7px;
    }
    .operator-page .sidebar { display: flex; height: 100%; border-radius: 14px; }
    .operator-page .chat { display: none; height: 100%; border-radius: 14px; }
    .operator-page.chat-open .sidebar { display: none; }
    .operator-page.chat-open .chat { display: flex; }
    .operator-page .tabs { padding: 8px; }
    .operator-page .tab { padding: 9px 7px; font-size: 12px; }
    .operator-page .list { padding: 8px; }
    .operator-page .ticket { margin-bottom: 7px; padding: 11px; }
    .operator-page .chat-head { min-height: 62px; padding: 9px; align-items: center; }
    .operator-page .chat-head > div { min-width: 0; flex: 1; }
    .operator-page .chat-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
    .operator-page .chat-head p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .operator-page .chat-head .btn { padding: 8px; font-size: 10px; }
    .operator-page .mobile-back { display: block; }
    .operator-page .messages { padding: 10px; gap: 8px; }
    .operator-page .message { max-width: 88%; padding: 9px 11px; font-size: 14px; }
    .operator-page .composer {
        flex: 0 0 auto;
        align-items: flex-end;
        padding: 8px 8px max(8px, env(safe-area-inset-bottom));
        gap: 7px;
        background: rgba(7, 21, 38, .96);
    }
    .operator-page .composer textarea {
        min-height: 44px;
        max-height: 96px;
        padding: 10px;
        resize: none;
    }
    .operator-page .attach-button { min-width: 44px; width: 44px; padding: 7px; }
    .operator-page .attach-text { display: none; }
    .operator-page .composer .btn { min-height: 44px; padding: 9px 12px; }
    .grid-2 { grid-template-columns: 1fr; }
    .message { max-width: 88%; }
    .user-chat { height: calc(100vh - 16px); margin: 8px auto; border-radius: 14px; }
}

@media (max-width: 390px) {
    .operator-page .brand span { display: none; }
    .operator-page .brand strong { max-width: 108px; }
    .operator-page .top-actions .btn { padding: 7px 6px; font-size: 9px; }
}
