/* =============================================================
   Loan UI - 9.2.6 共享元件樣式
   將原本散落在各視圖的 inline 樣式集中、cache、壓縮
   命名規範：ui-*（通用）/ loan-app-*（業務專用）
   ============================================================= */

/* ---------- 表單分組（4 步精靈）---------- */
.loan-app-form-group,
.ui-form-group {
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.4rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.loan-app-form-group__header,
.ui-form-group__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed #e2e8f0;
}
.loan-app-form-group__index,
.ui-form-group__index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.9rem;
}
.loan-app-form-group__title,
.ui-form-group__title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}
.loan-app-form-group__hint,
.ui-form-group__hint {
    font-size: 0.78rem;
    color: #64748b;
    margin: 0 0 0 0.5rem;
}
@media (max-width: 768px) {
    .loan-app-form-group, .ui-form-group { padding: 0.85rem 1rem; }
}

/* ---------- 即時計算器（貸款/還款）---------- */
.loan-app-calculator,
.loan-calculator,
.repayment-summary {
    position: sticky;
    top: 1rem;
    padding: 1.25rem 1.4rem;
    background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 50%, #38bdf8 100%);
    border-radius: 16px;
    color: #ffffff;
    box-shadow: 0 18px 36px rgba(37, 99, 235, 0.28);
}
.loan-app-calculator__title,
.loan-calculator__title,
.repayment-summary__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: rgba(255, 255, 255, 0.95);
}
.loan-app-calculator__row,
.loan-calculator__row,
.repayment-summary__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.loan-app-calculator__row:last-child,
.loan-calculator__row:last-child,
.repayment-summary__row:last-child {
    border-bottom: 0;
    padding-top: 0.7rem;
    margin-top: 0.3rem;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
}
.loan-app-calculator__label,
.loan-calculator__label,
.repayment-summary__label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}
.loan-app-calculator__value,
.loan-calculator__value,
.repayment-summary__value {
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
}
.loan-app-calculator__row--total .loan-app-calculator__value,
.loan-calculator__row--total .loan-calculator__value,
.repayment-summary__row--total .repayment-summary__value {
    font-size: 1.2rem;
}
.loan-app-calculator__hint,
.loan-calculator__hint,
.repayment-summary__hint {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.75);
    margin-top: 0.75rem;
}

/* 還款卡片白底變體 */
.repayment-summary {
    background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}
