* {
    box-sizing: border-box
}

:root {
    --sidebar-width: 292px;
    --topbar-height: 68px;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --panel-strong: #eef2f7;
    --text: #111827;
    --muted: #667085;
    --muted-2: #98a2b3;
    --line: #e5e9f0;
    --line-strong: #d8dee8;
    --accent: #5b5ce2;
    --accent-2: #7c3aed;
    --accent-soft: #eeefff;
    --success: #079455;
    --danger: #d92d20;
    --sidebar: #111827;
    --sidebar-2: #182230;
    --sidebar-line: rgba(255, 255, 255, .09);
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-sm: 0 4px 14px rgba(16, 24, 40, .07);
    --shadow-md: 0 12px 32px rgba(16, 24, 40, .11);
    --shadow-lg: 0 24px 64px rgba(16, 24, 40, .16);
    --radius-sm: 12px;
    --radius: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Noto Sans JP", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    overflow: hidden
}

button,
input,
textarea,
select {
    font: inherit
}

button {
    touch-action: manipulation
}

a {
    color: inherit
}

img {
    max-width: 100%;
    height: auto
}

.hidden {
    display: none !important
}

.mobile-only {
    display: none
}

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell {
    min-height: 100dvh;
    background: var(--bg)
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 18px 16px 16px;
    color: #fff;
    background:
        radial-gradient(circle at 18% 0%, rgba(99, 102, 241, .23), transparent 32%),
        linear-gradient(180deg, #151b28 0%, #101722 100%);
    border-right: 1px solid rgba(255, 255, 255, .05);
    z-index: 40;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 46px;
    flex: 0 0 auto;
}

.brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding-left: 48px;
    min-height: 38px;
    font-size: 17px;
    font-weight: 850;
    letter-spacing: -.02em;
}

.brand::before {
    content: "✦";
    position: absolute;
    left: 0;
    top: 0;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #fff;
    font-size: 18px;
    background: linear-gradient(135deg, #7c3aed 0%, #5b5ce2 52%, #3b82f6 100%);
    box-shadow: 0 8px 22px rgba(91, 92, 226, .34), inset 0 1px 0 rgba(255, 255, 255, .28);
}

.new-chat-btn,
.side-link {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--sidebar-line);
    border-radius: 14px;
    padding: 10px 12px;
    color: #e5e7eb;
    background: rgba(255, 255, 255, .045);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease, transform .16s ease, color .16s ease;
}

.new-chat-btn {
    margin: 18px 0 14px;
    color: #fff;
    font-weight: 750;
    border-color: rgba(255, 255, 255, .13);
    background: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .07));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

.new-chat-btn:hover,
.side-link:hover {
    background: rgba(255, 255, 255, .09);
    border-color: rgba(255, 255, 255, .16)
}

.new-chat-btn:active,
.side-link:active {
    transform: scale(.985)
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #3b4657 transparent;
    padding-right: 2px;
}

.chat-item {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 12px;
    padding: 10px 12px 10px 34px;
    color: #b8c0cc;
    background: transparent;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background .15s ease, color .15s ease;
}

.chat-item::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    width: 7px;
    height: 7px;
    border: 1.5px solid #667085;
    border-radius: 50%;
    transform: translateY(-50%);
}

.chat-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #f8fafc
}

.chat-item.active {
    background: rgba(99, 102, 241, .18);
    color: #fff;
    font-weight: 700
}

.chat-item.active::before {
    border-color: #a5b4fc;
    background: #818cf8;
    box-shadow: 0 0 0 4px rgba(129, 140, 248, .13)
}

.side-bottom {
    margin-top: auto;
    display: grid;
    gap: 8px;
    flex: 0 0 auto;
    padding-top: 14px;
    background: linear-gradient(180deg, rgba(16, 23, 34, 0), #101722 18%);
}

.sidebar-credit-card {
    padding: 13px;
    margin-bottom: 2px;
    border: 1px solid rgba(129, 140, 248, .24);
    border-radius: 17px;
    background: linear-gradient(145deg, rgba(99, 102, 241, .18), rgba(255, 255, 255, .055));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}

.credit-balance-label {
    margin-bottom: 4px;
    color: #aab4c3;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em
}

.credit-balance-value {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 10px;
    color: #fff
}

.credit-balance-value strong {
    font-size: 28px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: -.04em
}

.credit-balance-value span {
    font-size: 12px;
    color: #cbd5e1
}

.credit-buy-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 37px;
    padding: 8px 10px;
    border-radius: 11px;
    color: #fff;
    background: rgba(255, 255, 255, .11);
    text-decoration: none;
    font-size: 12px;
    font-weight: 800;
    transition: background .15s ease;
}

