/* 定義網站全域的 CSS 變數（色號與樣式設定），方便統一管理與修改 */
:root {
    --bg-color: #f8fafc;        /* 頁面背景色：非常淺的藍灰色 */
    --text-color: #0f172a;      /* 主要文字顏色：深灰藍色 */
    --text-muted: #64748b;      /* 次要文字顏色：較淡的灰色 */
    --primary-color: #4f46e5;   /* 主要強調色：靛藍色 */
    --primary-hover: #4338ca;   /* 靛藍色 - 滑鼠懸停 */
    --primary-light: #e0e7ff;   /* 最淺的靛藍色 - 背景用 */
    --card-bg: #ffffff;         /* 卡片背景色：純白 */
    --border-color: #f1f5f9;    /* 淺邊框顏色 */
    --border-dark: #e2e8f0;     /* 稍微深一點的邊框顏色 */
    --danger-color: #ef4444;    /* 刪除或警告色：紅色 */
    --emerald-color: #34d399;   /* 成功或強調色：翠綠色 */
    --dark-bg: #0f172a;         /* 深色卡片背景 */
    
    /* 圓角大小設定 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    /* 陰影效果設定 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* 基本重置：讓所有元素的邊距歸零，並使用 border-box 模式計算大小 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 網頁整體基礎樣式 */
body {
    font-family: 'Inter', sans-serif; /* 使用現代且乾淨的 Inter 字體 */
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased; /* 讓文字在螢幕上更平滑清晰 */
}

/* 主容器：限制最大寬度並居中 */
.app-container {
    max-width: 1152px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ---------------- HEADER (標題與統計區塊) ---------------- */
.header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

/* 在平板與桌面版改變排版：變成左右兩側 */
@media (min-width: 768px) {
    .header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.header-title-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* 標題旁邊的紫色 icon 區塊 */
.header-icon {
    background-color: var(--primary-color);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    color: white;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.header-text p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.2rem;
}

/* 右上角的統計數字區塊 (總計與人數) */
.header-stats {
    display: flex;
    align-items: center;
    gap: 1rem;
    background-color: var(--card-bg);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.stat-item {
    text-align: right;
}

.stat-label {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
    font-weight: 600;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 900;
}

.grand-total-display {
    color: var(--primary-color);
}

.people-count-display {
    color: #334155;
}

/* 兩個統計數字中間的分隔線 */
.stat-divider {
    height: 2.5rem;
    width: 1px;
    background-color: var(--border-dark);
}

/* ---------------- LAYOUT (主要排版) ---------------- */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

/* 螢幕較寬時，切分為 2:1 的兩欄版型 */
@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 2fr 1fr;
    }
}

.management-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ---------------- CARDS (卡片通用樣式) ---------------- */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.card-header h2 {
    font-weight: 700;
    font-size: 1.125rem;
}

.icon-indigo {
    color: var(--primary-color);
}

.icon-emerald {
    color: var(--emerald-color);
}

/* ---------------- PARTICIPANTS (參與酒友區塊) ---------------- */
.participants-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* 每個酒友的名字標籤 */
.participant-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #eef2ff;
    color: #4338ca;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px; /* 創造藥丸形狀效果 */
    border: 1px solid var(--primary-light);
    transition: all 0.2s; /* 讓 hover 動畫更順暢 */
}

.participant-chip:hover {
    background-color: var(--primary-light);
}

.participant-chip span {
    font-weight: 500;
    font-size: 0.875rem;
}

/* 刪除按鈕通用樣式 */
.btn-remove {
    background: none;
    border: none;
    color: #a5b4fc;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.btn-remove:hover {
    color: var(--danger-color);
}

/* ---------------- FORMS (表單樣式) ---------------- */
.input-form {
    display: flex;
    gap: 0.5rem;
}

/* 所有的輸入框外觀設定 */
input {
    background-color: var(--bg-color);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.input-form input {
    flex: 1; /* 讓輸入框自動填滿剩餘寬度 */
}

/* 當使用者點擊輸入框時的提示效果 */
input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

/* 按鈕的共通設定 */
.btn-icon, .btn-primary, .btn-copy {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius-md);
    color: white;
}

.bg-dark {
    background-color: var(--dark-bg);
}

.bg-dark:hover {
    background-color: var(--primary-color);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 700;
    gap: 0.5rem;
    box-shadow: var(--shadow-md);
}

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

/* 品項輸入表單（使用 grid 排版，在手機時直立，桌面時水平排列） */
.input-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 768px) {
    .input-form-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ---------------- ITEMS (品項明細區塊) ---------------- */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* 畫面上沒有任何品項時的空狀態顯示 */
.empty-state {
    text-align: center;
    padding: 3rem 0;
    border: 2px dashed var(--border-dark);
    border-radius: var(--radius-lg);
    color: #94a3b8;
    display: none; /* 預設隱藏，由 JS 控制顯示 */
}

/* 單一品項卡片 */
.item-card {
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-lg);
    padding: 1rem;
    background-color: #fff;
    transition: box-shadow 0.2s;
}

