/* ==================== 重置與基礎樣式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #2c3e50;
    --secondary: #3498db;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --light: #ecf0f1;
    --dark: #2c3e50;
    --gray: #95a5a6;
    --radius: 12px;
    --shadow: 0 4px 12px rgba(0,0,0,0.1);
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    background: #f5f7fa;
    min-height: 100vh;
    padding-bottom: 80px;
}

/* ==================== 底部導航 ==================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #ddd;
    display: flex;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    height: 60px;
}

.bottom-nav.hidden {
    transform: translateY(100%);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--gray);
    font-size: 0.7rem;
    padding: 8px 4px;
    transition: var(--transition);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: var(--secondary);
}

.nav-icon {
    font-size: 1.3rem;
    margin-bottom: 2px;
}

.nav-item.locked {
    color: var(--gray);
    opacity: 0.5;
    pointer-events: auto;
}

/* 導覽列收合按鈕 */
.nav-toggle-btn {
    position: fixed;
    bottom: 68px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #ddd;
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    padding: 4px 16px;
    cursor: pointer;
    z-index: 1001;
    box-shadow: 0 -2px 6px rgba(0,0,0,0.08);
    color: var(--gray);
    font-size: 0.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.nav-toggle-btn.nav-hidden {
    bottom: 0;
}

.nav-toggle-btn i {
    transition: transform 0.3s ease;
}

.nav-toggle-btn.nav-hidden i {
    transform: rotate(180deg);
}

/* 兩種導覽列共用樣式 */
.user-nav, .admin-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #ddd;
    display: flex;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    height: 60px;
    transition: transform 0.3s ease;
}

.user-nav.hidden, .admin-nav.hidden {
    transform: translateY(100%);
}

/* ==================== 頂部標題 ==================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary);
    color: white;
    padding: 10px 12px;
    min-height: 60px;
    position: sticky;
    top: 0;
    z-index: 999;
}

.logo-container {
    flex-shrink: 0;
    margin-right: 10px;
}

.site-logo {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: contain;
    background: none;
    padding: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.title-container {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.header h1 {
    font-size: 1.2rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

.header-subtitle {
    font-size: 0.7rem;
    opacity: 0.8;
    color: white;
}

.admin-btn{
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.3s ease;
    white-space: nowrap;
    padding: 6px 10px;
    font-size: 0.75rem;
    -webkit-tap-highlight-color: transparent;
}

.admin-btn span{
    display: inline;
}

.admin-btn span:first-child{
    font-size: 1rem;
    line-height: 1;
}

/* ==================== 頁面容器 ==================== */
.page-container {
    display: none;
    padding: 12px;
    animation: fadeIn 0.3s ease;
}

.page-container.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== 卡片樣式 ==================== */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--light);
}

.card-title {
    font-size: 1rem;
    color: var(--primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== 表單樣式 ==================== */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--primary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #ddd;
    border-radius: var(--radius);
    font-size: 1rem;
    transition: var(--transition);
    -webkit-appearance: none;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--secondary);
}

.form-text {
    font-size: 0.75rem;
    color: var(--gray);
    margin-top: 4px;
}

/* ==================== 按鈕樣式 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    width: 100%;
    gap: 8px;
    margin: 6px 0;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

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

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-secondary {
    background: var(--gray);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-info {
    background: #00bcd4;
    color: white;
}

/* 按鈕群組 */
.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.button-group .btn {
    flex: 1;
    min-width: 120px;
}

/* ==================== 餘額顯示 ==================== */
.balance-display {
    text-align: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: var(--radius);
    color: white;
    margin: 16px 0;
}

.balance-amount {
    font-size: 2.5rem;
    font-weight: bold;
    margin: 8px 0;
}

.balance-box {
    text-align: center;
    padding: 16px;
    background: var(--light);
    border-radius: var(--radius);
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 16px;
}

.balance-positive {
    color: var(--success);
}

.balance-negative {
    color: var(--danger);
}

/* ==================== 表格樣式 ==================== */
.table-container {
    overflow-x: auto;
    margin: 12px 0;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 350px;
    font-size: 0.85rem;
    background: white;
    border-radius: var(--radius);
}