.credit-buy-link:hover {
    background: rgba(255, 255, 255, .16)
}

.danger-link {
    color: #fda29b;
    background: rgba(217, 45, 32, .08);
    border-color: rgba(240, 68, 56, .16)
}

.danger-link:hover {
    color: #fff;
    background: rgba(217, 45, 32, .16);
    border-color: rgba(240, 68, 56, .25)
}

.danger-link:disabled {
    opacity: .55;
    cursor: not-allowed
}

.main-panel {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    height: 100dvh;
    min-width: 0;
    display: grid;
    grid-template-rows: var(--topbar-height) minmax(0, 1fr) auto;
    overflow: hidden;
    background: var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 0 24px;
    border-bottom: 1px solid rgba(216, 222, 232, .85);
    background: rgba(255, 255, 255, .86);
    backdrop-filter: saturate(160%) blur(18px);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
    z-index: 20;
}

.topbar>div {
    position: relative;
    flex: 1;
    min-width: 0;
    padding-left: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -.01em;
}

.topbar>div::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #12b76a;
    box-shadow: 0 0 0 4px #ecfdf3;
    transform: translateY(-50%);
}

.ghost-btn,
.icon-btn,
.text-btn {
    border: 0;
    background: transparent;
    cursor: pointer
}

.ghost-btn {
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: #344054;
    background: #fff;
    box-shadow: var(--shadow-xs);
    font-size: 13px;
    font-weight: 750;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.ghost-btn:hover {
    background: #f8fafc;
    border-color: #cfd6e1
}

.ghost-btn:active {
    transform: scale(.97)
}

.icon-btn {
    font-size: 24px;
    color: inherit
}

.text-btn {
    color: var(--danger);
    font-size: 13px;
    font-weight: 750
}

/* =========================================================
   CHAT / MESSAGES
   ========================================================= */
.messages {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    padding: 34px max(28px, calc((100% - 920px)/2)) 32px;
    background:
        radial-gradient(circle at 50% -10%, rgba(91, 92, 226, .055), transparent 30%),
        var(--bg);
}

.messages::-webkit-scrollbar {
    width: 10px
}

.messages::-webkit-scrollbar-thumb {
    background: #d9dee7;
    border: 3px solid var(--bg);
    border-radius: 999px
}

.empty-state {
    position: relative;
    width: min(620px, 100%);
    margin: 13vh auto 0;
    padding: 96px 24px 28px;
    text-align: center;
    color: var(--muted);
}

.empty-state::before {
    content: "✦";
    position: absolute;
    top: 0;
    left: 50%;
    width: 70px;
    height: 70px;
    display: grid;
    place-items: center;
    border-radius: 23px;
    color: #fff;
    font-size: 30px;
    background: linear-gradient(145deg, #7c3aed, #5b5ce2 56%, #3b82f6);
    box-shadow: 0 18px 45px rgba(91, 92, 226, .26), inset 0 1px 0 rgba(255, 255, 255, .28);
    transform: translateX(-50%) rotate(-3deg);
}

.empty-state h1 {
    margin: 0 0 10px;
    color: #101828;
    font-size: clamp(24px, 3vw, 32px);
    font-weight: 900;
    letter-spacing: -.045em
}

.empty-state p {
    margin: 0 auto;
    max-width: 520px;
    color: #7a8494;
    font-size: 14px;
    line-height: 1.75
}

.message {
    display: flex;
    min-width: 0;
    margin: 18px 0
}

.message.user {
    justify-content: flex-end
}

.bubble {
    min-width: 0;
    max-width: min(760px, 88%);
    border-radius: 20px;
    padding: 14px 16px
}

.user-bubble {
    color: #27255b;
    background: linear-gradient(145deg, #f0f0ff, #e9ebff);
    border: 1px solid #dfe1ff;
    border-bottom-right-radius: 7px;
    box-shadow: 0 4px 14px rgba(91, 92, 226, .07);
}

.assistant-bubble {
    width: min(760px, 94%);
    padding: 16px;
    border: 1px solid var(--line);
    border-bottom-left-radius: 7px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 4px 18px rgba(16, 24, 40, .045);
}

.message-source {
    display: block;
    width: auto;
    height: auto;
    max-width: min(230px, 100%);
    max-height: 300px;
    margin-bottom: 11px;
    border: 1px solid var(--line);
    border-radius: 15px;
    object-fit: contain;
    object-position: center;
    aspect-ratio: auto;
    background: #f2f4f7;
    box-shadow: var(--shadow-xs);
}

.message-text {
    line-height: 1.7;
    overflow-wrap: anywhere;
    font-size: 14px
}

.job-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 800;
    color: #475467
}

.job-status::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #f79009;
    box-shadow: 0 0 0 4px #fffaeb
}

.job-status.failed {
    color: #b42318
}

.job-status.failed::before {
    background: #f04438;
    box-shadow: 0 0 0 4px #fef3f2
}

.job-status.completed {
    color: #067647
}

.job-status.completed::before {
    background: #12b76a;
    box-shadow: 0 0 0 4px #ecfdf3
}

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

.result-image {
    display: block;
    min-width: 0;
    overflow: hidden;
    border-radius: 14px;
    background: #eef1f5;
    box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .04)
}

