/* 心享系統 — 行動優先樣式 */
:root {
  --c-bg: #f3f4f6;
  --c-surface: #ffffff;
  --c-text: #111827;
  --c-text-muted: #6b7280;
  --c-primary: #1e3a5f;
  --c-primary-soft: #e7eef7;
  --c-accent: #b8854b;        /* 心享橘金 */
  --c-success: #15803d;
  --c-warning: #b45309;
  --c-danger: #b91c1c;
  --c-border: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.5;
}

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

/* ---------- Layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--c-primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.topbar h1 { font-size: 1rem; margin: 0; font-weight: 500; letter-spacing: 1px; }
.topbar .who { font-size: 0.85rem; opacity: 0.9; }
.topbar button.logout {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}
.topbar > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- 雲端同步指示器 ---------- */
.sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  padding: 4px 8px 4px 10px;
  border-radius: 16px;
  white-space: nowrap;
}
.sync-indicator .sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #94a3b8; /* 灰：未連線 */
  flex-shrink: 0;
}
.sync-indicator.ok .sync-dot {
  background: #22c55e; /* 綠 */
  box-shadow: 0 0 4px rgba(34,197,94,0.6);
}
.sync-indicator.error .sync-dot {
  background: #ef4444; /* 紅 */
  box-shadow: 0 0 4px rgba(239,68,68,0.6);
  animation: blink 1s ease-in-out infinite;
}
.sync-indicator.error { background: rgba(239,68,68,0.2); }
@keyframes blink { 50% { opacity: 0.4; } }

.sync-reload {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 2px;
}
.sync-reload:hover { background: rgba(255,255,255,0.3); }
.sync-reload:active { transform: rotate(180deg); transition: transform 0.3s; }

/* 手機窄螢幕：把「N 秒前同步」收起來，只留圓點 + 刷新 */
@media (max-width: 480px) {
  .sync-indicator .sync-text { display: none; }
  .sync-indicator { padding: 4px 6px; }
}

.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--c-border);
  overflow-x: auto;
  position: sticky;
  top: 48px;
  z-index: 99;
}
.tabs button {
  flex: 1;
  min-width: max-content;
  border: none;
  background: transparent;
  padding: 12px 12px;
  font-size: 0.92rem;
  color: var(--c-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button.active {
  color: var(--c-primary);
  font-weight: 600;
  border-bottom-color: var(--c-primary);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- Boss dashboard layout ---------- */
.boss-shell {
  min-height: 100vh;
  display: flex;
  background: var(--c-bg);
}
.boss-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 150;
  width: 220px;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
}
.sidebar-brand {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  font-weight: 700;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.sidebar-nav button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-left: 4px solid transparent;
  background: transparent;
  color: rgba(255,255,255,0.82);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 14px;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.sidebar-nav button:hover,
.sidebar-nav button.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.sidebar-nav button.active {
  border-left-color: #93c5fd;
  font-weight: 700;
}
.sidebar-nav button span {
  width: 20px;
  flex: 0 0 20px;
  text-align: center;
}
.sidebar-footer {
  margin: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(0,0,0,0.18);
  color: rgba(255,255,255,0.9);
  font-size: 0.78rem;
}
.sidebar-footer strong,
.sidebar-footer span {
  display: block;
}
.sidebar-footer span {
  margin-top: 2px;
  color: rgba(255,255,255,0.65);
  letter-spacing: 1px;
}
.boss-panel {
  flex: 1;
  min-width: 0;
  margin-left: 220px;
}
.boss-topbar {
  background: #fff;
  color: var(--c-text);
  border-bottom: 1px solid var(--c-border);
  box-shadow: none;
}
.boss-topbar h1 {
  color: var(--c-text-muted);
  font-size: 13px;
  letter-spacing: 0;
}
.boss-topbar .who {
  color: var(--c-text-muted);
  opacity: 1;
}
.boss-topbar button.logout {
  background: var(--c-primary);
  border-color: var(--c-primary);
}
.boss-topbar .sync-indicator {
  color: var(--c-text-muted);
  background: #f8fafc;
  border-color: var(--c-border);
}
.boss-topbar .sync-reload {
  color: var(--c-primary);
  background: var(--c-primary-soft);
}
.boss-main {
  max-width: none;
  margin: 0;
  padding: 16px;
}
.hamburger,
.icon-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}
.hamburger {
  display: none;
  color: var(--c-primary);
  font-size: 1.25rem;
  padding: 4px 8px;
}
.icon-btn {
  font-size: 1rem;
  padding: 4px;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}
.empty-card .empty {
  padding: 48px 16px;
}

@media (max-width: 767px) {
  .boss-sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .boss-sidebar.open {
    transform: translateX(0);
  }
  .boss-panel {
    margin-left: 0;
  }
  .boss-topbar {
    position: sticky;
    top: 0;
  }
  .hamburger {
    display: inline-flex;
  }
  .boss-topbar > div {
    gap: 6px;
  }
  .boss-topbar #who {
    display: none;
  }
}

/* ---------- Card ---------- */
.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--c-border);
}
.card h2 { font-size: 1.05rem; margin: 0 0 12px; color: var(--c-primary); }
.card h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--c-text-muted); }

