@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

body { font-family: 'Noto Sans TC', sans-serif; background-color: #f8fafc; color: #334155; }
html { font-size: calc(1rem + 2pt); }

/* 主控台列表頁：接近 Apple 系統字體堆疊 */
#view-permissions,
#view-logs,
#view-vendors,
#view-terminology,
#view-import,
#view-ai-prompt,
#view-monitor,
#view-chat {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
}

.console-apple-table th {
    background: linear-gradient(to bottom, #fafafa, #f4f4f5);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
    color: #52525b;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.console-apple-table td {
    border-bottom: 1px solid rgba(15, 23, 42, 0.05);
    vertical-align: middle;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease-in-out; }

.nav-item.active { background-color: #eff6ff; color: #2563eb; border-right: 4px solid #2563eb; font-weight: 700; }
.nav-item { transition: all 0.2s ease; border-right: 4px solid transparent; }
.nav-item:hover:not(.active) { background-color: #f1f5f9; }
.view-section { display: none; animation: fadeIn 0.3s ease; }
.view-section.active { display: block; }

/* 抵消 .console-main-scroll 左右 padding（p-6 / sm:p-10 / md:px-10），讓列表與設定與 LINE／對話同寬 */
.console-tab-bleed-x {
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    width: calc(100% + 3rem);
}
@media (min-width: 640px) {
    .console-tab-bleed-x {
        margin-left: -2.5rem;
        margin-right: -2.5rem;
        width: calc(100% + 5rem);
    }
}

/* 主捲區：勿用單側 scrollbar-gutter（會讓內容看起來偏左、右側留白變大） */

/**
 * 列表／匯入／智慧總機提示詞共用內縮（與原 px-4 / sm:6 / md:8 / lg:10 等價）。
 * 使用 padding-inline，左右一定對稱。
 */
.console-inset-page-shell {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-inline: 1rem;
    padding-bottom: 2rem;
}
@media (min-width: 640px) {
    .console-inset-page-shell {
        padding-inline: 1.5rem;
        padding-bottom: 2.5rem;
    }
}
@media (min-width: 768px) {
    .console-inset-page-shell {
        padding-inline: 2rem;
        padding-bottom: 2.5rem;
    }
}
@media (min-width: 1024px) {
    .console-inset-page-shell {
        padding-inline: 2.5rem;
        padding-bottom: 2.5rem;
    }
}

/* 智慧總機：分段整理後回答的附註（不搶主內容） */
.chat-rag-footnote {
    margin-top: 0.35rem;
    padding: 0.35rem 0.5rem 0;
    font-size: 11px;
    line-height: 1.45;
    color: #64748b;
}
.chat-reply-meta {
    margin-top: 0.35rem;
    padding: 0.35rem 0.5rem 0;
    font-size: 11px;
    line-height: 1.45;
    color: #64748b;
}
.chat-reply-footer {
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.chat-reply-footer .chat-reply-meta {
    margin-top: 0;
    padding: 0.35rem 0 0;
}
.chat-reply-actions {
    padding: 0;
    display: inline-flex;
    align-items: center;
}
.chat-copy-btn {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #475569;
    border-radius: 9999px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.chat-copy-btn:hover {
    background: #f8fafc;
}
html.lock-tab-scroll,
body.lock-tab-scroll {
    overflow: hidden !important;
    height: 100%;
}
#app-interface.lock-tab-scroll,
#app-interface.lock-tab-scroll main {
    overflow: hidden !important;
}
.console-main-scroll.lock-scroll {
    overflow: hidden !important;
    overscroll-behavior: none;
}
/* LINE/智慧總機：都要吃滿內容區高度（手機保守扣掉頂欄） */
#view-monitor.view-section.active,
#view-chat.view-section.active {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
}
@media (max-width: 639.98px) {
    #view-monitor.view-section.active,
    #view-chat.view-section.active {
        height: calc(100vh - 7.5rem + env(safe-area-inset-bottom, 0px));
        min-height: 0;
    }
}
@media (min-width: 640px) and (max-width: 767.98px) {
    #view-monitor.view-section.active,
    #view-chat.view-section.active {
        height: calc(100vh - 9.5rem + env(safe-area-inset-bottom, 0px));
        min-height: 0;
    }
}
.admin-only.hidden-by-role { display: none !important; }
.readonly-disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; background-color: #f1f5f9 !important; border-color: #cbd5e1 !important; color: #94a3b8 !important; box-shadow: none !important; }
.form-input { width: 100%; padding: 10px 16px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; outline: none; transition: border-color 0.2s; }
.form-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
.modal-backdrop { background-color: rgba(15, 23, 42, 0.6); backdrop-filter: blur(2px); opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal-content { transform: scale(0.95) translateY(10px); opacity: 0; transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1); width: min(100%, 42rem); max-height: calc(100vh - 2.5rem); }
.modal-backdrop.show .modal-content { transform: scale(1) translateY(0); opacity: 1; }
@media (max-width: 767.98px) {
    .modal-backdrop {
        align-items: flex-start;
        padding-left: calc(0.875rem + env(safe-area-inset-left, 0px));
        padding-right: calc(0.875rem + env(safe-area-inset-right, 0px));
        padding-top: calc(1rem + env(safe-area-inset-top, 0px));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    .modal-content {
        width: 100%;
        max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
}
.brand-logo { object-fit: contain; border-radius: 8px; }
table.data-table { border-collapse: separate; border-spacing: 0; }
.data-table th { background-color: #f8fafc; text-transform: uppercase; font-size: calc(12px + 1pt); font-weight: 700; color: #64748b; letter-spacing: 0.05em; padding: 16px 24px; border-bottom: 1px solid #e2e8f0; }
.data-table td { padding: 16px 24px; border-bottom: 1px solid #f1f5f9; font-size: calc(14px + 1pt); vertical-align: middle; }
.data-table tbody tr:hover { background-color: #fcfcfc; }
@keyframes progress-stripes {
    from { background-position: 1rem 0; }
    to { background-position: 0 0; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.tab-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* LINE Chat */
.line-window {
    min-height: 420px;
    height: min(500px, 70vh);
    background-color: #7494c0;
}
#view-chat .chat-thread {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
}
.chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.chat-msg-assistant {
    gap: 0;
}
.chat-msg-user {
    justify-content: flex-end;
}
.bubble-left,
.bubble-right {
    max-width: min(88%, 980px);
    padding: 11px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.7;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    word-break: break-word;
}
.bubble-left {
    width: 100%;
    max-width: none;
    background-color: transparent;
    color: #334155;
    border: 0;
    border-top-left-radius: 10px;
    border-radius: 0;
    box-shadow: none;
}
.bubble-right {
    background-color: #2563eb;
    color: #ffffff;
    border-top-right-radius: 4px;
    max-width: min(76%, 720px);
}
.chat-msg-assistant .bubble-left {
    padding: 6px 4px 8px 4px;
}
.chat-msg-assistant .bubble-left strong {
    color: #0f172a;
}
.chat-msg-assistant .bubble-left br + br {
    content: "";
}
#chat-scroll { scroll-behavior: smooth; }
.line-scroll-region {
    max-height: 100%;
    overscroll-behavior: contain;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ERP 匯入：等待伺服器解析／寫入 DB 時的不確定進度條 */
@keyframes erpUploadIndeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}
.erp-upload-bar-fill {
    width: 40%;
    animation: erpUploadIndeterminate 1.1s ease-in-out infinite;
}

/* Chat：AI 思考中動畫 */
@keyframes chatTypingBlink {
    0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}
.chat-typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 9999px;
    background: #94a3b8;
    animation: chatTypingBlink 1.2s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
.chat-thinking .bubble-left {
    color: #475569;
}
.chat-thinking-head {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
@keyframes chatShimmerSlide {
    0% { background-position: 180% 0; }
    100% { background-position: -40% 0; }
}
.chat-thinking-shimmer {
    margin-top: 0.55rem;
    max-width: 26rem;
}
.chat-thinking-shimmer .line {
    display: block;
    height: 9px;
    border-radius: 9999px;
    margin-top: 0.4rem;
    background: linear-gradient(90deg, #e2e8f0 20%, #f8fafc 50%, #e2e8f0 80%);
    background-size: 220% 100%;
    animation: chatShimmerSlide 1.35s linear infinite;
}
@media (max-width: 767.98px) {
    .bubble-left,
    .bubble-right {
        max-width: 96%;
    }
    .bubble-right {
        max-width: 92%;
    }
    .chat-msg-assistant .bubble-left {
        padding: 6px 2px 8px 2px;
    }
}

@media (min-width: 768px) {
    /* 桌機版也維持滿版內容區，不做置中小窗 */
    #chat-shell {
        width: 100%;
        margin: 0;
        border-radius: 0;
    }
    #chat-scroll {
        padding-left: 8px;
        padding-right: 8px;
    }
    #line-monitor-shell > div:first-child,
    #line-monitor-layout {
        padding-left: 8px;
        padding-right: 8px;
    }
}

/* LINE 即時監聽：與智慧總機同調（透明底、無白卡） */
#view-monitor #line-log-list.monitor-msg-list {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
}
#view-monitor #line-log-list.monitor-msg-list > .monitor-msg-row {
    margin-top: 12px;
}
#view-monitor #line-log-list.monitor-msg-list > .monitor-msg-row-continue {
    margin-top: 5px;
}
#view-monitor #line-log-list.monitor-msg-list > .monitor-msg-row:first-child,
#view-monitor #line-log-list.monitor-msg-list > .monitor-msg-system:first-child {
    margin-top: 0;
}
#view-monitor #line-log-list.monitor-msg-list > .monitor-msg-system {
    margin-top: 14px;
    margin-bottom: 2px;
}
.monitor-group-item {
    width: 100%;
    border: 0;
    border-radius: 0;
    padding: 10px 4px 10px 2px;
    text-align: left;
    transition: background-color 0.15s ease;
    background: transparent;
    border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}
.monitor-group-item:hover {
    background: rgba(241, 245, 249, 0.55);
}
.monitor-group-item.is-active {
    border-bottom-color: rgba(125, 211, 252, 0.6);
    background: rgba(240, 249, 255, 0.45);
}
.monitor-group-item-inner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.monitor-group-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    flex: 0 0 30px;
}
.monitor-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.monitor-group-time {
    flex: 0 0 auto;
    font-size: 10px;
    color: #64748b;
}
.monitor-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.monitor-msg-row-continue {
    align-items: flex-start;
}
.monitor-msg-avatar-spacer {
    width: 32px;
    min-width: 32px;
    flex: 0 0 32px;
}
.monitor-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #334155;
    background: #e2e8f0;
    flex: 0 0 32px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(203, 213, 225, 0.95);
}
.monitor-msg-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.monitor-msg-avatar-fallback-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.monitor-msg-avatar-with-image {
    background: transparent;
    color: transparent;
}
.monitor-msg-avatar-with-image .monitor-msg-avatar-fallback-text {
    display: none;
}
.monitor-msg-avatar-fallback .monitor-msg-avatar-fallback-text {
    display: inline-flex;
}
.monitor-msg-main {
    min-width: 0;
    flex: 1 1 0%;
    width: auto;
    max-width: calc(100% - 42px);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}
