:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-soft: #fafbfc;
    --surface-muted: #f2f4f7;
    --ink: #1f2933;
    --ink-soft: #667085;
    --line: #e4e7ec;
    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --teal: #0f766e;
    --teal-soft: #ccfbf1;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --warning: #b54708;
    --warning-soft: #fffaeb;
    --shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
    --radius-xl: 18px;
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 8px;
    --font-sans: "Avenir Next", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-sans);
    color: var(--ink);
    background: var(--bg);
}

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

.login-page,
.chat-page {
    min-height: 100vh;
}

.login-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    margin: 0 auto;
    padding: 24px 16px;
    min-height: 100vh;
}

.eyebrow {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--ink-soft);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login-hero h1,
.chat-topbar h1 {
    margin: 14px 0 10px;
    font-size: clamp(2rem, 3vw, 2.8rem);
    line-height: 1.1;
}

.login-hero p,
.chat-topbar p,
.card-header p,
.demo-note p,
.empty-state p,
.composer-hint {
    margin: 0;
    color: var(--ink-soft);
    line-height: 1.65;
}

.hero-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.hero-pills span,
.language-badge,
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.hero-pills span {
    padding: 7px 10px;
    background: var(--surface-muted);
    color: var(--ink-soft);
}

.login-card {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 24px;
}

.login-title {
    margin: 0 0 18px;
    font-size: 1.75rem;
    text-align: center;
}

.card-header h2,
.demo-note h3,
.empty-state h2 {
    margin: 0 0 8px;
}

.login-form {
    display: grid;
    gap: 18px;
}

.login-form {
    margin-top: 18px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ink);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    padding: 12px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.field textarea {
    min-height: 92px;
    resize: vertical;
}

