:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #1d242b;
    --muted: #5b6773;
    --line: #d8dee4;
    --accent: #0b7a75;
    --accent-hover: #09645f;
    --danger: #c0392b;
    --success: #198754;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #f9fbfc 0%, #eef2f5 100%);
}

a {
    color: #0d5f92;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #0e1f2f;
    color: #fff;
}

.topbar nav {
    display: flex;
    gap: 16px;
    flex-wrap: nowrap;
}

.topbar nav a {
    display: inline-block;
    color: #e4edf6;
    white-space: nowrap;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.3px;
}

.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    padding: 16px;
}

.single {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}

.sidebar,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
}

.sidebar {
    min-width: 0;
    overflow: hidden;
}

.content {
    display: grid;
    gap: 16px;
}

.chat-screen {
    min-height: calc(100vh - 120px);
}

.chat-history-panel {
    display: block;
    min-height: 0;
}

.thread-list {
    list-style: none;
    padding: 0;
    margin: 0;
    min-width: 0;
}

.thread-list li {
    margin-bottom: 6px;
    min-width: 0;
}

.thread-item {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.thread-link {
    display: block;
    flex: 1 1 0%;
    width: 0;
    min-width: 0;
    max-width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-link.active {
    border-color: #94c0d8;
    background: #e9f4fb;
}

.thread-edit-btn {
    width: auto;
    margin-top: 0;
    padding: 6px 8px;
    font-size: 12px;
    border: 1px solid #c6d0da;
    border-radius: 6px;
    background: #fff;
    color: #42515e;
    cursor: pointer;
    flex: 0 0 auto;
}

.thread-edit-btn:hover {
    background: #f2f6fa;
}

label {
    display: block;
    margin-bottom: 12px;
    font-size: 14px;
}

input,
select,
textarea,
button {
    width: 100%;
    margin-top: 6px;
    border: 1px solid #c6d0da;
    border-radius: 6px;
    padding: 9px 10px;
    font-size: 14px;
    background: #fff;
}

textarea {
    resize: vertical;
}

button,
.button {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    width: auto;
    padding: 10px 16px;
    border-radius: 6px;
}

button:hover,
.button:hover {
    background: var(--accent-hover);
    text-decoration: none;
}

.button.secondary {
    background: #4b5b68;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.message-list {
    display: grid;
    gap: 12px;
}

.chat-history-panel .message-list {
    overflow: visible;
    padding-right: 0;
}

.message-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfdff;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.generated-box {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.job-progress {
    margin-top: 10px;
}

.job-progress-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: #dfe7ee;
    overflow: hidden;
}

.job-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #1c91c6 0%, #0b7a75 100%);
    width: 0;
    transition: width 0.35s ease;
}

.job-progress-text,
.job-progress-meta {
    margin: 6px 0 0;
}

.generated-box img {
    max-width: 280px;
    max-height: 180px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.preview-wrap img,
.inline-preview {
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

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

.checkbox input {
    width: auto;
    margin: 0;
}

.alert {
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
}

.alert.error {
    background: #fdecea;
    color: var(--danger);
    border: 1px solid #f5c2bd;
}

.alert.success {
    background: #e9f8ef;
    color: var(--success);
    border: 1px solid #b9e5c8;
}

.alert.warning {
    background: #fff7e6;
    color: #8a5b00;
    border: 1px solid #f2d5a5;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

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

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 24px;
}

.composer-panel {
    position: fixed;
    right: 20px;
    bottom: 76px;
    width: min(840px, calc(100vw - 360px));
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    overflow: auto;
    z-index: 1200;
    border-radius: 16px;
    border-color: #ccdae6;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbfe 100%);
    box-shadow: 0 10px 28px rgba(12, 31, 54, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px) scale(0.98);
    transform-origin: right bottom;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.composer-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.composer-launcher-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1250;
    width: auto;
    margin: 0;
    border-radius: 999px;
    padding: 12px 18px;
    font-weight: 600;
    box-shadow: 0 10px 20px rgba(10, 30, 52, 0.18);
}

.composer-panel-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.composer-panel-header h2 {
    margin: 0;
}

.composer-panel-body {
    display: grid;
    gap: 8px;
}

.chat-composer-form {
    display: grid;
    gap: 10px;
}

.composer-meta-row {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.composer-meta-field {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
}

.composer-meta-field span {
    display: block;
    margin-bottom: 4px;
}

.composer-meta-field select {
    margin-top: 0;
    padding: 8px 12px;
    border-radius: 999px;
    background: #f8fbff;
}

.composer-file-input {
    display: none;
}

.composer-text-wrap {
    border: 1px solid #c3d1df;
    border-radius: 16px;
    background: #fff;
    padding: 8px 10px;
    box-shadow: inset 0 1px 0 #ffffff;
}

.composer-textarea {
    margin: 0;
    padding: 4px;
    border: none;
    border-radius: 10px;
    resize: none;
    min-height: 96px;
    max-height: 260px;
    background: transparent;
}

.composer-textarea:focus {
    outline: none;
}

.composer-tools-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.composer-tool-button {
    width: auto;
    margin: 0;
    border: 1px solid #bfccd8;
    border-radius: 999px;
    background: #ffffff;
    color: #314254;
    padding: 8px 12px;
}

.composer-tool-button:hover {
    background: #eef4fa;
}

.composer-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 7px 12px;
    border: 1px solid #bfccd8;
    border-radius: 999px;
    background: #ffffff;
    font-size: 13px;
}

.composer-toggle input {
    width: 16px;
    margin: 0;
}

.composer-files-meta {
    flex: 1 1 200px;
    min-width: 120px;
    font-size: 12px;
    color: var(--muted);
}

.composer-send-button {
    width: auto;
    margin: 0 0 0 auto;
    border-radius: 999px;
    padding: 10px 20px;
    font-weight: 600;
}

.composer-send-button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.composer-file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.composer-file-chip {
    display: inline-block;
    max-width: 100%;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid #c8d9e8;
    background: #eaf2fb;
    color: #27445e;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.composer-helper {
    margin: 0;
}

@media (max-width: 960px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
    }

    .topbar nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .topbar nav a {
        display: block;
        text-align: center;
        padding: 8px 6px;
        border-radius: 6px;
        border: 1px solid rgba(255, 255, 255, 0.16);
        background: rgba(255, 255, 255, 0.06);
        overflow: hidden;
        text-overflow: ellipsis;
    }

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

    .grid.two,
    .grid.three,
    .grid.four {
        grid-template-columns: 1fr;
    }

    .chat-screen {
        min-height: auto;
    }

    .chat-history-panel .message-list {
        max-height: none;
    }

    .composer-panel {
        left: 10px;
        right: 10px;
        bottom: 66px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 140px);
    }

    .composer-launcher-btn {
        right: 10px;
        bottom: 10px;
        padding: 11px 15px;
    }

    .composer-panel-header {
        align-items: center;
    }

    .composer-meta-row {
        grid-template-columns: 1fr;
    }

    .composer-files-meta {
        flex-basis: 100%;
    }

    .composer-send-button {
        width: 100%;
        margin-left: 0;
    }
}