.result-image img,
.result-grid img,
.result-grid.multi img {
    display: block;
    width: 100%;
    height: auto !important;
    max-width: 100%;
    max-height: 760px;
    object-fit: contain !important;
    object-position: center;
    aspect-ratio: auto !important;
    transition: transform .2s ease, opacity .2s ease;
}

.result-image:hover img {
    transform: scale(1.008)
}

.meta {
    margin-top: 10px;
    color: var(--muted-2);
    font-size: 11px
}

.bulk-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px
}

.bulk-save-btn {
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 11px;
    color: #344054;
    background: #fff;
    box-shadow: var(--shadow-xs);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

.bulk-save-btn:hover {
    background: #f8fafc
}

.bulk-save-btn:disabled {
    opacity: .55;
    cursor: not-allowed
}

/* =========================================================
   COMPOSER
   ========================================================= */
.composer-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 12px max(24px, calc((100% - 920px)/2)) max(18px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(245, 247, 251, 0), rgba(245, 247, 251, .96) 20%, var(--bg) 42%);
    z-index: 22;
}

.upload-preview {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
    overflow: hidden;
    margin-bottom: 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow-sm);
}

.upload-preview img,
#previewImage {
    width: 56px;
    height: 56px;
    max-width: 56px;
    max-height: 56px;
    flex: 0 0 56px;
    border: 1px solid var(--line);
    border-radius: 11px;
    object-fit: contain;
    object-position: center;
    aspect-ratio: auto;
    background: #f3f5f8;
}

.upload-preview>div {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    max-width: 100%;
    overflow: hidden
}

.upload-preview strong,
#previewName {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    color: #344054
}

.upload-preview .text-btn {
    flex: 0 0 auto;
    white-space: nowrap
}

