/* ============================================================
   Tanya AI - widget mengambang + halaman /chat
   Memakai variabel yang sama dengan app.css (light + dark).
   ============================================================ */

/* ---------------------------------------------------------- Launcher */
.chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 60;
    width: 46px;
    height: 46px;
    border: 1px solid var(--primary-strong);
    border-radius: 6px;
    background: var(--primary);
    color: var(--on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: background .15s ease;
}

.chat-launcher:hover {
    background: var(--primary-strong);
}

.chat-launcher:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.chat-launcher .icon {
    width: 20px;
    height: 20px;
}

.chat-launcher__label {
    position: absolute;
    right: calc(100% + 8px);
    white-space: nowrap;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: .78rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

.chat-launcher:hover .chat-launcher__label,
.chat-launcher:focus-visible .chat-launcher__label {
    opacity: 1;
}

/* ------------------------------------------------------------- Panel */
.chat-panel {
    position: fixed;
    right: 20px;
    bottom: 76px;
    z-index: 61;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(620px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
}

.chat-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.chat-panel__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.chat-panel__title {
    font-size: .9rem;
    font-weight: 700;
    margin: 0;
}

.chat-panel__sub {
    font-size: .72rem;
    color: var(--muted);
    margin: 1px 0 0;
}

.chat-panel__spacer {
    flex: 1;
}

.chat-dataset-chip {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
}

.chat-icon-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-icon-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

.chat-icon-btn .icon {
    width: 15px;
    height: 15px;
}

/* ------------------------------------------------------- Quick cards */
.chat-quick {
    display: none;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    max-height: 210px;
    overflow-y: auto;
    padding: 10px 12px;
}

.chat-quick.is-open {
    display: block;
}

.chat-quick__title {
    font-size: .7rem;
    color: var(--muted);
    margin: 0 0 8px;
    font-weight: 600;
}

.chat-quick__row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* -------------------------------------------------------------- Log */
.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.chat-msg {
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: .85rem;
    line-height: 1.55;
    background: var(--surface-2);
    border: 1px solid var(--border);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.chat-msg--me {
    align-self: flex-end;
    background: var(--primary);
    color: var(--on-primary);
    border-color: transparent;
}

.chat-msg--err {
    background: var(--bad-soft);
    border-color: var(--bad);
    color: var(--text);
}

.chat-msg p {
    margin: 0 0 8px;
}

.chat-msg p:last-child {
    margin-bottom: 0;
}

.chat-msg ul,
.chat-msg ol {
    margin: 6px 0;
    padding-left: 20px;
}

.chat-msg li {
    margin: 2px 0;
}

.chat-msg strong {
    font-weight: 700;
}

.chat-msg code {
    font-family: var(--font-mono);
    font-size: .82em;
    background: var(--surface-3);
    padding: 1px 5px;
    border-radius: 5px;
}

.chat-msg table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: .8rem;
}

.chat-msg th,
.chat-msg td {
    text-align: left;
    padding: 5px 7px;
    border-bottom: 1px solid var(--border);
}

.chat-msg th {
    color: var(--muted);
    font-weight: 600;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.chat-msg--me th,
.chat-msg--me td {
    border-bottom-color: rgba(255, 255, 255, .25);
}

.chat-msg__meta {
    display: block;
    margin-top: 6px;
    font-size: .68rem;
    color: var(--muted);
}

/* Kartu kontak lokal (nomor tidak pernah dikirim ke AI) */
.chat-contact {
    align-self: flex-start;
    max-width: 88%;
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 10px;
    background: var(--surface);
    padding: 9px 11px;
    font-size: .8rem;
}

.chat-contact__name {
    font-weight: 600;
}

.chat-contact__row {
    color: var(--muted);
    font-size: .76rem;
    margin-top: 3px;
}

.chat-contact__phone {
    font-family: var(--font-mono);
    color: var(--text);
    font-weight: 600;
}

/* Daftar dihubungi lokal (nama + nomor, tidak pernah dikirim ke AI) */
.chat-sheet {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 10px;
    background: var(--surface);
    padding: 9px 11px;
    font-size: .78rem;
}

.chat-sheet__head {
    font-weight: 600;
    margin-bottom: 6px;
    font-size: .78rem;
}

.chat-sheet__table {
    width: 100%;
    border-collapse: collapse;
    font-size: .74rem;
}

.chat-sheet__table th {
    text-align: left;
    font-weight: 500;
    color: var(--muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 3px 5px;
    border-bottom: 1px solid var(--border);
}

.chat-sheet__table td {
    padding: 4px 5px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.chat-sheet__table tr:last-child td {
    border-bottom: none;
}

.chat-sheet__table .num {
    text-align: right;
    white-space: nowrap;
}

.chat-sheet__idx {
    color: var(--muted);
    font-family: var(--font-mono);
}

.chat-sheet__name {
    font-weight: 600;
}

.chat-sheet__sub {
    color: var(--muted);
    font-size: .7rem;
}

/* --------------------------------------------------------- Composer */
.chat-composer {
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    background: var(--surface);
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 9px;
}

.chat-chip {
    font: inherit;
    font-size: .73rem;
    line-height: 1.3;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 9px;
    cursor: pointer;
    text-align: left;
}

.chat-chip:hover {
    color: var(--text);
    border-color: var(--primary);
}

.chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    resize: none;
    font: inherit;
    font-size: .85rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 8px 10px;
    max-height: 120px;
    min-height: 38px;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}

.chat-send {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border: 1px solid var(--primary);
    border-radius: 5px;
    background: var(--primary);
    color: var(--on-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-send:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.chat-send .icon {
    width: 18px;
    height: 18px;
}

.chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: chat-blink 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: .18s; }
.chat-typing span:nth-child(3) { animation-delay: .36s; }

@keyframes chat-blink {
    0%, 60%, 100% { opacity: .25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-typing span { animation: none; }
    .chat-panel { transition: none; }
}

/* ================================================== Halaman /rekomendasi & /chat */
.rec-page {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.chat-page {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.chat-page--solo {
    display: block;
    max-width: 960px;
    margin: 0 auto;
}

@media (max-width: 1080px) {
    .rec-page,
    .chat-page { grid-template-columns: 1fr; }
}

.rec-block {
    margin-bottom: 18px;
}

.rec-block__head {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}

.rec-block__head h2 {
    font-size: 1rem;
    margin: 0;
}

.rec-block__head p {
    font-size: .78rem;
    color: var(--muted);
    margin: 2px 0 0;
}

.rec-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.rec-card__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .93rem;
    font-weight: 600;
    margin: 0 0 4px;
}

.rec-card__desc {
    font-size: .8rem;
    color: var(--muted);
    margin: 0 0 12px;
}

.rec-card__note {
    font-size: .74rem;
    color: var(--muted);
    border-top: 1px dashed var(--border);
    margin-top: 11px;
    padding-top: 9px;
}

.rec-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
}

.rec-table th {
    text-align: left;
    font-size: .69rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    padding: 0 8px 7px 0;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.rec-table td {
    padding: 8px 8px 8px 0;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.rec-table tr:last-child td {
    border-bottom: none;
}

.rec-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rec-table .rec-name {
    font-weight: 600;
}

.rec-table .rec-sub {
    color: var(--muted);
    font-size: .74rem;
}

.rec-phone {
    font-family: var(--font-mono);
    font-size: .78rem;
    font-weight: 600;
}

.rec-phone--none {
    font-family: inherit;
    font-weight: 400;
    color: var(--muted);
    font-style: italic;
}

.rec-stat {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.rec-stat__item {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    min-width: 130px;
}

.rec-stat__label {
    font-size: .69rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.rec-stat__value {
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rec-stat__note {
    font-size: .72rem;
    color: var(--muted);
}

.rec-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.rec-list li {
    display: flex;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: .83rem;
}

.rec-list li:last-child {
    border-bottom: none;
}

.rec-list__index {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: var(--primary-soft);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.rec-caveats {
    list-style: none;
    margin: 0;
    padding: 0;
}

.rec-caveats li {
    font-size: .81rem;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}

.rec-caveats li:last-child {
    border-bottom: none;
}

.rec-caveats strong {
    display: block;
    font-size: .78rem;
}

.rec-caveats span {
    color: var(--muted);
}

.rec-buckets {
    display: grid;
    gap: 10px;
}

.rec-bucket {
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.rec-bucket--now { border-left-color: var(--bad); }
.rec-bucket--week { border-left-color: var(--warn); }
.rec-bucket--blast { border-left-color: var(--info); }

.rec-bucket__title {
    font-size: .84rem;
    font-weight: 700;
}

.rec-bucket__meta {
    font-size: .74rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.rec-bucket__name {
    font-size: .8rem;
}

.rec-bucket__name + .rec-bucket__name {
    border-top: 1px dashed var(--border);
    padding-top: 5px;
    margin-top: 5px;
}

.rec-prompt-btn {
    font: inherit;
    font-size: .74rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    white-space: nowrap;
}

.rec-prompt-btn:hover {
    background: var(--primary);
    color: var(--on-primary);
}

/* Panel inline untuk halaman /chat */
.chat-inline {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    height: calc(100vh - 200px);
    min-height: 540px;
    overflow: hidden;
    position: static;
}

.chat-inline [data-chat-close] {
    display: none;
}

.chat-inline .chat-log {
    padding: 16px;
}

.chat-inline .chat-quick {
    max-height: 260px;
}

.chat-inline__empty {
    color: var(--muted);
    font-size: .86rem;
    text-align: center;
    margin: auto;
    padding: 20px;
    max-width: 320px;
}
