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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f7fa;
  color: #333;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  padding-bottom: 80px;
}

.hidden { display: none !important; }

/* Header */
.header {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.header p {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-top: 2px;
}

.btn-icon {
  background: rgba(255,255,255,0.2);
  border: none;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.2rem;
}

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

/* Toast */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #10b981;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  z-index: 200;
  animation: fadeIn 0.3s ease;
}

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

/* Main Content */
.main-content {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.tab-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Cards */
.card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.card-header {
  background: linear-gradient(to right, #eff6ff, white);
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #1f2937;
}

.card-body {
  padding: 16px;
}

/* Stats Card */
.stats-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stats-card.small {
  padding: 12px 16px;
}

.stats-label {
  font-size: 0.875rem;
  color: #6b7280;
}

.stats-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #2563eb;
}

.stats-value.green { color: #10b981; }

.stats-icon {
  font-size: 2rem;
  background: #eff6ff;
  padding: 12px;
  border-radius: 50%;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Form Styles */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  color: #6b7280;
  margin-bottom: 6px;
}

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

.form-section {
  background: #f9fafb;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.form-section label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.875rem;
  color: #6b7280;
}

.form-section input,
.form-section select {
  margin-bottom: 8px;
}

input, select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font-size: 1rem;
  background: white;
  transition: all 0.2s;
}

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: none;
  font-family: inherit;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
}

.input-with-btn button {
  padding: 12px 16px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-blue {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
}

.btn-green {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
}

.btn-outline {
  background: white;
  border: 1px solid #d1d5db;
  color: #4b5563;
}

.btn-outline:hover {
  background: #f9fafb;
}

.btn-danger {
  background: white;
  border: 1px solid #fecaca;
  color: #dc2626;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.875rem;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count {
  font-size: 0.875rem;
  color: #6b7280;
}

/* Report List */
.report-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.report-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.report-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  cursor: pointer;
}

.report-info {
  flex: 1;
}

.report-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.location {
  font-weight: 600;
  color: #1f2937;
}

.report-meta {
  display: flex;
  gap: 12px;
  font-size: 0.875rem;
  color: #6b7280;
}

.expand-icon {
  color: #9ca3af;
  font-size: 0.75rem;
}

.report-body {
  padding: 0 16px 16px;
  border-top: 1px solid #f3f4f6;
  padding-top: 12px;
}

.contact-info {
  font-size: 0.875rem;
  margin: 10px 0;
}

.progress-section {
  margin: 12px 0;
}

.progress-section .label {
  font-size: 0.875rem;
  color: #6b7280;
  margin-bottom: 4px;
}

.progress-section .content {
  font-size: 0.875rem;
  color: #1f2937;
  white-space: pre-wrap;
  line-height: 1.5;
}

.follow-up {
  background: #fef3c7;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #92400e;
  margin: 12px 0;
}

.report-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.report-actions .btn {
  flex: 1;
}

/* Tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: #f3f4f6;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  color: #4b5563;
}

.tag.blue {
  background: #dbeafe;
  color: #1d4ed8;
}

/* Stage Badges */
.stage-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.stage-1 { background: #f3f4f6; color: #4b5563; }
.stage-2 { background: #dbeafe; color: #1d4ed8; }
.stage-3 { background: #fef3c7; color: #92400e; }
.stage-4 { background: #fed7aa; color: #c2410c; }
.stage-5 { background: #d1fae5; color: #047857; }

/* Progress Bar */
.progress-bar-item {
  margin-bottom: 12px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  margin-bottom: 4px;
}

.progress-label span:first-child {
  color: #4b5563;
}

.progress-label span:last-child {
  font-weight: 600;
  color: #1f2937;
}

.progress-track {
  height: 8px;
  background: #f3f4f6;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.progress-fill.stage-1 { background: #9ca3af; }
.progress-fill.stage-2 { background: #3b82f6; }
.progress-fill.stage-3 { background: #f59e0b; }
.progress-fill.stage-4 { background: #f97316; }
.progress-fill.stage-5 { background: #10b981; }

/* List Item */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.list-item:last-child {
  border-bottom: none;
}

/* Empty State */
.empty-state {
  background: white;
  border-radius: 16px;
  padding: 48px 24px;
  text-align: center;
  color: #6b7280;
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.loading {
  text-align: center;
  padding: 40px;
  color: #6b7280;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-header button {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: #6b7280;
  padding: 4px;
}

.modal-body {
  padding: 20px;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-range input {
  flex: 1;
}

.date-range span {
  color: #6b7280;
}

.info-box {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.875rem;
  margin: 12px 0;
}

.info-box.blue {
  background: #dbeafe;
  color: #1d4ed8;
}

.info-box.gray {
  background: #f3f4f6;
  color: #4b5563;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.hint {
  text-align: center;
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 16px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e5e7eb;
  display: flex;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  z-index: 100;
}

.bottom-nav button {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: #9ca3af;
  transition: all 0.2s;
}

.bottom-nav button.active {
  color: #2563eb;
}

.nav-icon {
  font-size: 1.5rem;
}

.bottom-nav span:last-child {
  font-size: 0.75rem;
}

/* Responsive */
@media (max-width: 480px) {
  .header h1 {
    font-size: 1.1rem;
  }
  
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Admin */
.admin-add-form {
  background: #f0fdf4;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px dashed #86efac;
}

.admin-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
}

.admin-item:last-child {
  border-bottom: none;
}

.admin-item-info {
  flex: 1;
}

.admin-item-name {
  font-weight: 600;
  color: #1f2937;
}

.admin-item-meta {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 2px;
}

.admin-item-actions {
  display: flex;
  gap: 6px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
}

.btn-xs.red {
  color: #dc2626;
  border-color: #fecaca;
}

.btn-xs:hover {
  background: #f9fafb;
}

.admin-region-group {
  margin-top: 12px;
}

.admin-region-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #2563eb;
  background: #eff6ff;
  padding: 6px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.inactive {
  opacity: 0.5;
}

.inactive .admin-item-name {
  text-decoration: line-through;
}

/* ==================== Phase 3: 登入 / 帳號 ==================== */
.login-view {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
}
.login-logo { font-size: 2.6rem; }
.login-card h1 { font-size: 1.25rem; margin: 8px 0 2px; color: #1f2937; }
.login-sub { color: #6b7280; font-size: 0.9rem; margin-bottom: 20px; }
.login-card .form-group { text-align: left; margin-bottom: 14px; }
.login-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* Header 帳號區 */
.header-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: auto;
  padding: 6px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.user-chip .caret { font-size: 0.7rem; opacity: 0.8; }
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  z-index: 50;
  min-width: 140px;
}
.user-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: #fff;
  color: #1f2937;
  font-size: 0.9rem;
  cursor: pointer;
}
.user-menu button:hover { background: #f3f4f6; }

/* 唯讀「業務」欄 */
.readonly-field {
  background: #f3f4f6;
  color: #4b5563;
  cursor: not-allowed;
}

/* ==================== Phase 3: 責任區 ==================== */
.btn-ghost { background: transparent; color: #6b7280; border: 1px solid #e5e7eb; }
.btn-ghost:hover { background: #f9fafb; }

.units-bar {
  background: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.units-head { display: flex; justify-content: space-between; font-size: 0.85rem; color: #4b5563; margin-bottom: 8px; }

.reserve-form { margin-bottom: 12px; }

.territory-controls { margin-bottom: 12px; }
.territory-controls input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 0.95rem;
}
.show-ended {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.82rem; color: #6b7280; margin-top: 8px;
}

.res-group { margin-bottom: 16px; }
.res-group-head {
  font-size: 0.85rem; font-weight: 600; color: #2563eb;
  background: #eff6ff; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px;
}
.res-group-head .count { color: #6b7280; font-weight: 400; }

.res-card {
  background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.res-card.warn { border-left: 3px solid #f59e0b; }
.res-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.res-name { font-weight: 600; }
.res-meta { font-size: 0.82rem; color: #6b7280; margin-top: 4px; }
.res-note { font-size: 0.82rem; color: #4b5563; margin-top: 4px; }
.res-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.res-badge {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap;
}
.st-apply    { background: #fef3c7; color: #b45309; }
.st-hold     { background: #dcfce7; color: #15803d; }
.st-deal     { background: #dbeafe; color: #1d4ed8; }
.st-expired  { background: #fee2e2; color: #b91c1c; }
.st-released { background: #f3f4f6; color: #6b7280; }
.st-rejected { background: #f3f4f6; color: #9ca3af; }

.res-events { margin-top: 10px; border-top: 1px dashed #e5e7eb; padding-top: 8px; }
.res-event { font-size: 0.78rem; color: #4b5563; padding: 2px 0; }
.res-event .ev-time { color: #9ca3af; }

/* ==================== Phase 3: 公告 🔔 ==================== */
.bell-btn { position: relative; }
.bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px #2563eb;
}

.modal-tall { max-height: 85vh; display: flex; flex-direction: column; }
.modal-tall .modal-body { overflow-y: auto; }

.ann-compose {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  margin-top: 10px;
}

.ann-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }

.ann-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}
.ann-card.unread { border-left: 4px solid #2563eb; background: #f8fafc; }

.ann-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ann-title { font-weight: 600; color: #1f2937; font-size: 0.95rem; }
.ann-pin { font-size: 0.72rem; color: #b45309; }
.ann-badge {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap;
}
.an-normal    { background: #dbeafe; color: #1d4ed8; }
.an-territory { background: #dcfce7; color: #15803d; }
.an-remind    { background: #fef3c7; color: #b45309; }

.ann-body { margin-top: 6px; font-size: 0.85rem; color: #4b5563; white-space: pre-wrap; line-height: 1.5; }
.ann-foot {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #9ca3af;
}