.monitor-msg-main-top {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    width: 100%;
    min-width: 0;
}
.monitor-msg-main-top .monitor-msg-user-wrap {
    flex: 0 1 auto;
    min-width: 0;
    max-width: min(92%, 34rem);
}
.monitor-msg-user-wrap {
    box-sizing: border-box;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: min(92%, 34rem);
    background: rgba(241, 245, 249, 0.88);
    border: 1px solid rgba(203, 213, 225, 0.55);
    /* 略小於舊 14px：短句時不會像寬扁膠囊 */
    border-radius: 10px;
    padding: 7px 10px 9px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.monitor-msg-user-wrap-continue {
    padding-top: 6px;
    padding-bottom: 8px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}
.monitor-msg-meta-continue {
    margin-bottom: 4px;
}
.monitor-msg-meta-continue .monitor-msg-type {
    margin-bottom: 0;
}
/* 同一人連發：最後一則時間在氣泡外右側（類 LINE 小字） */
.monitor-msg-cluster-time-external {
    flex: 0 0 auto;
    flex-shrink: 0;
    align-self: flex-end;
    padding-bottom: 3px;
    line-height: 1.15;
    max-width: 4.5rem;
}
.monitor-msg-cluster-time-external .monitor-msg-time {
    font-size: 10px;
    color: #94a3b8;
    white-space: nowrap;
}
.monitor-msg-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
    min-width: 0;
    max-width: 100%;
}
.monitor-msg-user {
    font-size: 12px;
    font-weight: 600;
    color: #0f172a;
}
.monitor-msg-time {
    font-size: 11px;
    color: #64748b;
}
.monitor-msg-type {
    border-radius: 9999px;
    background: rgba(241, 245, 249, 0.85);
    color: #64748b;
    padding: 1px 7px;
    font-size: 10px;
}
.monitor-msg-bubble {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 2px 0 0;
    margin: 0;
    color: #1e293b;
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
    min-width: 0;
    max-width: 100%;
}
.monitor-msg-ai {
    margin-top: 6px;
    border-left: 3px solid #86efac;
    background: rgba(240, 253, 244, 0.55);
    color: #166534;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.6;
    white-space: pre-wrap;
}
.monitor-msg-main > .monitor-msg-ai {
    align-self: flex-start;
    width: auto;
    max-width: min(92%, 34rem);
    box-sizing: border-box;
}
.monitor-msg-image-layout {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.monitor-msg-image-preview-btn {
    border: 0;
    background: transparent;
    padding: 0;
    cursor: zoom-in;
}
.monitor-msg-image-frame {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: min(240px, 58vw);
    min-height: 180px;
    border-radius: 10px;
    border: 1px solid rgba(203, 213, 225, 0.9);
    background: #f8fafc;
    overflow: hidden;
}
.monitor-msg-image-frame-loading {
    background: linear-gradient(90deg, #e2e8f0 20%, #f8fafc 50%, #e2e8f0 80%);
    background-size: 220% 100%;
    animation: chatShimmerSlide 1.35s linear infinite;
}
.monitor-msg-image {
    max-height: 18rem;
    width: 100%;
    max-width: 100%;
    object-fit: contain;
    display: block;
}
.monitor-msg-image-actions {
    min-width: 88px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 2px;
}
.monitor-msg-image-vision-btn {
    border: 1px solid #2563eb;
    background: #2563eb;
    color: #ffffff;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    padding: 7px 10px;
    cursor: pointer;
}
.monitor-msg-image-vision-btn:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}
.monitor-msg-image-vision-btn:disabled {
    cursor: not-allowed;
    background: #cbd5e1;
    border-color: #cbd5e1;
}
.line-image-lightbox-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    max-height: calc(100vh - 8rem);
    padding: 12px;
}
.line-image-lightbox-img {
    max-width: 100%;
    max-height: calc(100vh - 10rem);
    object-fit: contain;
}
.line-image-vision-body {
    overflow-y: auto;
    max-height: calc(100vh - 12rem);
}
.monitor-msg-system {
    margin: 6px 0;
    text-align: center;
    font-size: 11px;
    color: #64748b;
}

/* Pagination select: iOS Safari fallback */
.pagination-page-size-select {
    min-height: 36px;
    line-height: 1.2;
    -webkit-appearance: menulist;
    appearance: menulist;
    background-image: none;
}

@supports (-webkit-touch-callout: none) {
    .pagination-page-size-select {
        font-size: 16px;
    }
}