.table th {
    background: var(--light);
    color: var(--primary);
    font-weight: 600;
    padding: 10px 8px;
    text-align: left;
    border-bottom: 2px solid #ddd;
}

.table td {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
}

/* ==================== 管理員區塊 ==================== */
.admin-section {
    background: #f5f3ff;
    border: 1px solid #cbd5e1;
    border-left: 4px solid #5b21b6;
    padding: 12px;
    border-radius: 12px;
    margin: 12px 0;
}

/* ==================== 訊息樣式 ==================== */
.message {
    padding: 12px;
    border-radius: var(--radius);
    margin: 12px 0;
    border-left: 4px solid transparent;
    font-size: 0.9rem;
}

.message.success {
    background: rgba(39, 174, 96, 0.1);
    border-left-color: var(--success);
    color: var(--success);
}

.message.error {
    background: rgba(231, 76, 60, 0.1);
    border-left-color: var(--danger);
    color: var(--danger);
}

.message.warning {
    background: rgba(243, 156, 18, 0.1);
    border-left-color: var(--warning);
    color: var(--warning);
}

.message.info {
    background: rgba(52, 152, 219, 0.1);
    border-left-color: var(--secondary);
    color: var(--secondary);
}

/* ==================== 載入動畫 ==================== */
.loading {
    text-align: center;
    padding: 30px 16px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(52, 152, 219, 0.3);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.fa-spinner {
    animation: spin 1s linear infinite;
}

/* ==================== 模態視窗 ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 380px;
    max-height: 85vh;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    background: var(--primary);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.modal-body {
    padding: 16px;
    max-height: 55vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 16px;
    background: var(--light);
    display: flex;
    gap: 10px;
}

.modal-footer .btn {
    margin: 0;
}

/* ==================== 頁腳 ==================== */
.footer {
    text-align: center;
    padding: 20px 16px;
    color: var(--gray);
    font-size: 0.8rem;
    line-height: 1.5;
}

.footer a {
    color: var(--secondary);
    text-decoration: none;
}

details.custom-arrow > summary {
    list-style-type: none;
    position: relative;
    padding-left: 22px;
    cursor: pointer;
}

details.custom-arrow > summary::before {
    content: '▶';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s;
    font-size: 0.8rem;
}

details.custom-arrow[open] > summary::before {
    transform: translateY(-50%) rotate(90deg);
}

/* ==================== 響應式設計 ==================== */
@media (min-width: 768px) {
    body {
        max-width: 450px;
        margin: 0 auto;
        padding-bottom: 0;
    }

    .user-nav, .admin-nav {
        max-width: 450px;
        left: 50%;
        transform: translateX(-50%);
    }

    .user-nav.hidden, .admin-nav.hidden {
        transform: translateX(-50%) translateY(100%);
    }

    .nav-toggle-btn {
        left: 50%;
        transform: translateX(-50%);
    }

    .nav-toggle-btn.nav-hidden {
        bottom: 0;
        transform: translateX(-50%);
    }
}

@media (max-width: 480px) {
    .header {
        padding: 8px 10px;
    }

    .site-logo {
        width: 40px;
        height: 40px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .header-subtitle {
        font-size: 0.65rem;
    }

    .balance-amount {
        font-size: 2rem;
    }

    .btn {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .button-group .btn {
        min-width: 100px;
    }

    .card-title {
        font-size: 0.95rem;
    }

    .table {
        font-size: 0.75rem;
    }
}

/* ==================== 新手教學樣式 ==================== */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 3000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.tutorial-highlight {
    position: fixed;
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 3001;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--secondary);
}

.tutorial-card {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 3002;
    width: calc(100% - 40px);
    max-width: 400px;
    margin: 0 auto;
    transition: none;
}

@media (min-width: 768px) {
    .tutorial-card {
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 100%;
    }
}

.tutorial-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--primary);
    color: white;
    border-radius: 20px 20px 0 0;
}

.tutorial-card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tutorial-skip-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.3s;
}

.tutorial-skip-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.tutorial-card-body {
    padding: 20px;
    font-size: 1rem;
    line-height: 1.5;
    color: #333;
    min-height: 100px;
}

