/* Mimo web chat prototype */

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body.chat-body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    color: #1a1d21;
    background: #f3f4f6;
}

button,
textarea {
    font: inherit;
}

/* —— layout —— */

.chat-app {
    display: flex;
    height: 100vh;
    min-height: 0;
}

.chat-sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #1e232b;
    color: #d7dbe2;
    border-right: 1px solid #14181e;
}

.chat-sidebar__head {
    padding: 16px 14px 12px;
    border-bottom: 1px solid #2a313c;
}

.chat-brand {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin-bottom: 12px;
    color: #fff;
}

.chat-brand span {
    color: #6cb2ff;
    font-weight: 500;
    margin-left: 4px;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-list__empty {
    padding: 16px 10px;
    color: #8b93a1;
    font-size: 13px;
    line-height: 1.5;
}

.chat-list__group {
    padding: 12px 10px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #8b93a1;
}

.chat-list__group:first-child {
    padding-top: 4px;
}

/* --- user groups (todos №8) --- */

.chat-list__gcreate {
    display: flex;
    gap: 4px;
    margin: 6px 4px 2px;
}

.chat-list__gcreate-input {
    flex: 1;
    min-width: 0;
    background: #1c2128;
    border: 1px solid #2a313c;
    border-radius: 6px;
    color: #d7dbe2;
    font-size: 12px;
    padding: 5px 8px;
}

.chat-list__gcreate-input::placeholder {
    color: #5c6573;
}

.chat-list__gcreate-input:focus {
    outline: none;
    border-color: #3d4c61;
}

.chat-list__gcreate-btn {
    background: #2a313c;
    border: 1px solid #3d4c61;
    border-radius: 6px;
    color: #d7dbe2;
    font-size: 13px;
    padding: 0 9px;
    cursor: pointer;
}

.chat-list__gcreate-btn:hover {
    background: #343e4c;
}

.chat-list__gsection {
    position: relative;
}

.chat-list__gcheck {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.chat-list__gbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 12px 6px 4px 6px;
}

.chat-list__gtoggle {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    font-size: 10px;
    color: #8b93a1;
    cursor: pointer;
    user-select: none;
    transition: transform .12s ease;
}

.chat-list__gcheck:checked ~ .chat-list__gbar .chat-list__gtoggle {
    transform: rotate(90deg);
}

.chat-list__gcheck:not(:checked) ~ .chat-list__gitems {
    display: none;
}

.chat-list__gform {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    margin: 0;
}

.chat-list__gname {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #8b93a1;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 4px;
}

.chat-list__gname:hover {
    border-color: #2a313c;
    background: #1c2128;
}

.chat-list__gname:focus {
    outline: none;
    border-color: #3d4c61;
    background: #1c2128;
    color: #d7dbe2;
}

.chat-list__gbtn {
    flex-shrink: 0;
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: #5c6573;
    font-size: 11px;
    line-height: 1;
    padding: 3px 5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s ease, color .12s ease;
}

.chat-list__gbar:hover .chat-list__gbtn,
.chat-list__gform:focus-within .chat-list__gbtn {
    opacity: 1;
}

.chat-list__gbtn:hover {
    color: #6cb2ff;
}

.chat-list__gbtn--del:hover {
    color: #ff6b6b;
}

.chat-list__gempty {
    padding: 4px 12px 6px;
    color: #5c6573;
    font-size: 11px;
    font-style: italic;
}

/* move-chat-to-group dropdown (📁) */

.chat-list__move {
    position: absolute;
    top: 50%;
    right: 50px;
    transform: translateY(-50%);
    z-index: 2;
}

.chat-list__move-btn {
    display: block;
    font-size: 12px;
    line-height: 1;
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s ease;
    filter: grayscale(1) opacity(.7);
}

.chat-list__entry:hover .chat-list__move-btn,
.chat-list__move[open] .chat-list__move-btn,
.chat-list__move:focus-within .chat-list__move-btn {
    opacity: 1;
}

.chat-list__move[open] .chat-list__move-btn {
    filter: none;
}

.chat-list__move-form {
    position: absolute;
    top: calc(100% + 4px);
    right: -8px;
    margin: 0;
    background: #232933;
    border: 1px solid #3d4c61;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    z-index: 3;
}

.chat-list__move-form select {
    background: #1c2128;
    border: 1px solid #2a313c;
    border-radius: 6px;
    color: #d7dbe2;
    font-size: 12px;
    padding: 4px 6px;
    min-width: 150px;
}

.chat-list__move-form select:focus {
    outline: none;
    border-color: #3d4c61;
}

.chat-list__entry {
    position: relative;
    margin-bottom: 4px;
}

.chat-list__item {
    display: block;
    padding: 10px 74px 10px 12px;
    border-radius: 8px;
    color: #d7dbe2;
    text-decoration: none;
    border: 1px solid transparent;
}

.chat-list__item:hover {
    background: #2a313c;
}

/* lighter plate = chat belongs to a user group */
.chat-list__item.is-grouped {
    background: #252c37;
}

.chat-list__item.is-grouped:hover {
    background: #2c3441;
}

.chat-list__item.is-active {
    background: #2f3a4a;
    border-color: #3d4c61;
}

/* spinner next to title while the session has an open overlay run */
.chat-list__item.is-running .chat-list__title::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border: 2px solid #6cb2ff;
    border-top-color: transparent;
    border-radius: 50%;
    vertical-align: middle;
    animation: chat-list-spin .7s linear infinite;
}

