:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --bg: #f9fafb;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    
    --badge-grey: #f3f4f6;
    --badge-grey-text: #374151;
    --badge-blue: #dbeafe;
    --badge-blue-text: #1e40af;
    --badge-green: #d1fae5;
    --badge-green-text: #065f46;
    --badge-orange: #fef3c7;
    --badge-orange-text: #92400e;
    --badge-red: #fee2e2;
    --badge-red-text: #991b1b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Auth */
.modal-content.login-modal-content { max-width: 400px; }
.login-modal-content .error { margin-top: 1rem; }
.error { color: #dc2626; margin-top: 1rem; font-size: 0.875rem; }

/* Layout */
#app-container { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 240px; background: var(--card-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1.5rem; flex-shrink: 0; }
.brand { font-size: 1.25rem; font-weight: bold; margin-bottom: 2rem; display: flex; align-items: center; gap: 0.5rem; }
.nav-links { list-style: none; flex-grow: 1; }
.nav-links li { margin-bottom: 0.5rem; }
.nav-links a { display: block; padding: 0.75rem 1rem; color: var(--text); text-decoration: none; border-radius: 6px; transition: all 0.2s; }
.nav-links a:hover { background: var(--bg); }
.nav-links a.active { background: #eff6ff; color: var(--primary); font-weight: 500; }
.btn-text { padding: 0.75rem 1rem; color: var(--text-muted); cursor: pointer; background: none; border: none; text-align: left; font-size: 1rem; transition: color 0.2s; }
.btn-text:hover { color: var(--text); }
#logout-btn { margin-top: auto; }
.content { flex-grow: 1; padding: 2rem; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

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

@media (max-width: 768px) {
    #app-container { flex-direction: column; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 1rem; flex-shrink: 0; }
    .brand { margin-bottom: 1rem; }
    .nav-links { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
    .content { padding: 1rem; }
}

/* UI Components */
.header-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }
h3 { font-size: 1.125rem; font-weight: 500; margin-bottom: 0.75rem; color: var(--text-muted); }

.card { background: var(--card-bg); padding: 1.5rem; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 1.5rem; border: 1px solid var(--border); overflow-x: auto; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); padding: 1.5rem; border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); text-align: center; border: 1px solid var(--border); }
.stat-card .value { font-size: 2rem; font-weight: bold; color: var(--primary); margin-bottom: 0.25rem; }
.stat-card .label { color: var(--text-muted); font-size: 0.875rem; }

.badge { display: inline-block; padding: 0.25rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge-未寄出 { background: var(--badge-grey); color: var(--badge-grey-text); }
.badge-已寄出 { background: var(--badge-blue); color: var(--badge-blue-text); }
.badge-已收回 { background: var(--badge-green); color: var(--badge-green-text); }
.badge-待再次投递 { background: var(--badge-orange); color: var(--badge-orange-text); }
.badge-alert { background: var(--badge-red); color: var(--badge-red-text); }

table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.875rem; }
th, td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f9fafb; font-weight: 500; color: var(--text-muted); }
tbody tr { transition: background 0.15s; }
tbody tr.clickable:hover { background: #f3f4f6; cursor: pointer; }

.list-group { display: flex; flex-direction: column; gap: 0.75rem; }
.list-item { background: var(--card-bg); padding: 1rem 1.25rem; border-radius: 8px; border: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; transition: all 0.2s; cursor: pointer; }
.list-item:hover { border-color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.list-item-content { flex-grow: 1; }
.list-item-title { font-weight: 500; margin-bottom: 0.25rem; font-size: 1rem; }
.list-item-meta { color: var(--text-muted); font-size: 0.875rem; display: flex; align-items: center; gap: 0.5rem; }

/* Timeline */
.timeline { position: relative; padding-left: 2rem; margin-top: 1.5rem; }
.timeline::before { content: ''; position: absolute; left: 0.5rem; top: 0; bottom: 0; width: 2px; background: #e5e7eb; }
.timeline-item { position: relative; margin-bottom: 1.5rem; }
.timeline-item::before { content: ''; position: absolute; left: -1.85rem; top: 0.25rem; width: 0.75rem; height: 0.75rem; border-radius: 50%; background: var(--primary); border: 2px solid white; box-shadow: 0 0 0 1px var(--border); }
.timeline-card { background: var(--card-bg); padding: 1.25rem; border-radius: 8px; border: 1px solid var(--border); }
.timeline-header { display: flex; justify-content: space-between; margin-bottom: 0.75rem; align-items: center; }
.timeline-images { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.timeline-images img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); transition: opacity 0.2s; }
.timeline-images img:hover { opacity: 0.8; }

/* Buttons & Forms */
.btn-primary { background: var(--primary); color: white; border: none; padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: background 0.2s; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-cancel { background: white; color: var(--text); border: 1px solid var(--border); padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: background 0.2s; }
.btn-cancel:hover { background: var(--bg); }
.btn-danger { background: white; color: #dc2626; border: 1px solid #fca5a5; padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: background 0.2s; }
.btn-danger:hover { background: #fef2f2; }
.btn-small { padding: 0.25rem 0.5rem; font-size: 0.75rem; margin-left: 0.5rem; }
.btn-block { width: 100%; }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 500; color: #374151; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.625rem; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 0.875rem; transition: border-color 0.2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
.search-input { padding: 0.625rem 1rem; border: 1px solid var(--border); border-radius: 6px; min-width: 250px; font-size: 0.875rem; }
.search-input:focus { outline: none; border-color: var(--primary); }

/* Modals */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
.modal.active { display: flex; animation: fadeInModal 0.2s ease; }
.modal-content { background: var(--card-bg); padding: 2rem; border-radius: 12px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); position: relative; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 2rem; }

@keyframes fadeInModal {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.image-modal-content { max-width: 90vw; max-height: 90vh; padding: 0; display: flex; align-items: center; justify-content: center; }
.image-modal-content img { max-width: 100%; max-height: 90vh; object-fit: contain; border-radius: 8px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); }

/* Upload Area */
.upload-area { border: 2px dashed var(--border); padding: 2rem; text-align: center; color: var(--text-muted); cursor: pointer; border-radius: 8px; margin-bottom: 0.75rem; font-size: 0.875rem; transition: all 0.2s; background: #fafafa; }
.upload-area:hover, .upload-area.dragover { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.image-preview-container { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.image-preview { position: relative; width: 80px; height: 80px; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.image-preview .remove-btn { position: absolute; top: -6px; right: -6px; background: #ef4444; color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.image-preview .remove-btn:hover { background: #dc2626; }

/* Utilities */
.text-danger { color: #dc2626; }
.font-bold { font-weight: bold; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-muted { color: var(--text-muted); }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1.5rem; }
.text-sm { font-size: 0.875rem; }

/* Postmark Grid */
.postmark-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.postmark-card { background: var(--card-bg); border-radius: 8px; border: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; }
.postmark-card img { width: 100%; height: 150px; object-fit: cover; cursor: pointer; transition: opacity 0.2s; }
.postmark-card img:hover { opacity: 0.9; }
.postmark-info { padding: 0.75rem; flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between; }
.postmark-name { font-weight: 500; font-size: 0.875rem; margin-bottom: 0.5rem; word-break: break-all; }
.postmark-actions { display: flex; gap: 0.25rem; margin-top: auto; }
.postmark-actions button { flex-grow: 1; margin: 0; padding: 0.25rem; }

/* Geocode search */
.geocode-results { margin-top: 0.5rem; max-height: 160px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); }
.geocode-item { padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.875rem; border-bottom: 1px solid var(--border); }
.geocode-item:last-child { border-bottom: none; }
.geocode-item:hover { background: rgba(128,128,128,0.1); }

/* Extracted inline styles and new components */
#image-file-input, #pm-image-file-input { display: none; }
.d-none { display: none; }
.flex-row { display: flex; gap: 1rem; align-items: center; }
.flex-1 { flex: 1; }
.ml-2 { margin-left: 10px; }
.modal-lg { max-width: 800px; }
.search-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.map-container { height: 400px; margin-top: 0.75rem; border-radius: 8px; border: 1px solid var(--border); }
.modal-close { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 0.25rem; transition: color 0.2s; }
.modal-close:hover { color: var(--text); }
