:root {
    /* Dark Theme (Default) */
    --bg-color: #0f172a;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --surface-color: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(255, 255, 255, 0.1);
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --accent-color: #8b5cf6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --danger: #ef4444;
    --success: #10b981;
    --input-bg: rgba(15, 23, 42, 0.6);
    --sidebar-bg: rgba(15, 23, 42, 0.4);
    --row-hover-bg: rgba(255, 255, 255, 0.05);
    --nav-hover-bg: rgba(255, 255, 255, 0.1);
}

:root[data-theme="light"] {
    --bg-color: #f1f5f9;
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --surface-color: rgba(255, 255, 255, 0.8);
    --surface-border: rgba(0, 0, 0, 0.1);
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --accent-color: #7c3aed;
    --text-main: #0f172a;
    --text-muted: #475569;
    --danger: #dc2626;
    --success: #059669;
    --input-bg: rgba(255, 255, 255, 0.9);
    --sidebar-bg: rgba(255, 255, 255, 0.5);
    --row-hover-bg: rgba(0, 0, 0, 0.05);
    --nav-hover-bg: rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
}

/* Auth Page */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    text-align: center;
}

.login-box h1 {
    font-size: 24px;
    margin-bottom: 8px;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box p {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 16px;
    transition: all 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(to right, var(--primary-color), var(--accent-color));
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

/* 次要按鈕 (取消、工具列開關)：原本寫死半透明白底 + 白字，淺色模式會看不見 */
.btn-ghost {
    background: var(--nav-hover-bg);
    color: var(--text-main);
    border: 1px solid var(--surface-border);
}

.btn-ghost:hover {
    background: var(--row-hover-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Dashboard */
.dashboard-layout {
    display: flex;
    flex: 1;
}

.sidebar {
    /* width: 250px; */
    padding: 24px;
    border-right: 1px solid var(--surface-border);
    background: var(--sidebar-bg);
}

.brand {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    margin-bottom: 4px;
}

.nav-links a {
    display: block;
    padding: 8px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.nav-links a:hover, .nav-links a.active {
    background: var(--nav-hover-bg);
    color: var(--text-main);
}

.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 16px;
}

.role-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.role-admin { background: rgba(139, 92, 246, 0.2); color: #c084fc; }
.role-staff { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }

.logout-btn {
    color: var(--danger);
    text-decoration: none;
    font-size: 14px;
}

/* Table Design */
.data-table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th, .data-table td {
    padding: 16px;
    border-bottom: 1px solid var(--surface-border);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
}

.data-table tbody tr {
    transition: background 0.2s ease;
}

.data-table tbody tr:hover {
    background: var(--row-hover-bg);
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: var(--nav-hover-bg);
    border-radius: 3px;
    margin-top: 4px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
}

/* 案件狀態標籤：深色主題用亮色字，淺色主題改用深色字避免與底色接近 */
.status-chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.status-chip.st-active   { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.status-chip.st-done     { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.status-chip.st-pause    { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.status-chip.st-stop     { background: rgba(239, 68, 68, 0.2);  color: #f87171; }
.status-chip.st-notstart { background: rgba(139, 92, 246, 0.2); color: #c084fc; }
.status-chip.st-other    { background: var(--nav-hover-bg);     color: var(--text-muted); }

:root[data-theme="light"] .status-chip.st-active   { background: rgba(37, 99, 235, 0.12);  color: #1d4ed8; }
:root[data-theme="light"] .status-chip.st-done     { background: rgba(5, 150, 105, 0.14);  color: #047857; }
:root[data-theme="light"] .status-chip.st-pause    { background: rgba(217, 119, 6, 0.14);  color: #b45309; }
:root[data-theme="light"] .status-chip.st-stop     { background: rgba(220, 38, 38, 0.12);  color: #b91c1c; }
:root[data-theme="light"] .status-chip.st-notstart { background: rgba(124, 58, 237, 0.12); color: #6d28d9; }

.action-btn {
    padding: 6px;
    white-space: nowrap;
    background: var(--row-hover-bg);
    color: var(--text-main);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-size: 12px;
    transition: background 0.2s;
}
.action-btn:hover {
    background: var(--surface-border);
}

/* Form Additions */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.styled-select {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 16px;
    font-family: inherit;
    appearance: none;
}
.styled-select option {
    background: var(--bg-color);
}

/* Layout classes to replace inline styles */
.admin-grid > * + * {
    margin-top: 24px;
}
.project-view-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
}

/* Responsive Design (RWD) */
@media (max-width: 1024px) {
    .dashboard-layout {
        flex-direction: column;
    }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--surface-border);
        padding: 16px;
        display: flex;
        flex-direction: column;
    }
    .brand { margin-bottom: 16px; }
    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .nav-links li {
        margin-bottom: 0;
    }
    .main-content {
        padding: 16px;
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .project-view-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .detail-grid {
        grid-template-columns: 1fr !important;
    }
    .detail-item[style*="grid-column"] {
        grid-column: 1 / -1 !important;
    }
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 12px !important;
    }
    .header-actions .btn {
        width: 100% !important;
        text-align: center;
    }
    
    /* 針對手機版最佳化：縮小卡片內距，爭取更多螢幕空間 */
    .glass-panel {
        padding: 16px !important;
    }
    
    /* 針對手機版最佳化：縮減表格留白以顯示更多資訊 */
    .data-table th, .data-table td {
        padding: 12px 8px;
        font-size: 13px;
    }
    
    /* 針對手機版最佳化：加大觸控區域大小 (符合 Apple 建議最低 44px 高度標準) */
    .input-group input, .styled-select {
        padding: 14px 16px;
        font-size: 16px; /* 防止 iOS 點擊輸入框時畫面強制放大 */
    }
    .btn {
        padding: 12px 16px;
    }
    .action-btn {
        /*padding: 10px 12px;*/
        display: inline-block;
        margin-bottom: 4px;
    }
    
    /* 讓首頁標題區塊 (包含新增案件、匯出按鈕) 在手機上垂直展開滿版 */
    .glass-panel > div[style*="justify-content: space-between"] {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 16px;
    }
    .glass-panel > div[style*="justify-content: space-between"] > div {
        width: 100%;
        flex-direction: column;
    }
    .glass-panel > div[style*="justify-content: space-between"] .btn {
        width: 100% !important;
        text-align: center;
        margin-bottom: 8px;
    }
}

@media print {
    .no-print {
        display: none !important;
    }
}

/* Highlight own projects */
.data-table tbody tr.own-project {
    background: rgba(59, 130, 246, 0.15); /* primary-color with opacity */
    border-left: 3px solid var(--primary-color);
}
.data-table tbody tr.own-project:hover {
    background: rgba(59, 130, 246, 0.25);
}