@keyframes chat-list-spin {
    to {
        transform: rotate(360deg);
    }
}

/* another session finished while this page is open — attract attention until opened */
.chat-list__item.is-finished {
    background: #1f2a24;
    box-shadow: inset 3px 0 0 #3dd68c;
}

.chat-list__item.is-finished:hover {
    background: #24312a;
}

.chat-list__item.is-finished .chat-list__title::after {
    content: '·';
    margin-left: 6px;
    color: #3dd68c;
    font-weight: 700;
}

.chat-list__star-form {
    position: absolute;
    top: 50%;
    right: 28px;
    transform: translateY(-50%);
    margin: 0;
    z-index: 1;
}

.chat-list__star {
    background: transparent;
    border: 0;
    color: #5c6573;
    font-size: 13px;
    line-height: 1;
    padding: 4px 4px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s ease, color .12s ease;
}

.chat-list__entry:hover .chat-list__star,
.chat-list__star-form:focus-within,
.chat-list__star.is-on {
    opacity: 1;
}

.chat-list__star:hover {
    background: #3a3527;
    color: #f0b429;
}

.chat-list__star.is-on {
    color: #f0b429;
}

.chat-list__del-form {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    margin: 0;
    opacity: 0;
    transition: opacity .12s ease;
    z-index: 1;
}

.chat-list__entry:hover .chat-list__del-form,
.chat-list__del-form:focus-within {
    opacity: 1;
}

.chat-list__del {
    background: transparent;
    border: 0;
    color: #8b93a1;
    font-size: 12px;
    line-height: 1;
    padding: 4px 5px;
    border-radius: 4px;
    cursor: pointer;
}

.chat-list__del:hover {
    background: #3a2f33;
    color: #ff6b6b;
}

.chat-list__title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13.5px;
}

.chat-list__row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-top: 2px;
}

.chat-list__time {
    display: block;
    font-size: 11px;
    color: #8b93a1;
    flex-shrink: 0;
}

.chat-list__tokens {
    display: block;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: #6cb2ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list__tokens.is-empty {
    color: #5c6573;
}

.chat-sidebar__foot {
    padding: 10px 14px;
    border-top: 1px solid #2a313c;
    font-size: 11px;
    color: #8b93a1;
}

.chat-auth-stub {
    opacity: 0.8;
}

