/* ============================================
   冷氣維修系統 - 全域樣式
   ============================================ */

/* --- CSS 變數 --- */
:root {
    --primary: #3B82F6;
    --primary-50: #EFF6FF;
    --primary-100: #DBEAFE;
    --primary-500: #3B82F6;
    --primary-600: #2563EB;
    --primary-700: #1D4ED8;
    --primary-900: #1E3A5F;
    --secondary: #8B5CF6;
    --bg: #F9FAFB;
    --bg-white: #FFFFFF;
    --text: #111827;
    --text-secondary: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;
    --border-focus: #93C5FD;
    --success: #22C55E;
    --success-bg: #F0FDF4;
    --warning: #F59E0B;
    --warning-bg: #FFFBEB;
    --danger: #EF4444;
    --danger-bg: #FEF2F2;
    --info: #3B82F6;
    --info-bg: #EFF6FF;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* --- 佈局 --- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.page-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--primary-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: 1.25rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    transition: var(--transition);
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
    text-decoration: none;
}

.sidebar-nav a .icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
    border-radius: var(--radius);
    transition: var(--transition);
}

.sidebar-footer a:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
    text-decoration: none;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    min-height: 100vh;
    overflow-x: hidden;
    min-width: 0;
}

.topbar {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    overflow: hidden;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    min-width: 0;
}

.page-body {
    padding: 1.5rem;
}

/* --- 卡片 --- */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

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

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--info-bg); color: var(--primary); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* --- 按鈕 --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover { background: #16A34A; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #DC2626; }

.btn-warning {
    background: var(--warning);
    color: #fff;
}
.btn-warning:hover { background: #D97706; }

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* --- 表單 --- */
.form-group {
    margin-bottom: 1rem;
}

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

.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-white);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-control::placeholder {
    color: var(--text-light);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.form-error {
    font-size: 0.8rem;
    color: var(--danger);
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* --- 表格 --- */
.table-wrapper {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    white-space: nowrap;
}

.table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

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

/* --- 狀態標籤 --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-pending { background: var(--warning-bg); color: #92400E; }
.badge-confirmed { background: var(--info-bg); color: #1E40AF; }
.badge-dispatched { background: #F5F3FF; color: #5B21B6; }
.badge-in_progress, .badge-in_progress { background: var(--info-bg); color: #1E40AF; }
.badge-completed { background: var(--success-bg); color: #166534; }
.badge-cancelled { background: var(--danger-bg); color: #991B1B; }
.badge-assigned { background: #F5F3FF; color: #5B21B6; }
.badge-accepted { background: var(--info-bg); color: #1E40AF; }
.badge-en_route { background: var(--warning-bg); color: #92400E; }
.badge-on_site { background: var(--success-bg); color: #166534; }
.badge-in_repair { background: var(--info-bg); color: #1E40AF; }
.badge-rejected { background: var(--danger-bg); color: #991B1B; }
.badge-available { background: var(--success-bg); color: #166534; }
.badge-busy { background: var(--warning-bg); color: #92400E; }
.badge-off_duty { background: var(--bg); color: var(--text-secondary); }

/* --- 分頁 --- */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    justify-content: center;
    margin-top: 1rem;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text);
    background: var(--bg-white);
    transition: var(--transition);
}

.pagination a:hover {
    background: var(--bg);
    text-decoration: none;
}

.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* --- 空狀態 --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text);
}

/* --- 警告/提示 --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.alert-success { background: var(--success-bg); color: #166534; border: 1px solid #BBF7D0; }
.alert-warning { background: var(--warning-bg); color: #92400E; border: 1px solid #FDE68A; }
.alert-danger { background: var(--danger-bg); color: #991B1B; border: 1px solid #FECACA; }
.alert-info { background: var(--info-bg); color: #1E40AF; border: 1px solid #BFDBFE; }

/* --- 時間軸（預約進度用） --- */
.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: -2rem;
    top: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg-white);
}

.timeline-item.active .timeline-dot {
    background: var(--primary);
}

.timeline-item.done .timeline-dot {
    background: var(--success);
}

.timeline-item h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.timeline-item p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.modal-header .close-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* --- 手機側邊欄 Toggle --- */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* --- Grid Layouts --- */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.grid-3col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

/* --- 響應式 --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .sidebar-toggle {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .grid-2col {
        grid-template-columns: 1fr;
    }

    .grid-3col {
        grid-template-columns: 1fr;
    }

    .page-body {
        padding: 1rem;
    }

    .topbar {
        padding: 0.75rem 1rem;
    }

    .topbar-title {
        font-size: 1rem;
    }

    .topbar-user {
        font-size: 0.8rem;
    }

    .topbar-user i {
        display: none;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .table-wrapper {
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 1rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    .topbar {
        padding: 0.5rem 0.75rem;
    }

    .topbar-title {
        font-size: 0.9rem;
    }

    .topbar-user {
        font-size: 0.75rem;
        max-width: 35%;
    }

    .topbar-user i {
        display: none;
    }

    .topbar-user span {
        display: none;
    }

    .btn-sm {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* --- 載入中 --- */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* --- 工具類別 --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* --- Public Nav --- */
.public-nav {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.public-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.public-nav .logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.public-nav .logo img {
    height: 36px;
    width: auto;
    object-fit: contain;
}

.public-nav .logo:hover {
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-links a {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-radius: var(--radius);
    transition: var(--transition);
}

.nav-links a:hover {
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
}

.nav-links a.active {
    background: var(--primary-50);
    color: var(--primary-700);
    font-weight: 500;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text);
}

/* --- Public Footer --- */
.public-footer {
    background: var(--primary-900);
    color: rgba(255,255,255,0.7);
    padding: 3rem 1rem 0;
}

.public-footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
    padding-bottom: 2rem;
}

.footer-brand .footer-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 0.5rem;
}

.footer-brand p {
    font-size: 0.85rem;
    line-height: 1.6;
}

.footer-links h4 {
    color: #fff;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.footer-links a,
.footer-links p {
    display: block;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
    margin-bottom: 0.4rem;
}

.footer-links a:hover {
    color: #fff;
    text-decoration: none;
}

.footer-contact-icons {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.5rem;
}

.footer-contact-icons a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    font-size: 1.6rem;
    transition: var(--transition);
}

.footer-contact-icons a:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
    text-decoration: none;
}

.footer-bottom {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 1.25rem 0;
    text-align: center;
    font-size: 0.8rem;
    max-width: 1200px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .nav-links {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--bg-white);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 0.5rem;
        box-shadow: var(--shadow-md);
    }

    .nav-links.open {
        display: flex;
    }

    .mobile-menu-btn {
        display: block;
    }

    .public-footer-inner {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}