.composer {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    min-width: 0;
    max-width: 100%;
    padding: 9px;
    border: 1px solid var(--line-strong);
    border-radius: 22px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 10px 35px rgba(16, 24, 40, .10), 0 1px 2px rgba(16, 24, 40, .04);
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.composer:focus-within {
    border-color: #b9baf7;
    box-shadow: 0 0 0 4px rgba(91, 92, 226, .09), 0 12px 38px rgba(16, 24, 40, .11);
    transform: translateY(-1px);
}

.attach-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    display: grid;
    place-items: center;
    border: 1px solid #e3e7ee;
    border-radius: 14px;
    color: #475467;
    background: #f7f8fa;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}

.attach-btn:hover {
    color: #3638b5;
    background: #f0f0ff
}

.attach-btn:active {
    transform: scale(.94)
}

.composer textarea {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    max-height: 180px;
    resize: none;
    border: 0;
    outline: 0;
    padding: 10px 4px 8px;
    color: #101828;
    background: transparent;
    font-size: 15px;
    line-height: 1.5;
}

.composer textarea::placeholder {
    color: #98a2b3
}

.send-btn,
.primary-btn {
    min-height: 42px;
    border: 0;
    border-radius: 14px;
    padding: 10px 17px;
    color: #fff;
    background: linear-gradient(135deg, #6366f1 0%, #5b5ce2 48%, #7c3aed 100%);
    box-shadow: 0 8px 18px rgba(91, 92, 226, .22), inset 0 1px 0 rgba(255, 255, 255, .2);
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

.send-btn:hover,
.primary-btn:hover {
    filter: brightness(1.03);
    box-shadow: 0 10px 22px rgba(91, 92, 226, .28), inset 0 1px 0 rgba(255, 255, 255, .2)
}

.send-btn:active,
.primary-btn:active {
    transform: scale(.97)
}

.send-btn:disabled,
.primary-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    box-shadow: none
}

.options-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    margin-top: 9px;
    padding: 0 4px;
    color: #667085;
    font-size: 12px;
    flex-wrap: wrap;
}

.options-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    white-space: nowrap
}

.options-row label strong {
    font-weight: 750;
    color: #475467
}

.shortcut-btn {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid #dddff7;
    border-radius: 999px;
    color: #4b4caa;
    background: #f5f5ff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
}

.shortcut-btn:hover {
    background: #eeeeff;
    border-color: #c9caf5
}

.shortcut-btn:active {
    transform: scale(.97)
}

.options-row select {
    appearance: none;
    -webkit-appearance: none;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    outline: 0;
    padding: 6px 30px 6px 10px;
    color: #344054;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    box-shadow: var(--shadow-xs);
    font-weight: 750;
    cursor: pointer;
}

.options-row select:focus {
    border-color: #b8b9f5;
    box-shadow: 0 0 0 3px rgba(91, 92, 226, .09)
}

body.is-dragging-file .composer {
    border-color: #8b8cf0;
    box-shadow: 0 0 0 4px rgba(91, 92, 226, .12), 0 12px 38px rgba(16, 24, 40, .11)
}

/* =========================================================
   LIBRARY DRAWER
   ========================================================= */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: flex-end;
    padding: 10px;
    background: rgba(15, 23, 42, .48);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    z-index: 80;
}

.drawer {
    width: min(700px, 94vw);
    height: calc(100dvh - 20px);
    overflow: auto;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 24px;
    background: #fff;
    box-shadow: var(--shadow-lg);
}

.drawer-head {
    position: sticky;
    top: -20px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -20px -20px 0;
    padding: 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(14px)
}

.drawer-head h2 {
    margin: 0;
    font-size: 19px;
    letter-spacing: -.025em
}

.drawer-head .icon-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f8fafc;
    font-size: 24px;
    color: #475467
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 20px
}

.library-item {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-xs)
}

.library-item a {
    display: block;
    background: #f2f4f7
}

.library-item img,
.library-grid img {
    display: block;
    width: 100%;
    height: auto !important;
    max-width: 100%;
    aspect-ratio: auto !important;
    object-fit: contain !important;
    object-position: center;
    background: #f2f4f7
}

.library-item div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    color: #475467;
    font-size: 11px
}

.library-item small {
    color: #98a2b3
}

/* =========================================================
   DRAG & DROP
   ========================================================= */
.drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
    pointer-events: none;
    background: rgba(15, 23, 42, .64);
    backdrop-filter: blur(10px);
}

.drop-overlay-card {
    width: min(460px, 90vw);
    min-height: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 2px dashed rgba(255, 255, 255, .72);
    border-radius: 28px;
    color: #fff;
    background: linear-gradient(145deg, rgba(91, 92, 226, .78), rgba(17, 24, 39, .88));
    box-shadow: 0 30px 80px rgba(0, 0, 0, .28);
    text-align: center;
}

.drop-overlay-icon {
    width: 66px;
    height: 66px;
    display: grid;
    place-items: center;
    margin-bottom: 5px;
    border-radius: 20px;
    color: #4b4caa;
    background: #fff;
    font-size: 38px;
    line-height: 1;
    box-shadow: var(--shadow-md)
}