.chat-auth {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-auth__user {
    color: #d7dbe2;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-auth__logout,
.chat-auth__login {
    background: none;
    border: none;
    padding: 0;
    color: #6cb2ff;
    font-size: 11px;
    cursor: pointer;
    text-decoration: none;
}

.chat-auth__logout:hover,
.chat-auth__login:hover {
    text-decoration: underline;
}

/* —— main —— */

.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #f3f4f6;
}

.chat-header {
    padding: 14px 20px;
    background: #fff;
    border-bottom: 1px solid #e2e5ea;
}

.chat-header__title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header__meta {
    margin-top: 2px;
    font-size: 12px;
    color: #6b7280;
}

.chat-header__meta code {
    font-size: 11px;
    background: #f0f2f5;
    padding: 1px 5px;
    border-radius: 4px;
}

.chat-tokens {
    color: #1d4ed8;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 12px;
}

.chat-log__hint {
    color: #6b7280;
    font-size: 13px;
    margin-top: 8px;
}

.msg {
    max-width: 760px;
    margin: 0 0 14px;
}

.msg--user {
    margin-left: auto;
}

/* d.m.Y H:i under question/answer bubbles */
.msg__time {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    line-height: 1.3;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
}

.msg--user .msg__time {
    text-align: right;
}

.msg__body {
    padding: 10px 14px;
    border-radius: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg--user .msg__body {
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg--assistant .msg__body {
    background: #fff;
    border: 1px solid #e2e5ea;
    border-bottom-left-radius: 4px;
    /* HTML from markdown — block layout, not pre-wrap plain text */
    white-space: normal;
}

/* markdown inside assistant bubbles */
.msg--assistant .msg__body > :first-child {
    margin-top: 0;
}

.msg--assistant .msg__body > :last-child {
    margin-bottom: 0;
}

.msg--assistant .msg__body p {
    margin: 0 0 0.6em;
}

.msg--assistant .msg__body h1,
.msg--assistant .msg__body h2,
.msg--assistant .msg__body h3,
.msg--assistant .msg__body h4 {
    margin: 0.9em 0 0.4em;
    line-height: 1.3;
    color: #111827;
}

.msg--assistant .msg__body h1 { font-size: 1.25em; }
.msg--assistant .msg__body h2 { font-size: 1.15em; }
.msg--assistant .msg__body h3 { font-size: 1.05em; }

.msg--assistant .msg__body ul,
.msg--assistant .msg__body ol {
    margin: 0.4em 0 0.6em;
    padding-left: 1.3em;
}

.msg--assistant .msg__body li {
    margin: 0.15em 0;
}

.msg--assistant .msg__body code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.92em;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 0.05em 0.35em;
}

.msg--assistant .msg__body pre {
    margin: 0.5em 0;
    padding: 10px 12px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.45;
}

.msg--assistant .msg__body pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.msg--assistant .msg__body a {
    color: #1d4ed8;
}

.msg--assistant .msg__body blockquote {
    margin: 0.5em 0;
    padding: 0.2em 0 0.2em 0.9em;
    border-left: 3px solid #d1d5db;
    color: #6b7280;
}

.msg--assistant .msg__body table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.95em;
}

.msg--assistant .msg__body th,
.msg--assistant .msg__body td {
    border: 1px solid #e5e7eb;
    padding: 4px 8px;
    text-align: left;
}

.msg--assistant .msg__body th {
    background: #f9fafb;
    font-weight: 600;
}

.msg--assistant .msg__body hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 0.8em 0;
}

.msg--error .msg__body {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* outbox download chips under assistant bubbles */
.msg__files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    max-width: 760px;
}

.msg__file {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    max-width: 100%;
    padding: 5px 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1d4ed8;
    font-size: 13px;
    text-decoration: none;
    word-break: break-all;
}

.msg__file:hover {
    background: #dbeafe;
}

.msg__file-name {
    font-weight: 600;
}

.msg__file-size {
    color: #6b7280;
    font-size: 12px;
    flex-shrink: 0;
}

/* live progress block */

.msg-progress {
    max-width: 760px;
    margin: 0 0 14px;
    background: #111827;
    color: #a7f3d0;
    border-radius: 12px;
    border: 1px solid #1f2937;
    overflow: hidden;
}

.msg-progress__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: #9ca3af;
    background: #0b1220;
    border-bottom: 1px solid #1f2937;
}