/* ---------- Form ---------- */
label { display: block; font-size: 0.85rem; color: var(--c-text-muted); margin-bottom: 4px; margin-top: 12px; }
input, select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}
textarea { min-height: 64px; resize: vertical; }
input[type="file"] { padding: 8px; background: #f9fafb; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ---------- Button ---------- */
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border: 1px solid var(--c-primary);
  background: var(--c-primary);
  color: #fff;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}
button.btn:hover { opacity: 0.9; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }
button.btn.secondary { background: #fff; color: var(--c-primary); }
button.btn.danger { background: var(--c-danger); border-color: var(--c-danger); }
button.btn.success { background: var(--c-success); border-color: var(--c-success); }
button.btn.warning { background: var(--c-warning); border-color: var(--c-warning); }
button.btn.small { padding: 6px 10px; font-size: 0.85rem; }
button.btn.full { width: 100%; }

/* ---------- List items ---------- */
.list-item {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.list-item .info { flex: 1; }
.list-item .info .meta { font-size: 0.78rem; color: var(--c-text-muted); margin-top: 4px; }
.list-item .info .title { font-weight: 600; }
.list-item .amount { font-weight: 700; color: var(--c-primary); font-size: 1.1rem; white-space: nowrap; }

.thumb {
  width: 60px; height: 60px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--c-border);
  cursor: pointer;
}

/* ---------- Status badge ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge.pending  { background: #fef3c7; color: #92400e; }
.badge.approved { background: #d1fae5; color: #065f46; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.repaid   { background: #e5e7eb; color: #374151; }
.badge.draft    { background: #e5e7eb; color: #374151; }
.badge.published{ background: #dbeafe; color: #1e40af; }
.badge.billed { background: #dbeafe; color: #1e40af; }
.badge.received { background: #d1fae5; color: #065f46; }
.badge.overdue { background: #fee2e2; color: #991b1b; }
.badge.cancelled { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }

.dept-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.4;
  vertical-align: middle;
}
.dept-chip[data-dept="木作"] { background: #fef3c7; color: #92400e; }
.dept-chip[data-dept="清潔"] { background: #d1fae5; color: #065f46; }
.dept-chip[data-dept="拆除"] { background: #fee2e2; color: #991b1b; }
.dept-chip[data-dept="其他"] { background: #e5e7eb; color: #374151; }

/* ---------- Boss dashboard home ---------- */
.dashboard-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.dashboard-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--c-text);
}
.dashboard-subtitle,
.dashboard-period {
  color: var(--c-text-muted);
  font-size: 0.86rem;
}
.dashboard-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dashboard-toolbar-actions select,
.dash-side-card select {
  min-width: 140px;
  padding: 10px 12px;
}
.dashboard-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}
.dashboard-content,
.dashboard-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}
.dash-kpi-card,
.dash-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.dash-kpi-card {
  position: relative;
  overflow: hidden;
  padding: 16px;
  min-height: 150px;
}
.dash-kpi-top {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--c-text-muted);
  font-size: 0.84rem;
  font-weight: 700;
}
.dash-kpi-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e0f2fe;
  font-size: 1.25rem;
}
.dash-kpi-card strong {
  display: block;
  margin-top: 16px;
  font-size: clamp(1.3rem, 2vw, 1.8rem);
  color: var(--c-text);
  line-height: 1.2;
}
.dash-kpi-card p {
  margin: 8px 0 0;
  color: var(--c-text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
}
.dash-kpi-card > i {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 4px;
  border-radius: 999px 999px 0 0;
  background: #38bdf8;
}
.dash-kpi-card.green .dash-kpi-icon { background: #dcfce7; }
.dash-kpi-card.green > i { background: #22c55e; }
.dash-kpi-card.orange .dash-kpi-icon { background: #ffedd5; }
.dash-kpi-card.orange > i { background: #f97316; }
.dash-kpi-card.gray .dash-kpi-icon { background: #f3f4f6; }
.dash-kpi-card.gray > i { background: #9ca3af; }
.dash-kpi-card.red .dash-kpi-icon { background: #fee2e2; }
.dash-kpi-card.red > i { background: #ef4444; }
.dashboard-grid {
  display: grid;
  gap: 16px;
}
.dashboard-grid-mid {
  grid-template-columns: 1.1fr 0.9fr 0.9fr;
}
.dashboard-grid-bottom {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.dash-card {
  padding: 16px;
}
.dash-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.dash-card-head h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--c-text);
}
.dash-card-head a,
.dash-card-head span {
  color: var(--c-text-muted);
  font-size: 0.78rem;
  text-decoration: none;
}
.dash-card-head a:hover { color: var(--c-primary); }
.dash-placeholder-badge {
  display: inline-flex;
  padding: 5px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #6b7280;
  font-weight: 800;
  font-size: 0.82rem;
}
.dash-mock-chart,
.dash-revenue-chart {
  height: 180px;
  margin-top: 14px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: repeating-linear-gradient(to top, #f8fafc 0, #f8fafc 35px, #e5e7eb 36px);
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 18px;
}
.dash-mock-chart i {
  flex: 1;
  border-radius: 999px 999px 0 0;
  background: #d1d5db;
}
.dash-revenue-chart {
  align-items: stretch;
  gap: 10px;
}
.dash-revenue-month {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  text-align: center;
  color: var(--c-text-muted);
  font-size: 0.72rem;
}
.dash-revenue-bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
}
.dash-revenue-bars i {
  width: 12px;
  min-height: 4px;
  border-radius: 999px 999px 0 0;
}
.dash-revenue-bars .billed { background: #93c5fd; }
.dash-revenue-bars .received { background: #22c55e; }
.dash-donut-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 18px;
  align-items: center;
}
.dash-donut {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(
    #2563eb 0 var(--in-progress),
    #f59e0b var(--in-progress) calc(var(--in-progress) + var(--pending-billing)),
    #ef4444 calc(var(--in-progress) + var(--pending-billing)) calc(var(--in-progress) + var(--pending-billing) + var(--pending-received)),
    #22c55e calc(var(--in-progress) + var(--pending-billing) + var(--pending-received)) 360deg
  );
  display: grid;
  place-items: center;
}
.dash-donut > div {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}
.dash-donut strong {
  font-size: 1.05rem;
  color: var(--c-text);
}
.dash-donut span {
  color: var(--c-text-muted);
  font-size: 0.72rem;
}
.dash-legend,
.dash-cash-flow,
.dash-reminders,
.dash-todos {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dash-legend div,
.dash-cash-flow div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--c-text-muted);
  font-size: 0.88rem;
}
.dash-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.dash-legend span { margin-right: auto; }
.dash-legend .active,
.dash-legend .in-progress { background: #2563eb; }
.dash-legend .archived { background: #64748b; }
.dash-legend .pending-billing { background: #f59e0b; }
.dash-legend .pending-received { background: #ef4444; }
.dash-legend .completed { background: #22c55e; }
.dash-legend .empty { background: #e5e7eb; }
.dash-cash-flow strong { color: var(--c-text); }
.dash-cash-flow .total {
  border-top: 1px solid var(--c-border);
  padding-top: 12px;
  font-weight: 800;
}
.dash-cash-flow .muted,
.dash-reminders .muted {
  color: #9ca3af;
  font-weight: 700;
}
.dash-table-wrap {
  overflow-x: auto;
}
.dash-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 430px;
}
.dash-table th,
.dash-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--c-border);
  font-size: 0.86rem;
  vertical-align: middle;
}
.dash-table th {
  color: var(--c-text-muted);
  font-size: 0.76rem;
  font-weight: 800;
  background: #f8fafc;
}
.dash-table td strong {
  display: block;
  color: var(--c-text);
}
.dash-table td small {
  display: block;
  color: var(--c-text-muted);
  margin-top: 2px;
}
.dash-progress {
  height: 8px;
  width: 86px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.dash-progress span {
  display: block;
  height: 100%;
  background: #2563eb;
  border-radius: inherit;
}
.dash-empty-cell {
  text-align: center !important;
  color: var(--c-text-muted);
  padding: 28px 8px !important;
}
.dash-quick-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}
.dash-quick-actions button {
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: #fff;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.dash-quick-actions button:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.1);
  border-color: #bfdbfe;
}
.dash-quick-actions button.is-pressed,
.dash-quick-actions button:active {
  transform: translateY(0) scale(0.98);
}
.dash-quick-actions span { font-size: 1.35rem; }
.dash-quick-actions strong {
  color: var(--c-text);
  font-size: 0.9rem;
}
.dash-side-card {
  margin: 0;
}
.dash-side-card label {
  margin-top: 10px;
}
.dash-date-title {
  font-weight: 800;
  color: var(--c-text);
}
.dash-reminders div {
  color: var(--c-text);
  font-size: 0.88rem;
}
.dash-todos label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--c-text);
}
.dash-todos input {
  width: auto;
  margin: 0;
}
.dash-beta {
  background: #eef2ff;
  color: #3730a3 !important;
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 800;
}
.dash-ai-card p {
  color: var(--c-text-muted);
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 0 0 14px;
}

@media (max-width: 1279px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }
  .dashboard-side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dashboard-grid-mid,
  .dashboard-grid-bottom {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1023px) {
  .dashboard-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dashboard-grid-mid,
  .dashboard-grid-bottom,
  .dashboard-side {
    grid-template-columns: 1fr;
  }
  .dash-quick-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .dashboard-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .dashboard-toolbar-actions {
    justify-content: space-between;
  }
  .dashboard-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dash-kpi-card {
    min-height: 142px;
  }
  .dash-donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .dash-quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5485 100%);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-card .brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-card .brand h1 {
  font-size: 1.4rem;
  color: var(--c-primary);
  margin: 0;
  letter-spacing: 2px;
}
.login-card .brand p {
  font-size: 0.85rem;
  color: var(--c-text-muted);
  margin: 4px 0 0;
}
.login-card select, .login-card input { font-size: 1.1rem; padding: 14px; }
.pin-input {
  letter-spacing: 8px;
  text-align: center;
  font-size: 1.5rem !important;
  font-family: monospace;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(17,24,39,0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 0.9rem;
  z-index: 1000;
  transition: transform 0.25s;
  max-width: 90%;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-bg.show { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin: 0 0 16px; color: var(--c-primary); }

.photo-viewer img { max-width: 100%; max-height: 80vh; }

/* ---------- Payments ---------- */
.payments-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.payments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.payments-head h2 {
  margin: 0;
  color: var(--c-text);
}
.payments-head p {
  margin: 4px 0 0;
  color: var(--c-text-muted);
  font-size: 0.9rem;
}
.payments-head-actions,
.payments-filters,
.payment-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.payments-head-actions select {
  width: 150px;
}
.payments-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.payment-kpi {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.payment-kpi > span {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e0f2fe;
  flex: 0 0 auto;
}
.payment-kpi.green > span { background: #dcfce7; }
.payment-kpi.orange > span { background: #ffedd5; }
.payment-kpi.red > span { background: #fee2e2; }
.payment-kpi p {
  margin: 0;
  color: var(--c-text-muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.payment-kpi strong {
  display: block;
  margin-top: 8px;
  color: var(--c-text);
  font-size: 1.35rem;
}
.payment-kpi small {
  display: block;
  margin-top: 4px;
  color: var(--c-text-muted);
}
.payments-filters,
.payments-table-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.payments-filters select {
  max-width: 180px;
}
.payments-table-wrap {
  overflow-x: auto;
  padding: 0;
}
.payments-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
.payments-table th,
.payments-table td {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: middle;
  font-size: 0.88rem;
}
.payments-table th {
  color: var(--c-text-muted);
  background: #f9fafb;
  font-size: 0.78rem;
}
.payments-table td strong,
.payments-table td small {
  display: block;
}
.payments-table td small {
  margin-top: 3px;
  color: var(--c-text-muted);
}
.payments-table .badge.pending {
  background: #e5e7eb;
  color: #374151;
}
.payment-actions {
  flex-wrap: wrap;
}
.payment-modal-box {
  max-width: 620px;
}
.project-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}
.project-form-grid button {
  min-height: 46px;
}

@media (max-width: 1023px) {
  .payments-kpis,
  .project-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .payments-head,
  .payments-head-actions,
  .payments-filters {
    align-items: stretch;
    flex-direction: column;
  }
  .payments-head-actions select,
  .payments-filters select {
    width: 100%;
    max-width: none;
  }
  .payments-kpis,
  .project-form-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Misc ---------- */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--c-text-muted);
}
.muted { color: var(--c-text-muted); font-size: 0.85rem; }
.tip {
  background: var(--c-primary-soft);
  border-left: 3px solid var(--c-primary);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin: 12px 0;
}
hr.sep { border: none; border-top: 1px solid var(--c-border); margin: 16px 0; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.summary-grid .stat {
  background: var(--c-primary-soft);
  padding: 10px;
  border-radius: 8px;
  text-align: center;
}
.summary-grid .stat .v { font-size: 1.2rem; font-weight: 700; color: var(--c-primary); }
.summary-grid .stat .l { font-size: 0.75rem; color: var(--c-text-muted); }

.dept-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}
.dept-kpi-card {
  border: 1px solid var(--c-border);
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
}
.dept-kpi-card div {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.dept-kpi-card strong {
  display: block;
  font-size: 1.1rem;
  color: var(--c-primary);
}
.dept-kpi-card span {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--c-text-muted);
}
.dept-kpi-card[data-dept="木作"] { background: #fffbeb; border-color: #fde68a; }
.dept-kpi-card[data-dept="清潔"] { background: #ecfdf5; border-color: #a7f3d0; }
.dept-kpi-card[data-dept="拆除"] { background: #fef2f2; border-color: #fecaca; }
.dept-kpi-card[data-dept="其他"] { background: #f9fafb; border-color: #d1d5db; }

/* ---------- Payslip dashboard ---------- */
.payslip-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.payslip-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.payslip-head h2 {
  margin: 0;
  color: var(--c-primary);
  font-size: 1.35rem;
}
.payslip-head p {
  margin: 4px 0 0;
  color: var(--c-text-muted);
  font-size: 0.9rem;
}
.payslip-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.payslip-head-actions select { width: 150px; }
.ps-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.ps-kpi-card {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  gap: 12px;
  min-width: 0;
}
.ps-kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--c-primary-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ps-kpi-title {
  color: var(--c-text-muted);
  font-size: 0.82rem;
}
.ps-kpi-value {
  color: var(--c-text);
  font-size: 1.45rem;
  line-height: 1.25;
  font-weight: 800;
  margin-top: 4px;
  word-break: break-word;
}
.ps-kpi-sub {
  color: var(--c-text-muted);
  font-size: 0.78rem;
  margin-top: 6px;
}
.ps-kpi-sub.up { color: #15803d; }
.ps-kpi-sub.down { color: #b91c1c; }
.ps-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
}
.ps-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
.ps-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ps-card {
  margin-bottom: 0;
  padding: 18px;
}
.ps-card h3 {
  margin: 0;
  color: var(--c-primary);
  font-size: 1rem;
}
.ps-card-title,
.ps-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.ps-card-title a {
  color: var(--c-primary);
  font-size: 0.82rem;
  text-decoration: none;
  white-space: nowrap;
}
.ps-insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.ps-anomaly {
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  border-left: 4px solid;
}
.ps-anomaly strong,
.ps-anomaly span {
  display: block;
}
.ps-anomaly span {
  color: var(--c-text-muted);
  font-size: 0.82rem;
  margin-top: 4px;
}
.ps-anomaly p {
  margin: 8px 0 0;
  font-size: 0.85rem;
}
.ps-anomaly.danger {
  background: #fee2e2;
  border-left-color: #ef4444;
}
.ps-anomaly.warning {
  background: #fef3c7;
  border-left-color: #f59e0b;
}
.ps-flow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.ps-flow-step {
  color: var(--c-text-muted);
  text-align: center;
  font-size: 0.82rem;
}
.ps-flow-dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #d1d5db;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  margin-bottom: 8px;
}
.ps-flow-step.active .ps-flow-dot { background: #1e3a5f; }
.ps-flow-step.done .ps-flow-dot { background: #22c55e; }
.ps-flow-step.active,
.ps-flow-step.done {
  color: var(--c-text);
  font-weight: 700;
}
.ps-flow-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--c-text-muted);
  font-size: 0.85rem;
}
.ps-donut-wrap {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}
.ps-donut {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.ps-donut::after {
  content: "";
  position: absolute;
  inset: 19px;
  background: #fff;
  border-radius: 50%;
}
.ps-donut > div {
  position: relative;
  z-index: 1;
  text-align: center;
}
.ps-donut span {
  display: block;
  color: var(--c-text-muted);
  font-size: 0.75rem;
}
.ps-donut strong {
  display: block;
  color: var(--c-primary);
  font-size: 0.92rem;
}
.ps-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.ps-legend div {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 6px;
  align-items: center;
  font-size: 0.78rem;
}
.ps-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.ps-legend strong,
.ps-legend em {
  font-style: normal;
  color: var(--c-text-muted);
  white-space: nowrap;
}
.ps-subtabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ps-subtabs button {
  border: 1px solid var(--c-border);
  background: #fff;
  color: var(--c-text-muted);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
}
.ps-subtabs button.active {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 700;
}
.ps-table-tools {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 8px;
  margin-bottom: 12px;
}
.ps-table-tools input {
  padding: 9px 12px;
}
.ps-table-scroll {
  overflow-x: auto;
  border: 1px solid var(--c-border);
  border-radius: 8px;
}
.ps-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}
.ps-table th,
.ps-table td {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: middle;
  font-size: 0.88rem;
}
.ps-table th {
  background: #f9fafb;
  color: var(--c-text-muted);
  font-size: 0.76rem;
  font-weight: 700;
}
.ps-table tbody tr:hover {
  background: #f8fafc;
}
.ps-table tbody tr:last-child td {
  border-bottom: 0;
}
.ps-employee {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}
.ps-employee small {
  display: block;
  color: var(--c-text-muted);
  font-size: 0.74rem;
  margin-top: 2px;
}
.ps-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #1f2937;
  flex-shrink: 0;
}
.ps-avatar.c0 { background: #fde68a; }
.ps-avatar.c1 { background: #fca5a5; }
.ps-avatar.c2 { background: #a7f3d0; }
.ps-avatar.c3 { background: #bfdbfe; }
.ps-avatar.c4 { background: #ddd6fe; }
.ps-avatar.c5 { background: #fbcfe8; }
.ps-negative { color: #b91c1c; font-weight: 800; }
.badge.anomaly { background: #fee2e2; color: #991b1b; }
.badge.ready { background: #dbeafe; color: #1e40af; }
.ps-table .badge.published { background: #e5e7eb; color: #374151; }
.ps-row-actions {
  display: flex;
  gap: 6px;
}
.ps-row-actions button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
  background: #fff;
  cursor: pointer;
}
.ps-collapse {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--c-primary);
  padding: 12px 0 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
}
.ps-action-list,
.ps-link-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.ps-link-list button {
  border: 1px solid var(--c-border);
  background: #fff;
  border-radius: 8px;
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--c-text);
}
.ps-link-list button:hover {
  background: #f8fafc;
}
.ps-tipbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: #dbeafe;
  color: #1e3a5f;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.9rem;
}
.ps-tipbar[hidden] { display: none; }
.ps-tipbar button {
  border: 0;
  background: transparent;
  color: #1e3a5f;
  cursor: pointer;
  font-size: 1rem;
}

@media (max-width: 1023px) {
  .ps-layout {
    grid-template-columns: 1fr;
  }
  .ps-side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ps-insight-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  .dept-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .payslip-head {
    flex-direction: column;
  }
  .payslip-head-actions {
    width: 100%;
    justify-content: stretch;
  }
  .payslip-head-actions select,
  .payslip-head-actions button {
    flex: 1 1 140px;
  }
  .ps-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .ps-kpi-card {
    padding: 14px;
    flex-direction: column;
  }
  .ps-kpi-value {
    font-size: 1.15rem;
  }
  .ps-side {
    grid-template-columns: 1fr;
  }
  .ps-table-head,
  .ps-flow-foot {
    align-items: flex-start;
    flex-direction: column;
  }
  .ps-table-tools {
    grid-template-columns: 1fr;
  }
  .ps-donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .ps-legend {
    width: 100%;
  }
}
