:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3a4f;
  --text: #e8eef6;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

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

html, body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top right, rgba(59, 130, 246, 0.18), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(34, 197, 94, 0.1), transparent 45%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
}

.btn-primary.btn-inline {
  width: auto;
  min-width: 120px;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 0.9rem;
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.error-msg {
  display: none;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.9rem;
}

.error-msg.show {
  display: block;
}

.demo-note {
  margin-top: 24px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  font-size: 0.88rem;
  color: var(--muted);
}

.demo-note strong {
  color: var(--text);
}

.demo-note code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: #93c5fd;
  font-size: 0.85rem;
}

/* ---- Dashboard ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header .left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .user-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.page-title {
  margin-bottom: 6px;
  font-size: 1.6rem;
}

.page-desc {
  color: var(--muted);
  margin-bottom: 24px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 720px) {
  .cards {
    grid-template-columns: 1fr;
  }
  .app-header {
    padding: 14px 16px;
    flex-wrap: wrap;
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  min-height: 132px;
  height: 100%;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  margin-bottom: 10px;
  min-height: 2.7em; /* reserve 2 lines so values line up across cards */
  display: flex;
  align-items: flex-start;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  margin-top: 0;
}

.stat-card .delta {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.85rem;
  line-height: 1.3;
  min-height: 1.3em;
}

.stat-card .delta.up {
  color: var(--success);
}

.stat-card .delta.down {
  color: var(--danger);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 180px;
  padding-top: 8px;
}

.chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar .bar {
  width: 100%;
  max-width: 56px;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  min-height: 4px;
  transition: height 0.4s ease;
}

.chart-bar .bar-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.chart-bar .bar-value {
  font-size: 0.75rem;
  color: var(--text);
  font-weight: 600;
}

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ---- Real-data dashboard extras ---- */
.cards-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 960px) {
  .cards-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .cards-4 {
    grid-template-columns: 1fr;
  }
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin-bottom: 0;
}

.panel-note {
  color: var(--muted);
  font-size: 0.85rem;
}

.filter-label {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  align-self: center;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filter-input,
.filter-select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.filter-input {
  flex: 1;
  min-width: 180px;
}

.filter-select {
  min-width: 140px;
}

.filter-input:focus,
.filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable::after {
  content: " ↕";
  opacity: 0.35;
  font-size: 0.75em;
}

th.sortable.sort-asc::after {
  content: " ↑";
  opacity: 1;
  color: var(--primary);
}

th.sortable.sort-desc::after {
  content: " ↓";
  opacity: 1;
  color: var(--primary);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td .sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.chart-scroll {
  overflow-x: auto;
  min-height: 200px;
  padding-bottom: 4px;
}

.chart-scroll .chart-bar {
  min-width: 64px;
}

.stat-card .delta {
  color: var(--muted);
}


/* Team filter buttons */
.team-panel .panel-head { margin-bottom: 12px; }
.team-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.team-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.team-btn:hover {
  border-color: var(--primary);
  color: #fff;
}
.team-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.wide-table {
  table-layout: fixed;
  width: 100%;
  min-width: 920px;
}

.wide-table th,
.wide-table td {
  padding: 10px 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

/* Shop + 員工號碼：左對齊、固定寬 */
.wide-table th.col-shop,
.wide-table td.col-shop {
  width: 72px;
  text-align: left;
  white-space: nowrap;
}

.wide-table th.col-staff,
.wide-table td.col-staff {
  width: 108px;
  text-align: left;
  white-space: nowrap;
}

/* 數字欄：右對齊、等寬字、唔截斷數字 */
.wide-table th.num,
.wide-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 12px;
}
.filter-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  margin-right: 4px;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.check-inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar .filter-input {
  flex: 1;
  min-width: 180px;
}


/* ---- Scrollable multi-select team chips ---- */
.team-panel .team-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.team-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 140px;
  overflow-y: auto;
  padding: 4px 2px 8px;
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 12px;
  background: rgba(0,0,0,0.15);
}

.team-scroll .team-btn {
  flex: 0 0 auto;
}

.team-btn[aria-pressed="true"],
.team-btn.active {
  outline: 2px solid var(--accent, #f5c542);
}

/* Summary cards: horizontal scroll for many metrics */
.cards-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(168px, 1fr);
  grid-auto-rows: 1fr;
  align-items: stretch;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}

@media (min-width: 900px) {
  .cards-scroll {
    grid-auto-flow: dense;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    grid-auto-columns: unset;
    grid-auto-rows: 1fr;
    align-items: stretch;
    overflow-x: visible;
  }
}

.wide-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1.25;
  vertical-align: bottom;
  /* long labels wrap cleanly; cells stay single-line so columns line up */
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  max-width: none;
  word-break: break-word;
  hyphens: auto;
}

.wide-table th.sortable {
  white-space: normal;
}

.wide-table th.num.sortable {
  text-align: right;
}

.wide-table tbody td.num {
  font-size: 0.92rem;
  font-weight: 500;
}

.wide-table .badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Category chips + date filters ---- */
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.category-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.category-chip:hover {
  border-color: var(--primary);
  color: #fff;
}

.category-chip.active,
.category-chip[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.filter-panel {
  margin-bottom: 16px;
}

/* Side-by-side: 1. Category (left) + 2. Shop (right) */
.filter-row-panel {
  padding-bottom: 16px;
}

.filter-split {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 20px;
  align-items: start;
}

.filter-col {
  min-width: 0;
}

.filter-col-shop .panel-head {
  margin-bottom: 10px;
}

.filter-col-shop .team-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Shop chips: constrained height, scroll — do not expand all */
.shop-scroll,
.team-scroll.shop-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  max-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.shop-scroll::-webkit-scrollbar {
  width: 8px;
}

.shop-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

@media (max-width: 820px) {
  .filter-split {
    grid-template-columns: 1fr;
  }
}

.date-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.date-field input[type="date"] {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  min-width: 160px;
}

.date-field input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  cursor: pointer;
}

#shopPanel[hidden] {
  display: none !important;
}

/* When shop hidden, category column takes full width */
.filter-split:has(#shopPanel[hidden]) {
  grid-template-columns: 1fr;
}


/* Change-password modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 12, 24, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px 22px 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.success-msg {
  display: none;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
  font-size: 0.92rem;
}

.success-msg.show {
  display: block;
}

/* Mode segmented control (ACQ / ISSUE) next to date filters */
.mode-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: 4px;
}

.mode-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.mode-seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 72px;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