.drop-overlay-card strong {
    font-size: 21px
}

.drop-overlay-card span {
    color: #dbe1ea;
    font-size: 12px
}

/* =========================================================
   AUTH
   ========================================================= */
.auth-page {
    min-height: 100dvh;
    overflow-y: auto;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 10%, rgba(124, 58, 237, .12), transparent 28%),
        radial-gradient(circle at 90% 90%, rgba(59, 130, 246, .12), transparent 30%),
        #f5f7fb;
}

.auth-card {
    position: relative;
    width: min(430px, 100%);
    display: grid;
    gap: 16px;
    padding: 78px 30px 30px;
    border: 1px solid rgba(255, 255, 255, .85);
    border-radius: 26px;
    background: rgba(255, 255, 255, .93);
    box-shadow: 0 28px 80px rgba(16, 24, 40, .12);
    backdrop-filter: blur(18px);
}

.auth-card::before {
    content: "✦";
    position: absolute;
    top: 25px;
    left: 30px;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed, #5b5ce2, #3b82f6);
    box-shadow: 0 10px 24px rgba(91, 92, 226, .24);
}

.auth-card h1 {
    margin: 0;
    font-size: 27px;
    font-weight: 900;
    letter-spacing: -.04em
}

.auth-card label {
    display: grid;
    gap: 7px;
    color: #475467;
    font-size: 13px;
    font-weight: 700
}

.auth-card input {
    width: 100%;
    min-width: 0;
    min-height: 47px;
    padding: 11px 13px;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    outline: 0;
    color: #101828;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.auth-card input:focus {
    border-color: #b9baf7;
    box-shadow: 0 0 0 4px rgba(91, 92, 226, .09)
}

.auth-card .primary-btn {
    width: 100%;
    min-height: 48px;
    margin-top: 2px
}

.auth-card>a {
    justify-self: center;
    color: #4b4caa;
    text-decoration: none;
    font-size: 13px;
    font-weight: 800
}

.auth-card>a:hover {
    text-decoration: underline
}

.error-box {
    padding: 10px 12px;
    border: 1px solid #fecdca;
    border-radius: 12px;
    color: #b42318;
    background: #fef3f2;
    font-size: 13px
}

/* =========================================================
   CREDITS
   ========================================================= */
.credits-page {
    overflow-y: auto;
    background: #f5f7fb;
    color: #111827
}

.credits-shell {
    width: min(1000px, calc(100% - 34px));
    margin: 0 auto;
    padding: 26px 0 64px
}

.credits-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 42px
}

.back-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 11px;
    color: #475467;
    background: #fff;
    box-shadow: var(--shadow-xs);
    text-decoration: none;
    font-size: 13px;
    font-weight: 750
}

.back-link:hover {
    background: #f8fafc
}

.credits-balance-box {
    display: flex;
    align-items: baseline;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #fff;
    box-shadow: var(--shadow-xs)
}

.credits-balance-box span {
    color: #667085;
    font-size: 12px
}

.credits-balance-box strong {
    font-size: 15px;
    font-weight: 900
}

.credits-hero {
    max-width: 700px;
    margin: 0 auto 38px;
    text-align: center
}

.credits-hero .eyebrow {
    display: inline-flex;
    margin: 0 0 12px;
    padding: 6px 10px;
    border-radius: 999px;
    color: #4b4caa;
    background: #eeeeff;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .12em
}

.credits-hero h1 {
    margin: 0 0 12px;
    font-size: clamp(30px, 5vw, 44px);
    font-weight: 950;
    letter-spacing: -.055em
}

.credits-hero p:not(.eyebrow) {
    margin: 0;
    color: #667085;
    font-size: 14px;
    line-height: 1.8
}

.payment-notice {
    max-width: 760px;
    margin: 0 auto 24px;
    padding: 12px 14px;
    border-radius: 13px;
    font-size: 13px;
    font-weight: 700;
    text-align: center
}

.payment-notice.success {
    color: #067647;
    background: #ecfdf3;
    border: 1px solid #abefc6
}

.payment-notice.info {
    color: #344054;
    background: #f2f4f7;
    border: 1px solid #eaecf0
}

.credit-plan-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch
}

.credit-plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 310px;
    padding: 26px 22px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease
}

