/* ─── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Layout ──────────────────────────────────── */
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.container-wide { max-width: 1000px; margin: 0 auto; padding: 20px; }

/* ─── Header ──────────────────────────────────── */
.header {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    padding: 24px 20px;
    text-align: center;
}
.header h1 { font-size: 1.5rem; font-weight: 600; }
.header p { opacity: 0.9; font-size: 0.9rem; margin-top: 4px; }
.header-admin {
    background: linear-gradient(135deg, #1e293b, #334155);
}
.header-engineer {
    background: linear-gradient(135deg, #0f766e, #115e59);
}

/* ─── Nav ─────────────────────────────────────── */
.nav {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 20px;
    display: flex;
    gap: 0;
    align-items: center;
}
.nav a {
    display: inline-block;
    padding: 12px 16px;
    text-decoration: none;
    color: #64748b;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.nav a:hover, .nav a.active { color: #1d4ed8; border-bottom-color: #1d4ed8; }
.nav .spacer { flex: 1; }
.nav .logout { color: #dc2626; }

/* ─── Cards ───────────────────────────────────── */
.card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.card h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: #1e293b;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

/* ─── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: #475569;
}
.form-group .hint {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 4px;
}
input[type="text"],
input[type="tel"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: white;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea { resize: vertical; min-height: 100px; }

/* ─── Buttons ─────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
    background: white;
    color: #2563eb;
    border: 1px solid #2563eb;
}
.btn-outline:hover { background: #eff6ff; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-block { display: block; width: 100%; }

/* ─── Status Badges ───────────────────────────── */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}
.badge-new { background: #fef3c7; color: #92400e; }
.badge-assigned { background: #dbeafe; color: #1e40af; }
.badge-contacted { background: #e0e7ff; color: #3730a3; }
.badge-scheduled { background: #c7d2fe; color: #4338ca; }
.badge-on_site { background: #fce7f3; color: #9d174d; }
.badge-resolved { background: #d1fae5; color: #065f46; }
.badge-recommend_replace { background: #fed7aa; color: #9a3412; }
.badge-quoted { background: #e9d5ff; color: #6b21a8; }
.badge-sold { background: #bbf7d0; color: #166534; }
.badge-closed { background: #e2e8f0; color: #475569; }

/* Warranty badges */
.badge-warranty-active { background: #d1fae5; color: #065f46; }
.badge-warranty-expiring { background: #fef3c7; color: #92400e; }
.badge-warranty-expired { background: #e2e8f0; color: #475569; }
.badge-aging { background: #fee2e2; color: #991b1b; }

/* ─── Status Timeline ─────────────────────────── */
.timeline { list-style: none; position: relative; padding-left: 24px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: #e2e8f0;
}
.timeline li {
    position: relative;
    padding-bottom: 16px;
}
.timeline li::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2563eb;
    border: 2px solid white;
    box-shadow: 0 0 0 2px #2563eb;
}
.timeline .time { font-size: 0.8rem; color: #94a3b8; }
.timeline .event { font-size: 0.9rem; }
.timeline .note { font-size: 0.85rem; color: #64748b; margin-top: 2px; }

/* ─── Tables ──────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}
th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tr:hover { background: #f8fafc; }

/* ─── Stats Row ───────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: white;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .number {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
}
.stat-card .label {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 2px;
}

/* ─── Alert ───────────────────────────────────── */
.alert {
    padding: 16px 20px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}
.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}
.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* ─── Photo Grid ──────────────────────────────── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}
.photo-grid img {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}
.photo-grid img:hover { transform: scale(1.05); }

/* ─── Inline Form ─────────────────────────────── */
.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.inline-form select, .inline-form input {
    width: auto;
    flex: 1;
    min-width: 120px;
}

/* ─── Filter Bar ──────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.filter-bar a {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    text-decoration: none;
    color: #64748b;
    background: white;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}
.filter-bar a:hover { border-color: #2563eb; color: #2563eb; }
.filter-bar a.active { background: #2563eb; color: white; border-color: #2563eb; }

/* ─── Detail Grid ─────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    font-size: 0.95rem;
}
.detail-grid dt { color: #64748b; font-weight: 500; }
.detail-grid dd { color: #1e293b; }

/* ─── Tabs ────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.tab {
    flex: 1;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    color: #64748b;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}
.tab:hover { color: #1e293b; background: #f8fafc; }
.tab-active {
    color: #0f766e;
    border-bottom-color: #0f766e;
    background: #f0fdfa;
}

/* ─── Calendar ────────────────────────────────── */
.calendar-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.calendar-table th {
    padding: 10px 4px;
    text-align: center;
    font-size: 0.85rem;
    background: #f8fafc;
}
.cal-cell {
    vertical-align: top;
    padding: 6px;
    min-height: 90px;
    height: 100px;
    border: 1px solid #f1f5f9;
    position: relative;
}
.cal-empty { background: #fafafa; }
.cal-today {
    background: #eff6ff;
    border-color: #93c5fd;
}
.cal-day {
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
}
.cal-today .cal-day { color: #2563eb; }
.cal-event {
    display: block;
    padding: 3px 6px;
    margin-bottom: 3px;
    border-radius: 4px;
    background: #dbeafe;
    text-decoration: none;
    font-size: 0.75rem;
    line-height: 1.3;
    overflow: hidden;
    transition: background 0.2s;
}
.cal-event:hover { background: #bfdbfe; }
.cal-event-name {
    display: block;
    font-weight: 500;
    color: #1e40af;
}
.cal-event-addr {
    display: block;
    color: #64748b;
    font-size: 0.7rem;
}
.cal-event-eng {
    display: block;
    font-weight: 600;
    color: #0f766e;
    font-size: 0.7rem;
}

/* ─── Performance Table ───────────────────────── */
.perf-good { color: #16a34a; font-weight: 600; }
.perf-warn { color: #f59e0b; font-weight: 600; }
.perf-bad { color: #dc2626; font-weight: 600; }
.perf-bar {
    height: 8px;
    border-radius: 4px;
    background: #e2e8f0;
    overflow: hidden;
    margin-top: 4px;
}
.perf-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

/* ─── Mobile Responsive ───────────────────────── */
@media (max-width: 640px) {
    .container-wide { padding: 12px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .nav { overflow-x: auto; }
    .nav a { padding: 10px 12px; font-size: 0.8rem; white-space: nowrap; }
    .inline-form { flex-direction: column; }
    .inline-form select, .inline-form input { width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-grid dt { font-size: 0.85rem; }
}
