/* --- V9.0 外觀_視覺風格.css --- */
/* 從 index.html 抽離，負責所有 UI/UX 視覺呈現 */

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Microsoft JhengHei", sans-serif;
    background: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
    color: #1e293b;
    font-size: 16.5px;
    line-height: 1.55;
    overflow-y: auto;
    min-height: 100vh;
}

/* --- Card Systems --- */
.glass-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    border: 1px solid rgba(255, 255, 255, 0.6);
    transition: transform 0.2s ease;
}

.card-elevated {
    border-radius: 1.25rem;
    background: linear-gradient(135deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
    box-shadow: 0 16px 40px rgba(15,23,42,0.06);
    border: 1px solid rgba(148,163,184,0.20);
}

/* --- Typography & Sections --- */
.section-header {
    background: linear-gradient(120deg, #1e293b 0%, #334155 100%);
    color: white;
    border-radius: 18px 18px 0 0;
    padding: 16px 24px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* --- Inputs --- */
input.editable-clean {
    width: 50px; text-align: center; padding: 4px; height: 32px;
    border-radius: 6px; border: 1px solid #cbd5e1; background-color: white;
    font-weight: 700; color: #334155; transition: all 0.2s;
    font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace !important;
}
#in_tax_year { width: 92px !important; min-width: 92px !important; }
#in_basic_living_unit { width: 110px !important; min-width: 110px !important; }

input.editable-clean:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); outline: none; }

input.editable {
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid #cbd5e1; border-radius: 8px; padding: 4px 12px;
    color: #0f172a; font-weight: 700; font-family: 'JetBrains Mono', monospace;
    transition: all 0.2s; text-align: right; font-size: 18px; width: 100%; min-width: 0px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02) inset;
    font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
input.editable:focus { background-color: #fff; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); outline: none; color: #1d4ed8; }

input.editable-shares { background-color: #f3e8ff; border-color: #d8b4fe; color: #7e22ce; }
input.editable-auto { background-color: #e0f2fe; color: #0369a1; border-color: #bae6fd; cursor: default; font-weight: 800; }
input.editable-text { background-color: rgba(255, 255, 255, 0.5); border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; color: #334155; font-weight: 500; font-family: 'Inter', sans-serif; text-align: left; font-size: 15px; width: 100%; box-shadow: 0 1px 2px rgba(0,0,0,0.02) inset; }
input.header-editable { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: white; width: 110px; text-align: center; border-radius: 8px; font-size: 1.4rem; font-weight: 800; padding: 2px 8px; font-family: 'JetBrains Mono', monospace; }
input.editable-sm { width: 50px; text-align: center; padding: 4px; height: 32px; border-radius: 6px; border: 1px solid #cbd5e1; font-weight: bold; }
input[type="number"] { -webkit-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.privacy-blur { color: transparent !important; text-shadow: 0 0 10px rgba(0,0,0,0.4); background-color: #e2e8f0 !important; user-select: none; }

/* --- Buttons --- */
.btn-reset { background: linear-gradient(to bottom, #475569, #334155); color: white; padding: 10px 24px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); border: 1px solid rgba(255,255,255,0.1); }
.btn-stress { font-size: 11px; padding: 2px 8px; background: #fff; border: 1px solid #cbd5e1; border-radius: 4px; color: #64748b; cursor: pointer; font-family: 'JetBrains Mono', monospace; }
.btn-stress:hover { background: #eff6ff; color: #2563eb; border-color: #2563eb; }

/* --- Utilities --- */
.custom-scrollbar::-webkit-scrollbar { width: 8px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; border: 2px solid #fff; }
details > summary { list-style: none; outline: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] summary ~ * { animation: sweep .25s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes sweep { 0% {opacity: 0; transform: translateY(-8px)} 100% {opacity: 1; transform: translateY(0)} }

/* --- Tags & Status --- */
.roi-tag { font-size: 13px; padding: 3px 8px; border-radius: 6px; margin-left: 8px; font-weight: 800; white-space: nowrap; display: inline-block; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.roi-pos { background-color: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.roi-neg { background-color: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.roi-neutral { background-color: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.status-ok { background-color: #10b981; box-shadow: 0 0 8px #10b981; }
.status-err { background-color: #ef4444; }
.status-wait { background-color: #f59e0b; animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* --- Layout Components --- */
.row-layout { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 6px 0; border-bottom: 1px dashed #e2e8f0; flex-wrap: wrap; }
.row-layout:hover { background-color: #f9fafb; }
.row-layout:last-child { border-bottom: none; }
.row-layout > * { min-width: 0; }
.label-text { font-size: 16.5px; font-weight: 600; color: #334155; white-space: nowrap; flex-shrink: 0; min-width: 0; }
.sub-label { font-size: 12px; color: #64748b; font-weight: 500; margin-left: 4px; opacity: 0.8; }
.input-wrapper { flex-grow: 1; display: flex; justify-content: flex-end; min-width: 140px; gap: 0.5rem; }
.input-wrapper input.editable { max-width: 320px; }
.stack-group { background: white; border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }

/* --- Timeline & Progress --- */
.timeline-item { position: relative; padding-left: 24px; padding-bottom: 24px; border-left: 2px solid #e2e8f0; }
.timeline-item:last-child { border-left: 2px solid transparent; }
.timeline-dot { position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid #8b5cf6; }
.tax-progress-bg { height: 6px; background: #334155; border-radius: 3px; margin-top: 8px; overflow: hidden; position: relative; }
.tax-progress-bar { height: 100%; background: linear-gradient(90deg, #fbbf24, #f59e0b); border-radius: 3px; transition: width 0.5s ease; }

/* --- Toast --- */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { background: white; padding: 12px 20px; border-radius: 10px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); border-left: 4px solid #10b981; display: flex; align-items: center; gap: 10px; transform: translateX(120%); transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55); font-size: 14px; font-weight: 700; color: #334155; pointer-events: auto; }
.toast.show { transform: translateX(0); }

/* --- Matrix Table --- */
.matrix-table { width: 100%; font-size: 13px; text-align: center; border-collapse: collapse; margin-top: 5px; }
.matrix-table th { font-weight: 700; color: #64748b; padding: 8px; border-bottom: 1px solid #e2e8f0; font-size: 11px; text-transform: uppercase; }
.matrix-table td { padding: 8px; font-family: 'JetBrains Mono', monospace; font-weight: 700; color: #334155; }
.matrix-current { background-color: #eff6ff; color: #2563eb; border-radius: 6px; }
.matrix-table tbody tr:nth-child(odd) td { background-color: #f8fafc; }
.matrix-table tbody tr:nth-child(even) td { background-color: #ffffff; }
.matrix-table tbody tr:hover td { background-color: #e0f2fe; }

/* --- Command Bar (V8.5.2) --- */
.command-bar { position: sticky; top: 0; z-index: 50; background: rgba(248,250,252,0.92); backdrop-filter: blur(10px); border: 1px solid rgba(148,163,184,0.25); box-shadow: 0 10px 25px rgba(15,23,42,0.06); }
.cmd-btn { display: inline-flex; align-items: center; gap: .5rem; padding: 8px 12px; border-radius: 12px; border: 1px solid rgba(148,163,184,0.35); background: rgba(255,255,255,0.85); font-weight: 800; font-size: 12px; color: #334155; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; user-select: none; }
.cmd-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 20px rgba(15,23,42,0.08); border-color: rgba(59,130,246,0.45); }
.cmd-btn:active { transform: translateY(0); }
.cmd-btn-primary { background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(16,185,129,0.12)); border-color: rgba(59,130,246,0.35); }
.cmd-pill { display:inline-flex; align-items:center; gap:.5rem; padding: 6px 10px; border-radius: 9999px; border: 1px solid rgba(148,163,184,0.30); background: rgba(255,255,255,0.75); min-width: 0; }
.cmd-pill > * { min-width: 0; }

.tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 9999px; border: 1px solid rgba(148,163,184,0.45); background: rgba(255,255,255,0.85); color: #64748b; font-weight: 900; font-size: 12px; cursor: help; margin-left: 8px; }
.tip:hover { border-color: rgba(59,130,246,0.55); color: #1d4ed8; }
.tip[data-tip]:hover::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 10px); transform: translateX(-50%); min-width: 240px; max-width: 360px; padding: 10px 12px; border-radius: 14px; background: rgba(15,23,42,0.96); color: #f8fafc; font-weight: 700; font-size: 12px; line-height: 1.4; box-shadow: 0 18px 40px rgba(0,0,0,0.20); border: 1px solid rgba(255,255,255,0.10); z-index: 999; white-space: normal; }
.tip[data-tip]:hover::before { content: ""; position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%) rotate(45deg); width: 10px; height: 10px; background: rgba(15,23,42,0.96); border-left: 1px solid rgba(255,255,255,0.10); border-top: 1px solid rgba(255,255,255,0.10); z-index: 999; }

/* --- Collapsible --- */
.collapse-shell { border-radius: 1.25rem; overflow: hidden; border: 1px solid rgba(148,163,184,0.18); background: rgba(255,255,255,0.92); box-shadow: 0 14px 32px rgba(15,23,42,0.05); }
.collapse-summary { display:flex; align-items:center; justify-content: space-between; gap: 12px; padding: 14px 18px; background: linear-gradient(120deg, #0f172a 0%, #1f2937 100%); color: white; cursor: pointer; user-select:none; }
.collapse-summary .title { font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; opacity: .95; }
.collapse-summary .hint { font-size: 11px; font-weight: 800; color: rgba(226,232,240,0.85); }
.collapse-body { padding: 18px 18px 22px 18px; }

/* --- Diagram / Group Cards --- */
.diagram-card { background: radial-gradient(circle at top, rgba(59,130,246,0.14), transparent 60%), linear-gradient(135deg, rgba(255,255,255,0.96), rgba(248,250,252,0.96)); border: 1px solid rgba(148,163,184,0.22); border-radius: 24px; box-shadow: 0 18px 45px rgba(15,23,42,0.08); }
.diagram-metric { font-family: 'JetBrains Mono', monospace; }
.diagram-divider { width: 1px; background: rgba(148,163,184,0.35); }
.group-card { box-shadow: 0 1px 2px rgba(15,23,42,0.04); }
.group-card .group-title { display:flex; align-items:center; gap:.5rem; }
.group-card .group-hint { font-size: 12px; color: #64748b; }

/* --- KPI Cards (Revamp) --- */
.kpi-section-divider{ height: 1px; background: linear-gradient(to right, rgba(15,23,42,0.00), rgba(15,23,42,0.14), rgba(15,23,42,0.00)); box-shadow: 0 1px 0 rgba(255,255,255,0.65); margin: 22px 0 30px; }
@media (min-width: 768px){ .kpi-section-divider{ margin: 26px 0 34px; } }
.kpi-section-divider + .grid{ padding-top: 6px; }
.kpi-card { position: relative; overflow: hidden; background: linear-gradient(135deg, rgba(255,255,255,0.96), rgba(248,250,252,0.96)); box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06); border-radius: 1.25rem; border: 1px solid rgba(148, 163, 184, 0.18); transform: translateY(0); transition: transform 0.18s ease-out, box-shadow 0.18s ease-out, border-color 0.18s ease-out, background 0.18s ease-out; min-width: 180px; }
.kpi-card::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at top left, rgba(56,189,248,0.25), transparent 55%), radial-gradient(circle at top right, rgba(52,211,153,0.25), transparent 55%); opacity: 0.9; pointer-events: none; }
.kpi-card > * { position: relative; z-index: 1; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 18px 40px rgba(15, 23, 42, 0.10); border-color: rgba(59, 130, 246, 0.35); }
.kpi-card .kpi-body { min-height: 140px; }
.kpi-metric-value { font-variant-numeric: tabular-nums; }
.kpi-metric-unit { margin-left: 6px; vertical-align: baseline; }

.kpi2-value-row { display:flex; align-items: baseline; gap: 6px; min-width: 0; }
.kpi2-value { font-variant-numeric: tabular-nums; font-size: clamp(18px, 2.0vw, 28px); line-height: 1.05; font-weight: 900; letter-spacing: -0.015em; white-space: nowrap; overflow: visible; text-overflow: clip; }
.kpi2-gap { color: rgba(220, 38, 38, 0.92); }
.kpi2-unit { margin-top: 6px; font-size: 12px; font-weight: 700; color: rgba(100, 116, 139, 0.95); letter-spacing: 0.08em; }
@supports (container-type: inline-size) {
  .kpi2-cell { container-type: inline-size; min-width: 0; }
  .kpi2-value { font-size: clamp(18px, 9cqw, 28px); }
}

.goal-status-tag { letter-spacing: 0.03em; }
.goal-status-neutral { background-color: #e5e7eb; color: #374151; }
.goal-status-safe { background-color: #dcfce7; color: #166534; }
.goal-status-warning { background-color: #fef9c3; color: #92400e; }
.goal-status-danger { background-color: #fee2e2; color: #b91c1c; }

/* --- Special Rows --- */
.basic-living-row { display: flex !important; flex-wrap: wrap !important; align-items: center !important; gap: 10px !important; }
.basic-living-row .basic-living-left { display: flex !important; flex-wrap: wrap !important; align-items: center !important; gap: 10px !important; min-width: 260px !important; }
.basic-living-row .basic-living-left .sub-label { display: inline-flex !important; align-items: center !important; gap: 6px !important; max-width: 100% !important; margin-left: 0 !important; }
.basic-living-row #out_basic_living_total { margin-left: auto !important; flex: 0 0 auto !important; white-space: nowrap !important; line-height: 1; }
@media (max-width: 640px){ .basic-living-row #out_basic_living_total { margin-left: 0 !important; width: 100% !important; text-align: right !important; } }

.interest-income-row .flex.justify-between.items-center { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.interest-income-row .flex.justify-between.items-center .label-text { flex: 1 1 auto; min-width: 0; }
.interest-income-row .flex.justify-between.items-center label { margin-left: auto; flex: 0 0 auto; white-space: nowrap; }

.fx-box { display:flex; flex-wrap:wrap; align-items:center; gap:12px; max-width:100%; box-sizing:border-box; min-width: 0; }
.fx-box > span { order:1; flex:0 0 auto; }
.fx-box > input { order:2; flex:1 1 180px; min-width:140px; max-width:100%; font-family: 'JetBrains Mono', monospace !important; padding-left: 8px; padding-right: 8px; }
.fx-box > div { order:3; flex:1 1 100%; width:100%; margin-left:0 !important; display:flex !important; flex-direction:row !important; justify-content:flex-end; flex-wrap:wrap; gap:10px; }

#out_tax_amount { margin-left: auto; padding-left: 10px; max-width: 100%; line-height: 1.05; letter-spacing: 0.01em; font-size: clamp(1.9rem, 4.6vw, 2.35rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Cashflow Timeline --- */
.cashflow-timeline { --tl-pad: 32px; }
.cashflow-timeline .tl-dot { left: calc(-1 * (var(--tl-pad) + 14px)) !important; }
.cashflow-timeline .tl-dot.tl-dot-lg { left: calc(-1 * (var(--tl-pad) + 14px)) !important; }

/* --- Dividend Radar Style --- */
#dividend-radar-list { display: flex; flex-direction: column; gap: 14px; padding: 14px; }

/* --- Mobile Responsive --- */
@media (max-width: 640px) {
    body { padding: 10px !important; padding-bottom: 140px !important; }
    .max-w-\[1920px\] { padding-left: 0.25rem !important; padding-right: 0.25rem !important; }
    .command-bar { padding-left: 12px !important; padding-right: 12px !important; }
    .command-bar .custom-scrollbar { flex-direction: column !important; align-items: stretch !important; justify-content: flex-start !important; gap: 10px !important; overflow-x: visible !important; white-space: normal !important; }
    .command-bar .custom-scrollbar > div { flex-wrap: wrap !important; white-space: normal !important; }
    .command-bar .custom-scrollbar > div:last-child { justify-content: flex-start !important; gap: 8px !important; }
    .command-bar h1 { font-size: 18px !important; }
    .cmd-pill { flex-wrap: wrap !important; }
    #cmd_search { width: 120px !important; max-width: 55vw !important; }
    .glass-card, .diagram-card { max-width: 100% !important; }
    .privacy-target { max-width: 100% !important; }
    canvas { max-width: 100% !important; height: auto !important; }
    .cmd-actions { display: none !important; }
    .command-bar.is-expanded .cmd-actions { display: flex !important; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
    .command-bar.is-expanded .cmd-actions .cmd-pill { flex-wrap: wrap; }
    #cmd_mobile_toggle { white-space: nowrap; }
}

/* --- Font & Base Utilities --- */
.font-mono, .font-mono * { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
html { -webkit-text-size-adjust: 100%; }