.credit-plan-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md)
}

.credit-plan-card.featured {
    border-color: #c8c9f7;
    box-shadow: 0 16px 40px rgba(91, 92, 226, .12)
}

.popular-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    box-shadow: 0 7px 18px rgba(91, 92, 226, .22);
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap
}

.plan-count {
    margin: 12px 0 20px;
    font-size: 54px;
    line-height: 1;
    font-weight: 950;
    letter-spacing: -.06em
}

.plan-count span {
    margin-left: 4px;
    color: #667085;
    font-size: 17px;
    font-weight: 800
}

.plan-price {
    margin-bottom: 7px;
    font-size: 28px;
    font-weight: 950;
    letter-spacing: -.03em
}

.plan-price span {
    margin-left: 5px;
    color: #98a2b3;
    font-size: 11px;
    font-weight: 700
}

.plan-unit {
    margin-bottom: 24px;
    color: #667085;
    font-size: 12px
}

.buy-credit-btn {
    width: 100%;
    min-height: 48px;
    margin-top: auto;
    padding: 10px 14px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #5b5ce2 50%, #7c3aed);
    box-shadow: 0 8px 18px rgba(91, 92, 226, .20);
    cursor: pointer;
    font-weight: 850
}

.buy-credit-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
    box-shadow: none
}

.credits-notes {
    max-width: 760px;
    margin: 28px auto 0;
    padding: 19px 21px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: #fff;
    box-shadow: var(--shadow-xs)
}

.credits-notes h2 {
    margin: 0 0 8px;
    font-size: 15px
}

.credits-notes p {
    margin: 0;
    color: #667085;
    font-size: 13px;
    line-height: 1.75
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width:1100px) and (min-width:821px) {
    :root {
        --sidebar-width: 248px
    }

    .sidebar {
        padding-left: 13px;
        padding-right: 13px
    }

    .messages {
        padding-left: 24px;
        padding-right: 24px
    }

    .composer-wrap {
        padding-left: 24px;
        padding-right: 24px
    }
}