.repayment-summary__label { color: #475569; }
.repayment-summary__value { color: #0f172a; }
.repayment-summary__row { border-bottom-color: #e2e8f0; }
.repayment-summary__row:last-child {
    border-top-color: #cbd5e1;
    border-bottom: 0;
}

/* ---------- 還款進度條 ---------- */
.repayment-amount-progress {
    display: block;
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
    margin: 0.5rem 0;
}
.repayment-amount-progress__bar {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #22c55e 0%, #16a34a 100%);
    border-radius: 999px;
    transition: width 0.3s ease;
}
.repayment-amount-progress--warn .repayment-amount-progress__bar {
    background: linear-gradient(90deg, #f59e0b 0%, #dc2626 100%);
}
.repayment-amount-warn {
    display: none;
    color: #dc2626;
    font-size: 0.78rem;
    margin-top: 0.25rem;
    font-weight: 500;
}
.repayment-amount-warn.is-shown { display: block; }

/* ---------- 快速金額膠囊 ---------- */
.repayment-quick-amounts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.5rem 0 0.75rem;
}
.repayment-quick-amounts__btn {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.repayment-quick-amounts__btn:hover {
    background: #eff6ff;
    border-color: #2563eb;
}
.repayment-quick-amounts__btn[aria-pressed="true"] {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

/* ---------- 兩欄（主+側）排版 ---------- */
.loan-app-form-layout,
.loan-form-layout,
.repayment-form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
    gap: 1.25rem;
}
@media (max-width: 1199px) {
    .loan-app-form-layout,
    .loan-form-layout,
    .repayment-form-layout {
        grid-template-columns: 1fr;
    }
    .loan-app-calculator,
    .loan-calculator,
    .repayment-summary {
        position: static;
    }
}

/* ---------- 還款時間軸（5 段式視圖）---------- */
.schedule-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}
.schedule-kpi {
    padding: 0.85rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.schedule-kpi__label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin: 0 0 0.15rem;
    font-weight: 500;
}
.schedule-kpi__value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    font-variant-numeric: tabular-nums;
}
.schedule-kpi--success .schedule-kpi__value { color: #16a34a; }
.schedule-kpi--danger .schedule-kpi__value  { color: #dc2626; }
.schedule-kpi--info .schedule-kpi__value    { color: #0ea5e9; }
@media (max-width: 576px) {
    .schedule-kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .schedule-kpi { padding: 0.6rem 0.7rem; }
    .schedule-kpi__value { font-size: 1rem; }
}

.schedule-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.75rem 0;
}
.schedule-filters__btn {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.schedule-filters__btn[aria-pressed="true"] {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1d4ed8;
}

.schedule-timeline {
    position: relative;
    margin: 1rem 0;
    padding: 1.25rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.schedule-timeline__track {
    position: relative;
    height: 4px;
    background: #e2e8f0;
    border-radius: 999px;
    margin: 0 1rem 1rem;
}
.schedule-timeline__progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, #22c55e 0%, #16a34a 100%);
    border-radius: 999px;
    transition: width 0.3s;
}
.schedule-timeline__now {
    position: absolute;
    top: -8px;
    width: 4px;
    height: 20px;
    background: #dc2626;
    border-radius: 2px;
}
.schedule-timeline__nodes {
    display: flex;
    gap: 0.5rem;
    min-width: max-content;
    padding: 0 0.5rem;
}
.schedule-timeline__node {
    flex: 0 0 auto;
    width: 92px;
    padding: 0.6rem 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.schedule-timeline__node:hover {
    border-color: #2563eb;
    transform: translateY(-2px);
}
.schedule-timeline__node--current {
    border-color: #2563eb;
    background: #eff6ff;
}
.schedule-timeline__node--paid .schedule-timeline__marker    { background: #16a34a; }
.schedule-timeline__node--overdue .schedule-timeline__marker { background: #dc2626; }
.schedule-timeline__node--pending .schedule-timeline__marker { background: #0ea5e9; }
.schedule-timeline__node--delayed .schedule-timeline__marker { background: #f59e0b; }
.schedule-timeline__node--upcoming .schedule-timeline__marker{ background: #94a3b8; }
.schedule-timeline__marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #cbd5e1;
    margin: 0 auto 0.4rem;
}
.schedule-timeline__index {
    font-size: 0.78rem;
    font-weight: 700;
    color: #0f172a;
}
.schedule-timeline__amount {
    font-size: 0.78rem;
    color: #1e293b;
    font-variant-numeric: tabular-nums;
    margin: 0.15rem 0;
}
.schedule-timeline__date {
    font-size: 0.7rem;
    color: #64748b;
}
@media (max-width: 768px) {
    .schedule-timeline__node { width: 76px; padding: 0.4rem 0.3rem; }
    .schedule-timeline__index { font-size: 0.7rem; }
}

.schedule-detail {
    margin: 1rem 0;
    padding: 1rem 1.1rem;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.schedule-detail__row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px dashed #e2e8f0;
}
.schedule-detail__row:last-child { border-bottom: 0; }
.schedule-detail__label { color: #64748b; font-size: 0.85rem; }
.schedule-detail__value { font-weight: 600; color: #0f172a; font-variant-numeric: tabular-nums; }
.schedule-detail__row--total .schedule-detail__value { color: #1d4ed8; font-size: 1.05rem; }

.ui-table-row-highlight {
    animation: ui-row-flash 1.5s ease;
}
@keyframes ui-row-flash {
    0%   { background-color: #fef3c7; }
    100% { background-color: transparent; }
}

/* ---------- 客戶 360° 視圖（Hero / 聯繫 / 時間軸）---------- */
.client-hero {
    position: relative;
    padding: 1.5rem 1.5rem 1.25rem;
    border-radius: 16px;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 60%, #6366f1 100%);
    color: #ffffff;
    box-shadow: 0 12px 28px rgba(59, 130, 246, 0.25);
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) {
    .client-hero { padding: 1rem; }
}
.client-hero__top {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.client-hero__avatar {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.4);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    flex-shrink: 0;
}
.client-hero__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.client-hero__main { flex: 1 1 0; min-width: 0; }
.client-hero__name {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.client-hero__status {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.4);
}
.client-hero__status--active    { background: rgba(34, 197, 94, 0.35); }
.client-hero__status--pending   { background: rgba(245, 158, 11, 0.4); }
.client-hero__status--inactive  { background: rgba(100, 116, 139, 0.4); }
.client-hero__status--closed    { background: rgba(71, 85, 105, 0.5); }
.client-hero__status--deceased  { background: rgba(220, 38, 38, 0.45); }
.client-hero__number {
    margin-top: 0.3rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}
.client-hero__contacts {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.client-hero__contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.85rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.32);
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    min-height: 44px;
}
.client-hero__contact-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    color: #ffffff;
}
.client-hero__metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.client-hero__metric {
    text-align: center;
    color: #ffffff;
}
.client-hero__metric-value {
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    display: block;
}
.client-hero__metric-value--warning { color: #fde68a; }
.client-hero__metric-value--success { color: #bbf7d0; }
.client-hero__metric-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.75);
    margin-top: 0.15rem;
    display: block;
}
@media (max-width: 576px) {
    .client-hero__metrics { grid-template-columns: repeat(2, 1fr); }
    .client-hero__avatar { width: 56px; height: 56px; }
}

/* 客戶時間軸 */
.client-timeline {
    margin: 1.25rem 0;
}
.client-timeline__title {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.client-timeline__list {
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
}
.client-timeline__list::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 14px;
    width: 2px;
    background: #e2e8f0;
}
.client-timeline__item {
    position: relative;
    padding: 0.5rem 0 0.85rem 2.25rem;
    border-bottom: 1px dashed #e2e8f0;
}
.client-timeline__item:last-child { border-bottom: 0; }
.client-timeline__node {
    position: absolute;
    top: 0.6rem;
    left: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
}
.client-timeline__node--info    { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.client-timeline__node--success { background: #dcfce7; color: #15803d; border-color: #86efac; }
.client-timeline__node--primary { background: #e0e7ff; color: #4338ca; border-color: #a5b4fc; }
.client-timeline__node--warning { background: #fef3c7; color: #b45309; border-color: #fcd34d; }
.client-timeline__heading {
    margin: 0;
    font-size: 0.9rem;
    color: #0f172a;
    font-weight: 600;
}
.client-timeline__heading a {
    color: #1d4ed8;
    text-decoration: none;
}
.client-timeline__heading a:hover { text-decoration: underline; }
.client-timeline__date {
    font-size: 0.75rem;
    color: #64748b;
    margin-left: 0.5rem;
}
.client-timeline__desc {
    font-size: 0.82rem;
    color: #475569;
    margin: 0.15rem 0 0;
}
.client-timeline__empty {
    color: #64748b;
    font-size: 0.85rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px dashed #cbd5e1;
}
@media (max-width: 768px) {
    .client-timeline__item { padding-left: 2rem; }
    .client-timeline__node { width: 24px; height: 24px; }
    .client-timeline__list::before { left: 11px; }
}

/* ---------- 客戶詳情 Tabs / 快速操作 ---------- */
.client-show-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.client-show-tabs__btn {
    border: 0;
    background: transparent;
    color: #64748b;
    padding: 0.7rem 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.client-show-tabs__btn:hover { color: #1d4ed8; }
.client-show-tabs__btn[aria-selected="true"] {
    color: #1d4ed8;
    border-bottom-color: #1d4ed8;
}
.client-show-tab__badge {
    background: #e2e8f0;
    color: #1e293b;
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 600;
}
.client-show-tabs__btn[aria-selected="true"] .client-show-tab__badge {
    background: #1d4ed8;
    color: #ffffff;
}

.client-quick-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.4rem;
}
.client-quick-actions__btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    color: #0f172a;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    min-height: 44px;
    transition: all 0.15s;
}
.client-quick-actions__btn:hover {
    background: #eff6ff;
    border-color: #2563eb;
    color: #1d4ed8;
}
.client-quick-actions__btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* ---------- 編輯欄位 ---------- */
.editable-field {
    border-bottom: 1px dashed #007bff;
    cursor: pointer;
    padding: 2px 4px;
    display: inline-block;
    min-width: 30px;
}
.editable-field:hover {
    background-color: #e9f5ff;
    border-bottom: 1px solid #007bff;
}
.editable-field input {
    padding: 2px 4px;
    font-size: inherit;
    line-height: inherit;
    border: 1px solid #007bff;
    border-radius: 3px;
    outline: none;
}

/* ---------- sr-only 別名（相容舊 inline 樣式）---------- */
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Button height override (compact ~30px) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.25rem;
    min-height: 30px;
}
.btn-lg, .btn-group-lg > .btn {
    padding: 0.375rem 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    min-height: 34px;
}
.btn-sm, .btn-group-sm > .btn {
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1rem;
    min-height: 26px;
}

/* Input group button height alignment */
.input-group .btn {
    min-height: auto;
    height: 100%;
    padding: 0.25rem 0.75rem;
}
.input-group-sm .btn {
    min-height: auto;
    height: 100%;
    padding: 0.125rem 0.5rem;
}
.input-group-lg .btn {
    min-height: auto;
    height: 100%;
    padding: 0.375rem 1rem;
}