.msg-progress__meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.msg-progress__meta .msg__time {
    display: inline;
    margin: 0;
    color: #6b7280;
}

.msg-progress__body {
    padding: 10px 12px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    max-height: 220px;
    overflow-y: auto;
    /* normal: lines are single-line spans — pre-wrap renders HTML indent between them */
    white-space: normal;
    word-break: break-word;
}

.msg-progress__line {
    display: block;
    margin: 0;
    padding: 0;
}

.msg-progress__line--tool {
    color: #93c5fd;
}

.msg-progress__line--text {
    color: #fde68a;
}

.msg-progress.is-done .msg-progress__body {
    color: #6b7280;
}

.msg-progress.is-error .msg-progress__body {
    color: #fca5a5;
}

/* typing dots — JS sets msg msg--typing (was .msg-typing: styles never applied) */

.msg--typing .msg__body {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    background: #fff;
    border: 1px solid #e2e5ea;
    color: #6b7280;
    font-size: 12px;
}

.msg--typing .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: bounce 1.2s infinite ease-in-out;
}

.msg--typing .dot:nth-child(2) {
    animation-delay: 0.15s;
}

.msg--typing .dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    0%,
    80%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* —— composer —— */

.chat-composer {
    padding: 12px 16px 16px;
    background: #fff;
    border-top: 1px solid #e2e5ea;
}

.chat-composer form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 900px;
}

.chat-composer textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 160px;
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    outline: none;
    background: #f9fafb;
}

.chat-composer textarea:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-composer textarea:disabled {
    opacity: 0.6;
}

/* —— buttons —— */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 13.5px;
    text-decoration: none;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.btn[hidden] {
    display: none;
}

.btn--primary {
    background: #2563eb;
    color: #fff;
}

.btn--primary:hover {
    background: #1d4ed8;
}

.btn--primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn--stop {
    background: #dc2626;
    color: #fff;
}

.btn--stop:hover {
    background: #b91c1c;
}

.btn--block {
    width: 100%;
}

/* —— empty state —— */

.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.chat-empty__card {
    background: #fff;
    border: 1px solid #e2e5ea;
    border-radius: 16px;
    padding: 28px 32px;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.chat-empty__card h2 {
    margin: 0 0 8px;
    font-size: 18px;
}

.chat-empty__card p {
    margin: 0 0 6px;
    color: #4b5563;
}

.chat-empty__hint {
    font-size: 13px;
    color: #6b7280 !important;
}

/* —— login (dark shell, same family as sidebar) —— */

body.login-body {
    background: #14181e;
    min-height: 100vh;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: #1e232b;
    color: #d7dbe2;
    border: 1px solid #2a313c;
    border-radius: 16px;
    padding: 28px 28px 24px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.login-card__brand {
    margin-bottom: 6px;
    font-size: 18px;
}

.login-card__hint {
    margin: 0 0 20px;
    font-size: 13px;
    color: #8b93a1;
}

.login-form .form-group {
    margin-bottom: 14px;
}

.login-form .form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #3d4c61;
    border-radius: 10px;
    background: #14181e;
    color: #e8eaed;
    font: inherit;
    outline: none;
}

.login-form .form-control::placeholder {
    color: #5c6573;
}

.login-form .form-control:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
    background: #1a1f27;
}

.login-form .has-error .form-control {
    border-color: #dc2626;
}

.login-form .help-block {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #f87171;
}

.login-form__row--check {
    margin-bottom: 16px;
}

.login-form__check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #8b93a1;
    cursor: pointer;
    user-select: none;
}

.login-form__check input {
    width: 14px;
    height: 14px;
    accent-color: #2563eb;
    margin: 0;
}

.login-form__submit {
    padding-top: 11px;
    padding-bottom: 11px;
    font-size: 14px;
}

/* —— narrow screens —— */

@media (max-width: 720px) {
    .chat-app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .chat-sidebar {
        width: 100%;
        max-height: 40vh;
    }

    .chat-log {
        padding: 14px 12px;
    }

    .msg,
    .msg-progress {
        max-width: 100%;
    }

    .login-card {
        padding: 22px 18px 18px;
    }
}