@media(max-width:820px) {
    :root {
        --topbar-height: 58px
    }

    body {
        overflow: hidden
    }

    .app-shell {
        display: block;
        min-height: 100dvh
    }

    .sidebar {
        left: 0;
        top: 0;
        bottom: 0;
        width: min(86vw, 330px);
        height: 100dvh;
        z-index: 90;
        padding-top: max(16px, env(safe-area-inset-top));
        transform: translateX(-105%);
        transition: transform .22s cubic-bezier(.2, .8, .2, 1);
        box-shadow: 18px 0 48px rgba(0, 0, 0, .20);
    }

    .sidebar.open {
        transform: translateX(0)
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 85;
        display: block;
        background: rgba(15, 23, 42, .48);
        backdrop-filter: blur(4px)
    }

    .sidebar-backdrop.hidden {
        display: none !important
    }

    #closeSidebar {
        display: grid;
        width: 39px;
        height: 39px;
        min-width: 39px;
        padding: 0;
        place-items: center;
        border: 1px solid rgba(255, 255, 255, .12);
        border-radius: 12px;
        color: #fff;
        background: rgba(255, 255, 255, .07);
        font-size: 27px;
        line-height: 1
    }

    body.sidebar-open {
        overflow: hidden
    }

    .main-panel {
        margin-left: 0;
        width: 100%;
        height: 100dvh;
        grid-template-rows: var(--topbar-height) minmax(0, 1fr) auto
    }

    .mobile-only {
        display: inline-grid;
        place-items: center
    }

    #openSidebar {
        width: 38px;
        height: 38px;
        min-width: 38px;
        border: 1px solid var(--line);
        border-radius: 12px;
        color: #475467;
        background: #fff;
        font-size: 0;
        box-shadow: var(--shadow-xs)
    }

    #openSidebar::before {
        content: "";
        width: 17px;
        height: 14px;
        margin-top: 7px;
        background: linear-gradient(#475467 0 0) top/100% 1.5px no-repeat, linear-gradient(#475467 0 0) center/100% 1.5px no-repeat, linear-gradient(#475467 0 0) bottom/100% 1.5px no-repeat
    }

    .topbar {
        padding: 0 11px;
        gap: 8px
    }

    .topbar>div {
        font-size: 13px;
        padding-left: 15px
    }

    .ghost-btn {
        min-height: 38px;
        padding: 7px 10px;
        font-size: 12px
    }

    .messages {
        padding: 20px 12px 24px
    }

    .empty-state {
        margin: 9vh auto 0;
        padding-top: 82px
    }

    .empty-state::before {
        width: 62px;
        height: 62px;
        border-radius: 20px;
        font-size: 27px
    }

    .empty-state h1 {
        font-size: 24px
    }

    .empty-state p {
        font-size: 13px
    }

    .message {
        margin: 13px 0
    }

    .bubble {
        max-width: 95%;
        padding: 12px 13px;
        border-radius: 17px
    }

    .assistant-bubble {
        width: 95%;
        padding: 13px
    }

    .message-text {
        font-size: 14px
    }

    .message-source {
        max-width: min(190px, 100%);
        max-height: 250px
    }

    .result-grid {
        grid-template-columns: 1fr
    }

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

    .result-grid.multi .result-image img {
        max-height: none
    }

    .composer-wrap {
        padding: 8px 10px max(10px, env(safe-area-inset-bottom))
    }

    .composer {
        gap: 7px;
        padding: 7px;
        border-radius: 20px
    }

    .attach-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        border-radius: 13px;
        font-size: 23px
    }

    .composer textarea {
        min-height: 40px;
        padding: 9px 3px 7px;
        font-size: 16px;
        line-height: 1.45
    }

    .send-btn {
        min-height: 40px;
        padding: 9px 13px;
        border-radius: 13px;
        font-size: 13px
    }

    .upload-preview>div {
        max-width: calc(100% - 67px)
    }

    .options-row {
        gap: 7px;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 0 2px 2px;
        scrollbar-width: none
    }

    .options-row::-webkit-scrollbar {
        display: none
    }

    .options-row>.shortcut-btn {
        min-height: 38px;
        padding: 8px 13px;
        font-size: 13px
    }

    .options-row label {
        flex: 0 0 auto
    }

    .options-row select {
        min-height: 38px;
        font-size: 16px;
        line-height: 1.2;
        touch-action: manipulation
    }

    .drawer-backdrop {
        padding: 0;
        align-items: flex-end;
        background: rgba(15, 23, 42, .44)
    }

    .drawer {
        width: 100vw;
        height: min(88dvh, 860px);
        padding: 15px;
        border: 0;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -20px 60px rgba(16, 24, 40, .18)
    }

    .drawer-head {
        top: -15px;
        margin: -15px -15px 0;
        padding: 15px;
        border-radius: 24px 24px 0 0
    }

    .library-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
        margin-top: 15px
    }

    .auth-card input {
        font-size: 16px
    }
}

@media(max-width:560px) {
    .messages {
        padding: 14px 8px 19px
    }

    .bubble {
        max-width: 96%
    }

    .assistant-bubble {
        width: 96%
    }

    .result-grid.multi {
        gap: 6px
    }

    .result-image {
        border-radius: 11px
    }

    .composer-wrap {
        padding-left: 8px;
        padding-right: 8px
    }

    .composer {
        border-radius: 18px
    }

    .upload-preview {
        border-radius: 13px
    }

    .drawer {
        height: 91dvh
    }

    .auth-page {
        padding: 14px
    }

    .auth-card {
        padding: 72px 20px 23px;
        border-radius: 22px
    }

    .auth-card::before {
        left: 20px
    }
}

@media(max-width:760px) {
    .credits-shell {
        width: min(100% - 22px, 1000px);
        padding-top: 15px
    }

    .credits-top {
        align-items: flex-start;
        margin-bottom: 34px
    }

    .credits-balance-box {
        display: block;
        padding: 8px 11px;
        text-align: right
    }

    .credits-balance-box span {
        display: block;
        margin-bottom: 2px
    }

    .credit-plan-grid {
        grid-template-columns: 1fr;
        gap: 14px
    }

    .credit-plan-card {
        min-height: 270px;
        padding: 23px 20px
    }

    .plan-count {
        font-size: 48px
    }
}

@media(prefers-reduced-motion:reduce) {

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important
    }
}