#klokin-chat-widget {
    position: relative;
    display: flex;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
    font-family: "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

#klokin-chat-widget,
#klokin-chat-widget * {
    box-sizing: border-box;
}

#klokin-chat-widget .hidden {
    display: none !important;
}

#klokin-chat-widget button,
#klokin-chat-widget textarea {
    font: inherit;
}

.chat-widget-header {
    position: relative;
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) 64px;
    align-items: center;
    flex: 0 0 auto;
    height: 48px;
    padding: 0 12px;
    border-bottom: 0;
    background: var(--kl-canvas, #F7F7F4);
}

.chat-widget-header__title {
    min-width: 0;
    padding: 0 12px;
    text-align: center;
}

.chat-widget-header__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.chat-icon {
    width: 16px;
    height: 16px;
}

#chat-current-title {
    overflow: hidden;
    color: var(--kl-ink, #111111);
    font-size: 12px;
    font-weight: 500;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-icon-button {
    display: inline-flex;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    color: var(--kl-muted, #737373);
    background: transparent;
    cursor: pointer;
    transition: color 140ms ease, background-color 140ms ease;
}

.chat-icon-button:hover {
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
}

.chat-icon-button:focus-visible,
.chat-suggestion:focus-visible,
.chat-confirm-button:focus-visible,
#chat-input:focus-visible,
#chat-send-btn:focus-visible {
    outline: 2px solid var(--kl-focus-border, #7D9272);
    outline-offset: 2px;
}

#chat-workspace {
    position: relative;
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden;
    background: var(--kl-surface, #FFFFFF);
}

#chat-thread-sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 20;
    display: flex;
    width: min(300px, calc(100% - 48px));
    min-height: 0;
    flex-direction: column;
    border-right: 1px solid var(--kl-border, #E7E5E4);
    background: var(--kl-surface, #FFFFFF);
    box-shadow: 12px 0 24px rgba(17, 17, 17, 0.08);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 220ms cubic-bezier(.4, 0, .2, 1), visibility 0s linear 220ms;
}

.dark #chat-thread-sidebar {
    box-shadow: 12px 0 24px rgba(0, 0, 0, 0.24);
}

#klokin-chat-widget.chat-history-open #chat-thread-sidebar {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
}

.chat-thread-sidebar__header {
    display: flex;
    height: 48px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--kl-border, #E7E5E4);
}

.chat-thread-sidebar__header p {
    color: var(--kl-muted, #737373);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#chat-thread-list {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px;
}

.chat-thread-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    color: var(--kl-ink, #111111);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background-color 140ms ease;
}

.chat-thread-item:hover {
    background: var(--kl-canvas, #F7F7F4);
}

.chat-thread-item:focus-visible {
    outline: 2px solid var(--kl-focus-border, #7D9272);
    outline-offset: -2px;
}

.chat-thread-item[aria-current="true"] {
    background: var(--kl-selection, #E7E5E4);
}

.chat-thread-item__title {
    display: block;
    overflow: hidden;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-thread-item__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
    color: var(--kl-muted, #737373);
    font-size: 11px;
    line-height: 16px;
}

.chat-thread-item__preview {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-thread-item__date {
    flex: 0 0 auto;
}

.chat-thread-empty,
.chat-thread-loading,
.chat-thread-error {
    padding: 24px 12px;
    color: var(--kl-muted, #737373);
    font-size: 12px;
    line-height: 16px;
    text-align: center;
}

.chat-thread-error {
    color: var(--kl-danger, #A04438);
}

#chat-conversation {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    background: var(--kl-surface, #FFFFFF);
}

#chat-messages {
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 16px;
    background: var(--kl-canvas, #F7F7F4);
}

#chat-messages-inner {
    display: flex;
    width: 100%;
    min-height: 100%;
    flex-direction: column;
}

/* Auto margin consumes spare height without making long conversations unscrollable. */
#chat-messages-inner::before {
    display: block;
    margin-top: auto;
    content: "";
}

#chat-loader {
    padding: 32px 0 16px;
    color: var(--kl-muted, #737373);
    font-size: 12px;
    line-height: 16px;
    text-align: center;
}

.chat-message {
    display: flex;
    width: 100%;
    flex: 0 0 auto;
    margin-bottom: 16px;
}

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

.chat-message__content {
    max-width: min(88%, 720px);
}

.chat-message__body {
    padding: 12px 14px;
    overflow-wrap: anywhere;
    border: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 8px;
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.55;
}

.chat-message--assistant .chat-message__body {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--kl-canvas, #F7F7F4);
}

.chat-message__body strong {
    font-weight: 600;
}

.chat-message__body a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-message--user .chat-message__body {
    border-color: var(--kl-action, #111111);
    border-radius: 20px 0 20px 20px;
    color: var(--kl-on-action, #FFFFFF);
    background: var(--kl-action, #111111);
}

.chat-message-actions {
    display: flex;
    min-height: 32px;
    align-items: center;
    gap: 2px;
    margin-top: 6px;
}

.chat-message-action {
    display: inline-flex;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: var(--kl-muted, #737373);
    background: transparent;
    cursor: pointer;
    transition: color 140ms ease, background-color 140ms ease, opacity 140ms ease;
}

.chat-message-action svg {
    width: 18px;
    height: 18px;
}

.chat-message-action:hover,
.chat-message-action.is-active {
    color: var(--kl-ink, #111111);
    background: var(--kl-selection, #E7E5E4);
}

.chat-message-action:focus-visible {
    outline: 2px solid var(--kl-focus-border, #737373);
    outline-offset: 2px;
}

.chat-message-action:disabled {
    opacity: 0.45;
    cursor: wait;
}

.chat-message-actions__status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
}

.chat-message--system .chat-message__content {
    max-width: 100%;
}

.chat-message--system .chat-message__body {
    border-style: dashed;
    color: var(--kl-muted, #737373);
    background: transparent;
    font-size: 12px;
}

.chat-message__time {
    margin-top: 4px;
    color: var(--kl-muted, #737373);
    font-size: 10px;
    line-height: 16px;
}

.chat-message--user .chat-message__time {
    text-align: right;
}

/* Markdown is rendered for both Jesper and user messages. */
.chat-markdown > :first-child {
    margin-top: 0;
}

.chat-markdown > :last-child {
    margin-bottom: 0;
}

.chat-markdown p,
.chat-markdown ul,
.chat-markdown ol,
.chat-markdown blockquote,
.chat-markdown pre,
.chat-markdown table {
    margin: 0 0 10px;
}

.chat-markdown h1,
.chat-markdown h2,
.chat-markdown h3,
.chat-markdown h4 {
    margin: 14px 0 6px;
    color: inherit;
    font-size: 1em;
    font-weight: 600;
    line-height: 1.35;
}

.chat-markdown h1 {
    font-size: 1.2em;
}

.chat-markdown h2 {
    font-size: 1.1em;
}

.chat-markdown ul,
.chat-markdown ol {
    padding-left: 20px;
}

.chat-markdown li + li {
    margin-top: 4px;
}

.chat-markdown blockquote {
    padding-left: 10px;
    border-left: 2px solid var(--kl-border-strong, #D6D3D1);
    color: var(--kl-muted, #737373);
}

.chat-message--user .chat-markdown blockquote {
    border-left-color: rgba(255, 255, 255, 0.45);
    color: inherit;
}

.chat-markdown code {
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--kl-selection, #E7E5E4);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
}

.chat-message--user .chat-markdown code {
    background: rgba(255, 255, 255, 0.14);
}

.chat-markdown pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 10px;
    border: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 6px;
    background: var(--kl-canvas, #F7F7F4);
}

.chat-markdown pre code {
    padding: 0;
    background: transparent;
}

.chat-markdown table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 12px;
}

.chat-markdown th,
.chat-markdown td {
    padding: 6px 8px;
    border: 1px solid var(--kl-border, #E7E5E4);
    text-align: left;
    white-space: nowrap;
}

.chat-markdown th {
    background: var(--kl-canvas, #F7F7F4);
    font-weight: 600;
}

.chat-message__body--component-fallback {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.chat-message--has-component .chat-message__content {
    width: 100%;
    max-width: min(100%, 880px);
}

.chat-component {
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 8px;
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
}

.chat-component + .chat-component {
    margin-top: 8px;
}

.chat-component__header {
    display: flex;
    min-height: 40px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--kl-border, #E7E5E4);
}

.chat-component__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    line-height: 20px;
}

.chat-component__count {
    flex: 0 0 auto;
    color: var(--kl-muted, #737373);
    font-size: 11px;
    line-height: 16px;
}

.chat-component__empty {
    display: flex;
    min-height: 96px;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 16px;
    color: var(--kl-muted, #737373);
    font-size: 12px;
    text-align: center;
}

.chat-component-link {
    color: var(--kl-ink, #111111);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: var(--kl-border-strong, #D6D3D1);
    text-underline-offset: 3px;
}

.chat-component-link:hover {
    text-decoration-color: currentColor;
}

.chat-component-link:focus-visible {
    border-radius: 3px;
    outline: 2px solid var(--kl-focus-border, #7D9272);
    outline-offset: 2px;
}

.chat-component-list {
    min-width: 0;
}

.chat-component-list .kl-list-surface {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.chat-component-list .kl-list-toolbar {
    min-height: 44px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--kl-border, #E7E5E4);
    background: var(--kl-surface, #FFFFFF);
}

.chat-component-list .kl-list-toolbar__views,
.chat-component-list .kl-list-toolbar__actions {
    display: none;
}

.chat-component-list .kl-list-toolbar__search {
    width: 100%;
    max-width: none;
}

.chat-component-list .kl-list-search {
    width: 100%;
    min-height: 32px;
    border-radius: 6px;
}

.chat-component-list .kl-list-header,
.chat-component-list .kl-list-table-scroll {
    border-color: var(--kl-border, #E7E5E4);
    background: var(--kl-surface, #FFFFFF);
}

.chat-component-list .kl-list-header table,
.chat-component-list .kl-list-table-scroll table {
    width: 100%;
}

.chat-component-list .kl-list-th > div {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-component-list .kl-sort-arrow,
.chat-component-list .kl-sort-icon {
    display: inline-flex;
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
}

.chat-component-list .kl-list-table-scroll {
    max-height: 320px;
    overflow: auto;
}

.chat-component-list .kl-list-th,
.chat-component-list__heading {
    padding: 8px 10px !important;
    color: var(--kl-muted, #737373);
    background: var(--kl-canvas, #F7F7F4);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}

.chat-component-list__cell,
.chat-component-list__scroll th,
.chat-component-list__scroll td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--kl-border, #E7E5E4);
    color: var(--kl-ink, #111111);
    font-size: 12px;
    line-height: 18px;
    vertical-align: top;
}

.chat-component-list__cell {
    width: auto;
}

.chat-component-list .kl-list-footer {
    min-height: 44px;
    padding: 6px 8px;
    border-top: 1px solid var(--kl-border, #E7E5E4);
    background: var(--kl-surface, #FFFFFF);
}

.chat-component-list__scroll {
    max-height: 320px;
    overflow: auto;
}

.chat-component-list__scroll table {
    width: 100%;
    border-collapse: collapse;
}

.chat-component-map {
    position: relative;
    width: 100%;
    height: clamp(240px, 42vh, 360px);
    background: var(--kl-canvas, #F7F7F4);
}

.chat-component-map--unavailable {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: var(--kl-muted, #737373);
    font-size: 12px;
    text-align: center;
}

.chat-suggestions {
    flex: 0 0 auto;
    margin-bottom: 16px;
}

.chat-suggestions__title {
    margin: 0 0 4px;
    color: var(--kl-muted, #737373);
    font-size: 12px;
    font-weight: 500;
    line-height: 16px;
}

.chat-suggestions__list {
    border-top: 1px solid var(--kl-border, #E7E5E4);
}

.chat-suggestion {
    display: flex;
    width: 100%;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 4px;
    border: 0;
    border-bottom: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 0;
    color: var(--kl-ink, #111111);
    background: transparent;
    font-size: 13px;
    font-weight: 400;
    line-height: 20px;
    text-align: left;
    cursor: pointer;
    transition: color 140ms ease, background-color 140ms ease;
}

.chat-suggestion:hover {
    background: var(--kl-surface, #FFFFFF);
}

.chat-suggestion:disabled {
    color: var(--kl-disabled, #A8A8A3);
    cursor: not-allowed;
}

.chat-suggestion__icon {
    flex: 0 0 auto;
    color: var(--kl-muted, #737373);
    font-size: 16px;
    line-height: 20px;
}

.chat-confirm-card {
    flex: 0 0 auto;
    margin-bottom: 16px;
    padding: 16px;
    border: 1px solid var(--kl-warning-border, rgba(134, 95, 36, 0.25));
    border-radius: 12px;
    color: var(--kl-ink, #111111);
    background: var(--kl-warning-surface, #EEE2CC);
}

.chat-diagnostic {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--kl-danger-border, rgba(153, 61, 61, 0.24));
    border-radius: 8px;
    background: var(--kl-danger-surface, rgba(153, 61, 61, 0.06));
}

.chat-diagnostic__status {
    margin: 0;
    color: var(--kl-ink, #111111);
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
}

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

.chat-diagnostic__reference code {
    color: var(--kl-muted, #737373);
    font: 500 11px/16px ui-monospace, SFMono-Regular, Consolas, monospace;
}

.chat-diagnostic__copy {
    min-height: 28px;
    padding: 4px 8px;
    border: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 6px;
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
}

.chat-diagnostic__copy:hover {
    background: var(--kl-canvas, #F7F7F4);
}

.chat-diagnostic__copy:focus-visible {
    outline: 2px solid var(--kl-focus-border, #7D9272);
    outline-offset: 2px;
}

.chat-confirm-card__title {
    margin: 0;
    color: var(--kl-warning, #865F24);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
}

.chat-confirm-card__details {
    margin: 8px 0 0;
    padding-left: 20px;
    font-size: 12px;
    line-height: 18px;
}

.chat-confirm-card__warning {
    margin: 12px 0 0;
    color: var(--kl-warning, #865F24);
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
}

.chat-confirm-card__actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.chat-confirm-button {
    min-height: 32px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}

.chat-confirm-button--primary {
    border: 1px solid var(--kl-action, #111111);
    color: var(--kl-on-action, #FFFFFF);
    background: var(--kl-action, #111111);
}

.chat-confirm-button--secondary {
    border: 1px solid var(--kl-warning-border, rgba(134, 95, 36, 0.25));
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
}

.chat-confirm-button:hover {
    filter: brightness(0.96);
}

.chat-confirm-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.confirm-card-flash {
    animation: chat-confirm-flash 500ms ease;
}

@keyframes chat-confirm-flash {
    50% {
        outline: 3px solid var(--kl-warning-border, rgba(134, 95, 36, 0.25));
        outline-offset: 2px;
    }
}

.chat-typing-dots {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 8px;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kl-muted, #737373);
    animation: chat-typing 1.2s infinite ease-in-out both;
}

.chat-typing-dot:nth-child(1) {
    animation-delay: -240ms;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: -120ms;
}

@keyframes chat-typing {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: scale(0.75);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

#chat-composer {
    flex: 0 0 auto;
    padding: 12px;
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    border-top: 0;
    background: var(--kl-canvas, #F7F7F4);
}

#chat-form {
    position: relative;
}

#chat-input {
    display: block;
    width: 100%;
    min-height: 48px;
    max-height: var(--chat-input-max-height, 160px);
    resize: none;
    padding: 12px 48px 12px 12px;
    border: 1px solid var(--kl-border, #E7E5E4);
    border-radius: 8px;
    color: var(--kl-ink, #111111);
    background: var(--kl-surface, #FFFFFF);
    font-size: 14px;
    line-height: 22px;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

#chat-input::placeholder {
    color: var(--kl-muted, #737373);
}

#chat-input:focus {
    border-color: var(--kl-focus-border, #7D9272);
    box-shadow: 0 0 0 3px var(--kl-focus-ring, #DDE5D7);
    outline: none;
}

#chat-input:disabled {
    color: var(--kl-disabled, #A8A8A3);
    background: var(--kl-canvas, #F7F7F4);
    cursor: not-allowed;
}

#chat-send-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: inline-flex;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--kl-action, #111111);
    border-radius: 8px;
    color: var(--kl-on-action, #FFFFFF);
    background: var(--kl-action, #111111);
    cursor: pointer;
    transition: background-color 140ms ease, opacity 140ms ease;
}

#chat-send-btn:hover {
    background: var(--kl-action-hover, #262626);
}

#chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-disclaimer {
    margin: 8px 4px 0;
    color: var(--kl-muted, #737373);
    font-size: 10px;
    line-height: 16px;
}

@media (min-width: 768px) {
    .admin-ai-panel-fullscreen #chat-thread-sidebar {
        position: relative;
        inset: auto;
        width: 280px;
        flex: 0 0 280px;
        box-shadow: none;
        transform: translateX(0);
        visibility: visible;
        transition: none;
    }

    .admin-ai-panel-fullscreen #chat-history-btn {
        visibility: hidden;
    }

    .admin-ai-panel-fullscreen #chat-history-close-btn {
        display: none;
    }
}

@media (max-width: 767px) {
    #klokin-chat-widget #chat-input { font-size: 16px; line-height: 24px; }
    .chat-widget-header { padding-right: max(12px, env(safe-area-inset-right, 0px)); }
}

.admin-ai-panel-fullscreen #chat-messages-inner,
.admin-ai-panel-fullscreen #chat-composer-inner {
    width: 100%;
    max-width: 800px;
    margin-right: auto;
    margin-left: auto;
}

@media (prefers-reduced-motion: reduce) {
    #chat-thread-sidebar,
    .chat-icon-button,
    .chat-thread-item,
    .chat-suggestion,
    .chat-message-action,
    #chat-input,
    #chat-send-btn {
        transition: none;
    }

    .chat-typing-dot,
    .confirm-card-flash {
        animation: none;
    }
}