.item-card:hover {
    box-shadow: var(--shadow-md);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.item-header h3 {
    font-weight: 700;
    color: #1e293b;
    font-size: 1rem;
}

.item-price {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1rem;
    margin-top: 0.2rem;
}

.item-participants-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.item-participants-label {
    font-size: 0.75rem;
    color: #94a3b8;
    width: 100%;
    margin-bottom: 0.25rem;
}

/* 分攤者切換按鈕 */
.toggle-participant-btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-dark);
    background-color: white;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-participant-btn:hover {
    border-color: #a5b4fc;
}

/* 當該參與者有分攤這筆品項時的樣式 (Active) */
.toggle-participant-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 分擔者按鈕後方的份數標籤 */
.share-count {
    font-size: 0.8rem;
    margin-left: 4px;
    opacity: 0.9;
    font-weight: 700;
}

/* ---------------- RESULTS (右側結帳面板) ---------------- */
/* 右邊那塊深色背景區域 */
.results-card {
    background-color: var(--dark-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    color: white;
    box-shadow: var(--shadow-xl);
    border: 1px solid #1e293b;
    position: sticky; /* 讓結帳面板在捲動時跟著螢幕停留 */
    top: 2rem;
}

.results-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* 顯示每個酒友要付多少錢的條目 */
.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.breakdown-person {
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
    position: relative;
    cursor: default;
}

/* 使用 ::after 創造出文字底下的紫色動畫線 */
.breakdown-person::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    height: 2px;
    width: 0;
    background-color: #8b5cf6;
    transition: width 0.3s;
}

/* 當滑鼠移過去時，線條展開 */
.breakdown-item:hover .breakdown-person::after {
    width: 100%;
}

.breakdown-amount {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: monospace; /* 數字使用等寬字體更清晰 */
}

.currency-symbol {
    color: #64748b;
    font-size: 0.75rem;
    margin-right: 0.25rem;
}

/* 費用總結底部區域 */
.summary-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #1e293b;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    color: #94a3b8;
}

.text-emerald {
    color: rgba(52, 211, 153, 0.8);
}

.grand-total-row {
    padding-top: 0.5rem;
    color: #e2e8f0;
    font-weight: 700;
}

.grand-total-row span:last-child {
    font-size: 1.5rem;
    font-weight: 900;
    color: #818cf8;
}

/* 複製結算明細的大按鈕 */
.btn-copy {
    width: 100%;
    margin-top: 1rem;
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 1rem;
    gap: 0.5rem;
    box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.39);
}

.btn-copy:hover {
    background-color: #6366f1; /* 較淺的紫色 */
}

/* 按下去那瞬間縮小的動畫效果 */
.btn-copy:active {
    transform: scale(0.98);
}

.drink-responsibly {
    font-size: 0.625rem;
    text-align: center;
    color: #64748b;
    margin-top: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