.primary-button,
.secondary-button {
    appearance: none;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.primary-button,
.secondary-button {
    padding: 11px 16px;
    font-weight: 600;
}

.primary-button {
    background: var(--accent);
    color: #fff;
}

.secondary-button {
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    border: 1px solid var(--line);
}

.topbar-logout {
    padding: 10px 14px;
}

.locale-switcher {
    display: block;
}

.login-locale-switcher {
    margin: 0 auto;
    width: 100%;
    max-width: 220px;
}

.primary-button:hover,
.secondary-button:hover {
    transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.app-alert {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecdca;
    line-height: 1.5;
}

.app-alert.is-success {
    background: var(--teal-soft);
    color: var(--teal);
    border-color: #99f6e4;
}

.app-alert.is-hidden,
.empty-state.is-hidden {
    display: none;
}

.demo-note {
    margin-top: 20px;
    padding: 16px;
    border-radius: var(--radius-lg);
    background: var(--panel-soft);
    border: 1px solid var(--line);
}

.login-meta {
    margin: 16px 0 0;
    color: var(--ink-soft);
    font-size: 0.92rem;
    line-height: 1.7;
    text-align: center;
}

.demo-note ul {
    margin: 12px 0 8px;
    padding-left: 18px;
    color: var(--ink-soft);
}

.chat-shell {
    max-width: 760px;
    margin: 0 auto;
    padding: 0;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 0;
}

.chat-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

.topbar-main {
    min-width: 0;
}

.topbar-main h1 {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.2;
}

.topbar-subtitle {
    margin: 2px 0 0;
    color: var(--ink-soft);
    font-size: 0.84rem;
    line-height: 1.4;
}

.chat-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-stream {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty-state {
    margin: auto;
    max-width: 380px;
    text-align: center;
    padding: 24px;
    background: var(--panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
}

.message-card {
    width: min(100%, 78%);
    padding: 0;
    border-radius: 16px;
    background: transparent;
    border: 1px solid var(--line);
    overflow: hidden;
}

.message-card.is-self {
    margin-left: auto;
    border-color: #dbeafe;
    background: #f8fbff;
}

.message-topline,
.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.message-topline {
    padding: 8px 10px 4px;
    margin-bottom: 0;
}

.sender-block {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.sender-name {
    font-weight: 700;
}

.message-time {
    font-size: 0.82rem;
    color: var(--ink-soft);
}

.message-copy {
    display: block;
}

.message-body {
    padding: 10px;
    background: var(--panel);
    border-top: 1px solid rgba(228, 231, 236, 0.8);
}

.message-card.is-self .message-body {
    background: #ffffff;
}

.message-translation {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(228, 231, 236, 0.8);
    color: var(--ink-soft);
}

.message-card.is-self .message-translation {
    color: #475467;
}

.message-text,
.status-text {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.message-meta {
    padding: 6px 10px 8px;
}

.message-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.language-badge,
.status-badge {
    padding: 5px 9px;
}

.language-badge {
    background: var(--teal-soft);
    color: var(--teal);
}

.status-badge.pending {
    background: var(--warning-soft);
    color: var(--warning);
}

.status-badge.done {
    background: var(--teal-soft);
    color: var(--teal);
}

.status-badge.failed {
    background: var(--danger-soft);
    color: var(--danger);
}

.composer {
    display: flex;
    flex-direction: column;
    position: sticky;
    bottom: 0;
    padding: 10px 24px 14px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(12px);
    gap: 8px;
}

.compact-field {
    max-width: 220px;
}

.locale-field {
    display: block;
}

.composer-language {
    display: block;
    width: 96px;
    align-self: flex-start;
}

.composer-language select,
.locale-field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    padding: 8px 10px;
}

.composer-language select:focus,
.locale-field select:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
}

.composer-textarea {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
}

.composer-textarea textarea {
    min-height: 26px;
    max-height: 78px;
    background: #fff;
    border: 1px solid var(--line);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 6px 14px;
    resize: none;
    overflow-y: hidden;
    width: 100%;
    transition: height 0.15s ease;
}

.composer-textarea textarea:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.composer-send {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    min-width: 52px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.composer-send svg {
    width: 22px;
    height: 22px;
}

.composer-send[aria-busy="true"] svg {
    opacity: 0.5;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.composer-hint {
    margin-top: 0;
    font-size: 0.75rem;
    text-align: left;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 900px) {
    .login-shell {
        padding: 24px 16px 28px;
    }

    .chat-shell {
        max-width: none;
    }

    .chat-topbar {
        padding: 14px 16px;
    }

}

@media (max-width: 640px) {
    .login-card,
    .chat-topbar {
        padding: 14px;
    }

    .message-topline,
    .message-meta {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-main h1 {
        display: none;
    }

    .topbar-actions {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        flex-wrap: nowrap;
    }

    .login-locale-switcher,
    .locale-switcher,
    .locale-field {
        width: 100%;
        max-width: none;
    }

    .message-card {
        width: min(100%, 88%);
    }

    .compact-field {
        max-width: none;
    }

    .composer {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    }

    .composer-box {
        gap: 6px;
    }

    .composer-language {
        width: 88px;
    }

    .composer-send {
        width: 46px;
        height: 46px;
        min-width: 46px;
    }

    .login-form .primary-button,
    .login-form .secondary-button {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .topbar-logout {
        width: auto;
        white-space: nowrap;
    }
}

/* ── Scroll-to-bottom button ── */

.scroll-bottom-btn {
    position: absolute;
    left: 50%;
    bottom: 155px;
    transform: translateX(-50%);
    z-index: 20;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 12px rgba(16, 24, 40, 0.12);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.scroll-bottom-btn svg {
    width: 20px;
    height: 20px;
    color: var(--ink-soft);
}

.scroll-bottom-btn:hover {
    box-shadow: 0 4px 16px rgba(16, 24, 40, 0.16);
    transform: translateX(-50%) translateY(-1px);
}

.scroll-bottom-btn.is-hidden {
    display: none;
}

/* ── Admin ── */

.admin-page {
    min-height: 100vh;
}

.admin-shell {
    max-width: 860px;
    margin: 0 auto;
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.admin-main {
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.admin-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 24px;
}

.admin-section-title {
    margin: 0 0 20px;
    font-size: 1.05rem;
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.admin-form-row .field {
    flex: 1 1 180px;
    min-width: 0;
}

.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.admin-table th {
    font-weight: 700;
    color: var(--ink-soft);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.admin-table tbody tr:last-child td {
    border-bottom: 0;
}

.side-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.side-indonesia {
    background: var(--accent-soft);
    color: var(--accent);
}

.side-japan {
    background: var(--teal-soft);
    color: var(--teal);
}

.side-admin {
    background: var(--surface-muted);
    color: var(--ink-soft);
}

@media (max-width: 640px) {
    .admin-shell {
        max-width: 100%;
    }

    .admin-card {
        padding: 16px 14px;
        border-radius: var(--radius-lg);
    }

    .admin-main {
        padding: 16px 12px 32px;
        gap: 16px;
    }

    .admin-form-row {
        flex-direction: column;
        gap: 14px;
    }

    .admin-form-row .field {
        flex: 1 1 100%;
    }

    .admin-form [data-add-user-submit] {
        width: 100%;
        text-align: center;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px 10px;
        font-size: 0.82rem;
    }
}