.tutorial-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-top: 1px solid #eee;
}

.tutorial-step-counter {
    color: var(--gray);
    font-size: 0.85rem;
}

.tutorial-card-footer .btn {
    width: auto;
    padding: 8px 20px;
    margin: 0;
    font-size: 0.9rem;
}

body.tutorial-active {
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    right: 0;
}

/* ==================== 日期編輯器 ==================== */
.dates-input-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.date-input-item {
    display: flex;
    flex-direction: column;
}

.date-input-item label {
    font-size: 0.7rem;
    margin-bottom: 4px;
    color: #6c757d;
}

.date-input-item input {
    padding: 6px;
    font-size: 0.8rem;
}

/* 統計卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 8px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-card .stat-icon {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.stat-card .stat-value {
    font-size: 1.3rem;
    font-weight: bold;
}

.stat-card .stat-label {
    font-size: 0.7rem;
    opacity: 0.9;
}

/* 趨勢圖 */
.trend-chart {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
}

.trend-bar {
    display: flex;
    align-items: center;
    margin: 8px 0;
    gap: 10px;
}

.trend-date {
    width: 45px;
    font-size: 0.7rem;
    color: var(--gray);
}

.trend-bar-track {
    flex: 1;
    height: 24px;
    background: #f0f0f0;
    border-radius: 12px;
    overflow: hidden;
}

.trend-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    border-radius: 12px;
    min-width: 4px;
}

.trend-amount {
    width: 60px;
    text-align: right;
    font-size: 0.75rem;
    font-weight: bold;
}

.trend-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.trend-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
}

.trend-legend span span {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* ==================== 柯南載入動畫 ==================== */
.loading-conan {
  text-align: center;
  padding: 40px 20px;
}

.loading-conan .conan-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  display: inline-block;
  animation: conanFloat 2s ease-in-out infinite;
}

.loading-conan .loading-text {
  margin-top: 16px;
  color: var(--gray);
  font-size: 0.95rem;
  animation: fadeInOut 1.5s ease-in-out infinite;
}

.loading-conan .loading-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.loading-conan .loading-dots span {
  width: 10px;
  height: 10px;
  background: var(--secondary);
  border-radius: 50%;
  animation: dotBounce 1.4s ease-in-out infinite;
}

.loading-conan .loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-conan .loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes conanFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes dotBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ==================== 星星評分 ==================== */
.star-rating {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.star-rating i {
  font-size: 1.8rem;
  color: #ddd;
  transition: color 0.15s ease, transform 0.15s ease;
}

.star-rating i.active {
  color: #f39c12;
}

.star-rating i:hover {
  transform: scale(1.1);
}

.star-rating i:active {
  transform: scale(0.95);
}

/* ==================== 載入終端機閃爍 ==================== */
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ==================== 工業級 Tabs 分頁籤 ==================== */

/* Tab 導航列容器 */
.tabs-nav {
    display: flex;
    background: #f8f9fa;
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 20px;
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* 隱藏 Firefox 捲軸 */
}

.tabs-nav::-webkit-scrollbar {
    display: none; /* 隱藏 Chrome/Safari 捲軸 */
}

/* Tab 按鈕 */
.tab-btn {
    flex: 1;
    min-width: 80px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

/* 滑鼠移入效果 */
.tab-btn:hover {
    color: var(--primary);
}

/* 選中狀態 (模擬滑動膠囊效果) */
.tab-btn.active {
    background: white;
    color: var(--secondary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    font-weight: 700;
}

/* Tab 內容容器 */
.tab-content {
    display: none;
    animation: tabFadeIn 0.3s ease;
}

/* 顯示中的 Tab 內容 */
.tab-content.active {
    display: block;
}

/* 切換時的淡入動畫 */
@keyframes tabFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 響應式調整 ==================== */
@media (max-width: 480px) {
    .tab-btn {
        font-size: 0.85rem;
        padding: 8px 10px;
        min-width: 70px;
    }
    
    .tabs-nav {
        padding: 3px;
        margin-bottom: 16px;
    }
}
