:root {
  color-scheme: light;
  font-size: 15px;
  --background: #f4f7fc;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --text: #0f172a;
  --text-muted: #5f6c7b;
  --primary: #3366ff;
  --accent: #8b5cf6;
  --border: rgba(15, 23, 42, 0.08);
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

/* HTML spec: elements with [hidden] must never be visible */
[hidden] {
  display: none !important;
}

/* Never override native appearance for radio/checkbox */
input[type="radio"],
input[type="checkbox"] {
  width: auto;
  height: auto;
  min-width: unset;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  margin: 0;
  accent-color: var(--primary);
  flex-shrink: 0;
}

span {
  font-size: 1rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.8rem;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", sans-serif;
  background: var(--background);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button.button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: 16px;
  padding: 0.9rem 1.2rem;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

button.button:hover,
.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(51, 102, 255, 0.18);
}

button.button.ghost,
.button.ghost {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
}

button.button.secondary,
.button.secondary {
  background: #f4f5f7;
  color: var(--text);
}

button.button.danger,
.button.danger {
  background: #ef4444;
  color: #ffffff;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5em 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-size: 1rem;
  font-weight: 700;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.font-zoom {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
}

.font-zoom button {
  width: 2.7rem;
  height: 2.7rem;
  padding: 0;
  border-radius: 14px;
  background: #f4f5f7;
  color: var(--text);
}

.font-zoom span {
  font-weight: 700;
  color: var(--text);
  min-width: 1.8rem;
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

.main-area {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  align-items: start;
  padding: 1rem;
}

.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 1.25rem;
  min-height: calc(100vh - 96px);
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li + li {
  margin-top: 0.35rem;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.82rem 0.95rem;
  border-radius: 16px;
  color: var(--text);
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.sidebar a:hover,
.sidebar a:focus-visible {
  background: rgba(51, 102, 255, 0.08);
  transform: translateX(2px);
}

.page-header {
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.5vw, 2.5rem);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 1rem;
  align-items: start;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 1rem;
  align-items: start;
}

.page-grid > *,
.form-grid > * {
  min-width: 0;
}

.card,
.form-card,
.full-card {
  width: 100%;
  min-width: 0;
}

.form-narrow {
  max-width: 600px;
  margin: 0 auto;
}

.main-area > * {
  min-width: 0;
}

.required {
  color: #ef4444;
}

.sidebar {
  transition:
    transform 0.25s ease,
    opacity 0.25s ease,
    visibility 0.25s ease;
  background: var(--surface);
  overflow-y: auto;
}

body.sidebar-collapsed .main-area {
  grid-template-columns: 1fr;
}

body.no-sidebar .main-area {
  grid-template-columns: 1fr;
  padding: 1rem;
}

body.sidebar-collapsed .sidebar {
  position: fixed;
  top: 76px;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  z-index: 20;
  transform: translateX(-100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  margin: 0;
  height: calc(100vh - 76px);
  box-shadow: 16px 0 40px rgba(15, 23, 42, 0.12);
}

body.sidebar-collapsed .sidebar-backdrop {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease;
  z-index: 15;
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.8rem;
  height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

@media (max-width: 1120px) {
  .main-area {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    z-index: 20;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    box-shadow: 16px 0 40px rgba(15, 23, 42, 0.12);
    margin: 0;
    height: calc(100vh - 72px);
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .page-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .data-table {
    min-width: 700px;
  }

  .data-table th,
  .data-table td {
    padding: 0.75rem 0.9rem;
  }
}

.project-card {
  background: #ffffff;
  border: 1px solid rgba(51, 102, 255, 0.14);
  border-radius: 22px;
  padding: 1.25rem 1.3rem;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.project-card .tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  background: rgba(51, 102, 255, 0.08);
  color: var(--primary);
  font-size: 1rem;
  font-weight: 700;
}

.card-value {
  margin-top: 1rem;
  font-size: 1rem;
  font-weight: 700;
}

.project-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.metric {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  font-size: 1rem;
  color: var(--text);
}

.card,
.full-card,
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2,
.form-card h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.page-content {
  width: 100%;
  min-width: 0;
}

.data-table-wrapper {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table thead {
  background: rgba(51, 102, 255, 0.08);
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 0.2rem;
}
.drag-handle:active {
  cursor: grabbing;
}
tr.is-dragging,
[data-sort-id].is-dragging {
  opacity: 0.4;
}

.data-table th,
.data-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  color: var(--text);
}

.data-table th {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-table th.is-sortable {
  position: relative;
  cursor: pointer;
  user-select: none;
  padding-right: 2.1rem;
}

.data-table th.is-sortable::after {
  content: "▲▼";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  letter-spacing: -0.12em;
  color: rgba(100, 116, 139, 0.72);
}

.data-table th.is-sort-asc,
.data-table th.is-sort-desc {
  color: #1d4ed8;
}

.data-table th.is-sort-asc::after,
.data-table th.is-sort-desc::after {
  color: #1d4ed8;
  letter-spacing: normal;
}

.data-table th.is-sort-asc::after {
  content: "▲";
}

.data-table th.is-sort-desc::after {
  content: "▼";
}

.data-table tbody tr {
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.data-table tbody tr:hover {
  background: rgba(51, 102, 255, 0.08);
  transform: translateX(2px);
}

.data-table td {
  font-size: 1rem;
  white-space: nowrap;
}

.data-table th,
.data-table td {
  vertical-align: top;
}

.table-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  float: right;
}

.no-data {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
  font-size: 1rem;
}

input:not([type="radio"]):not([type="checkbox"]),
select,
textarea {
  width: 100%;
  padding: 0.95rem 1rem;
  margin-bottom: 1rem;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: var(--surface-strong);
  color: var(--text);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

input:not([type="radio"]):not([type="checkbox"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(51, 102, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(51, 102, 255, 0.08);
}

textarea {
  min-height: 120px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.project-card {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid rgba(51, 102, 255, 0.1);
  border-radius: 24px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.96),
    rgba(248, 250, 252, 0.96)
  );
}

.project-card .tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: rgba(51, 102, 255, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 700;
}

.project-card h3 {
  margin: 0;
  font-size: 1.8rem;
}

.project-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.project-metrics .metric {
  padding: 0.95rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.04);
  color: var(--text);
}

.project-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (max-width: 1120px) {
  .main-area {
    grid-template-columns: 1fr;
  }

  .page-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .page-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar,
  .card,
  .form-card {
    border-radius: 20px;
  }
}

.alert.error {
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
}

@media (max-width: 900px) {
  .main-area {
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: 100%;
  }
}

/* Vivid workspace overrides */
:root {
  --background: #f3f8ff;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --text-muted: #55657b;
  --primary: #2563eb;
  --primary-2: #06b6d4;
  --accent: #ff5c7a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: rgba(148, 163, 184, 0.22);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.1);
}

body {
  font-family: "Noto Sans TC", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef5ff 0%, #f6fbff 35%, #f3f8ff 100%);
  color: var(--text);
}

body.drawer-open {
  overflow: hidden;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  background: linear-gradient(135deg, #08182f 0%, #123a7a 52%, #0b93b2 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 36px rgba(8, 24, 47, 0.2);
}

.topbar .button.ghost,
.topbar .sidebar-toggle,
.topbar .font-zoom button,
.topbar .icon-button {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.topbar-left,
.brand-wrap,
.brand-copy,
.user-chip {
  display: flex;
  align-items: center;
}

.topbar-left {
  gap: 1rem;
}

.brand-wrap {
  gap: 0.9rem;
}

.brand-mark {
  width: 2.7rem;
  height: 2.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.24),
    rgba(255, 255, 255, 0.1)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.brand-copy {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
}

.brand {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0;
}

.top-right {
  gap: 0.75rem;
}

.top-quick {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  box-shadow: 0 14px 24px rgba(37, 99, 235, 0.28);
}

.user-chip {
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar {
  display: flex;
  flex-direction: column;
  border: none;
  border-radius: 28px;
  padding: 0.9rem;
  background: linear-gradient(180deg, #071733 0%, #0d214a 100%);
  color: #dbeafe;
  box-shadow: 0 24px 50px rgba(8, 15, 33, 0.14);
}

.sidebar-top {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-title {
  display: grid;
  gap: 0.1rem;
}

.sidebar-kicker,
.drawer-kicker {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #93c5fd;
}

.sidebar-section-title {
  margin-bottom: 0.35rem;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(219, 234, 254, 0.7);
}

.sidebar-quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.sidebar-quick {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 0.8rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fbff;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-quick:hover,
.sidebar-quick:focus-visible,
.sidebar-quick.is-active {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.92),
    rgba(6, 182, 212, 0.92)
  );
  color: #ffffff;
}

.sidebar a {
  color: #dbeafe;
}

.sidebar a.is-active {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.18),
    rgba(255, 255, 255, 0.08)
  );
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.sidebar a:hover,
.sidebar a:focus-visible {
  background: rgba(255, 255, 255, 0.11);
  transform: translateX(4px);
}

.page-content {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

.page-header {
  margin-bottom: 0;
  padding: 0.1rem 0;
}

.page-header h1 {
  font-size: clamp(2rem, 2.4vw, 3rem);
}

.page-header p {
  margin: 0.45rem 0 0;
  max-width: 60ch;
  color: var(--text-muted);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.5rem;
}

.section-count {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 700;
}

.card,
.form-card,
.full-card {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 28px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
}

.card:hover,
.form-card:hover,
.full-card:hover {
  box-shadow: 0 30px 70px rgba(15, 23, 42, 0.11);
}

.button {
  border-radius: 16px;
}

.button.primary {
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22);
}

.button.secondary {
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.button.ghost {
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.button.danger {
  background: linear-gradient(135deg, #ef4444 0%, #ff7a59 100%);
  color: #ffffff;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.7rem;
  height: 2.7rem;
  padding: 0;
  border-radius: 14px;
}

.icon-button i {
  font-size: 1rem;
}

.data-table-wrapper {
  border-radius: 24px;
}

.data-table {
  min-width: 820px;
}

.data-table thead {
  background: linear-gradient(
    90deg,
    rgba(37, 99, 235, 0.09),
    rgba(6, 182, 212, 0.09)
  );
}

.data-table th {
  color: #334155;
  text-transform: none;
  letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.05);
}

.data-table td {
  vertical-align: middle;
}

/* 群組權限矩陣：功能名稱那欄靠右對齊（跟後面一整排 checkbox 更貼近，掃描起來比較
   順），瀏覽/新增/編輯/刪除/匯出Excel 每一欄（含標題）置中對齊。 */
.perm-matrix th,
.perm-matrix td {
  text-align: center;
}
.perm-matrix th:first-child,
.perm-matrix td:first-child {
  text-align: right;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
}

.status-pill.is-on {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.status-pill.is-off {
  background: rgba(148, 163, 184, 0.16);
  color: #475569;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.project-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.project-card {
  border: 1px solid rgba(37, 99, 235, 0.12);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.96),
    rgba(245, 250, 255, 0.94)
  );
}

.project-card .tag {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.12),
    rgba(6, 182, 212, 0.12)
  );
  color: #1d4ed8;
}

.project-meta {
  display: grid;
  gap: 0.35rem;
  color: var(--text);
}

.metric {
  background: linear-gradient(
    180deg,
    rgba(248, 251, 255, 0.96),
    rgba(241, 246, 255, 0.92)
  );
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 33, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 28;
}

.drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

body.drawer-open.drawer-preload .drawer-backdrop.is-open {
  opacity: 0;
  pointer-events: auto;
}

body.drawer-open.drawer-ready .drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

body.drawer-closing .drawer-backdrop.is-open {
  opacity: 0;
  pointer-events: none;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 92vw);
  height: 100vh;
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 30;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(244, 250, 255, 0.98)
  );
  border-left: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: -24px 0 50px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
}

body.drawer-open .drawer {
  transform: translateX(0);
}

body.drawer-open.drawer-preload .drawer {
  transform: translateX(100%);
}

body.drawer-open.drawer-ready .drawer {
  transform: translateX(0);
}

body.drawer-closing .drawer {
  transform: translateX(100%);
}

.drawer-header {
  padding: 1.25rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  align-items: flex-start;
  gap: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.drawer-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.drawer-body {
  padding: 1.25rem 1.4rem 1.5rem;
  overflow: auto;
}

body.drawer-closing .drawer,
body.drawer-closing .drawer-backdrop.is-open {
  pointer-events: none;
}

.drawer-form {
  display: grid;
  gap: 0;
}

.drawer-form label {
  font-weight: 700;
  color: #475569;
  font-size: 0.85rem;
  margin-bottom: 0.12rem;
}

.drawer-form input:not([type="checkbox"]):not([type="radio"]),
.drawer-form select,
.drawer-form textarea {
  background: #f8fbff;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 16px;
  padding: 0.58rem 0.9rem;
  margin-bottom: 0.3rem;
}

.drawer-form .autocomplete {
  margin-bottom: 0.3rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  cursor: pointer;
  font-weight: 600;
  color: #475569;
}
.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary, #3366ff);
}

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.font-zoom {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.2rem 0.35rem;
}

.font-zoom span {
  color: rgba(255, 255, 255, 0.88);
}

.font-zoom button {
  border: none;
}

/* Global year navigator in topbar */
.topbar-year-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.2rem 0.35rem;
}

.topbar-year-label {
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  min-width: 3rem;
  text-align: center;
  letter-spacing: 0.02em;
}

@media (max-width: 1120px) {
  .sidebar {
    top: 76px;
    width: min(340px, 88vw);
    height: calc(100vh - 76px);
  }

  .sidebar-quick-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0.9rem 1rem;
  }

  .brand-subtitle {
    display: none;
  }

  .top-quick span,
  .sidebar-quick span {
    display: none;
  }

  .page-header {
    gap: 0.75rem;
  }

  .drawer {
    width: 100vw;
  }

  .drawer-header,
  .drawer-body {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .data-table {
    min-width: 760px;
  }
}

.workspace-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  align-self: start;
  width: 100%;
}

.list-toolbar {
  display: grid;
  gap: 0.75rem;
}

.list-toolbar-top {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.list-search {
  display: flex;
  align-items: center;
  flex: 1 1 360px;
  min-width: 260px;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  border-radius: 0;
  position: relative;
}

.list-search i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 1;
}

.list-search input {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 1rem 0.65rem 2.4rem;
  border: 1.5px solid rgba(148, 163, 184, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: none;
  font-size: 0.9rem;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.list-search input:focus {
  outline: none;
  border-color: rgba(51, 102, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.08);
}

.list-search:focus-within {
  /* no outer glow needed — handled by input:focus */
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.72rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
}

.mode-pill:hover,
.mode-pill:focus-visible,
.mode-pill.is-active {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.filter-panels {
  display: grid;
  gap: 0.75rem;
}

.filter-panel {
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-panel.is-active {
  display: flex;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.62rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255, 255, 255, 0.84);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
}

.filter-chip small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  padding: 0.18rem 0.38rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 800;
}

.filter-chip:hover,
.filter-chip:focus-visible,
.filter-chip.is-active {
  transform: translateY(-1px);
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.12),
    rgba(6, 182, 212, 0.12)
  );
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.26);
}

.list-empty {
  padding: 0.95rem 1rem;
  border-radius: 18px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-weight: 700;
}

.status-lamp {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.75rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 999px;
  flex: 0 0 auto;
}

.status-lamp.is-on {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.status-lamp.is-on .status-dot {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}

.status-lamp.is-off {
  background: rgba(148, 163, 184, 0.16);
  color: #475569;
}

.status-lamp.is-off .status-dot {
  background: #94a3b8;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.18);
}

.status-lamp.is-partial {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

.status-lamp.is-partial .status-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
}

.status-lamp.is-cancel {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.status-lamp.is-cancel .status-dot {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.18);
}

/* Read-only field display */
.field-readonly {
  padding: 0.62rem 0.85rem;
  border-radius: 10px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1rem;
  font-family: "Noto Sans Mono TC", monospace;
  letter-spacing: 0.03em;
}

/* Invoice year navigator */
.invoice-year-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.invoice-year-label {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  min-width: 6rem;
  text-align: center;
}

/* Invoice filter chip rows (category + month) */
.invoice-filter-chips,
.invoice-month-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.25rem;
}

.invoice-filter-chips {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

/* ── Compact invoice table ── */
.invoice-table {
  width: 100%;
  min-width: 900px;
}

.invoice-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.invoice-table th,
.invoice-table td {
  padding: 0.38rem 0.55rem;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* Column widths (by data-col) */
.invoice-table [data-col="status"] {
  width: 44px;
}
.invoice-table [data-col="date"] {
  width: 54px;
}
.invoice-table [data-col="party"] {
  width: 90px;
}
.invoice-table [data-col="order-no"] {
  width: 170px;
}
.invoice-table [data-col="item"] {
  width: auto;
}
.invoice-table [data-col="qty"] {
  width: 72px;
  text-align: right;
}
.invoice-table [data-col="project"] {
  width: 88px;
}
.invoice-table [data-col="customer"] {
  width: 88px;
}
.invoice-table [data-col="unit-price"] {
  width: 72px;
  text-align: right;
}
.invoice-table [data-col="subtotal"] {
  width: 80px;
  text-align: right;
}
.invoice-table [data-col="note"] {
  width: 80px;
}
.invoice-table [data-col="actions"] {
  width: 10rem;
}

/* Item-name cell: inline — name + spec on one line */
.invoice-item-cell {
  white-space: normal !important;
  overflow: visible !important;
}
.item-spec {
  font-size: 1rem;
  color: var(--text-muted);
  margin-left: 0.35rem;
}

/* Qty cell – monospace, compact */
.invoice-qty-cell {
  font-family: ui-monospace, monospace;
  font-size: 1rem;
}

/* ── Inline cell editing ── */
.editable-cell {
  cursor: text;
  position: relative;
}
.editable-cell .editable-display {
  border-radius: 3px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: outline 0.1s;
}
.editable-cell:not(.is-editing):not(.is-saving):hover .editable-display {
  outline: 1.5px dashed var(--border);
}
.editable-display[contenteditable="true"] {
  outline: 1.5px dashed var(--border);
  cursor: text;
}
.editable-cell.is-editing {
}
/* Remove number spinner arrows from qty inputs */
.cell-input[type="number"] {
  -moz-appearance: textfield;
}
.cell-input[type="number"]::-webkit-inner-spin-button,
.cell-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.editable-cell.save-flash {
  background: color-mix(in srgb, #22c55e 18%, transparent);
  transition: background 0.6s;
}
.editable-cell.save-error {
  background: color-mix(in srgb, #ef4444 18%, transparent);
}
.editable-cell.is-saving {
  opacity: 0.55;
  pointer-events: none;
}

.cell-editor {
  display: flex;
  align-items: center;
  gap: 2px;
}
.cell-input {
  border: 1.5px dashed var(--border);
  border-radius: 3px;
  padding: 1px 3px;
  font-size: inherit;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  outline: none;
  box-shadow: none;
}
.cell-input:focus {
  border-color: var(--text-muted);
}
.cell-input-text {
  width: 14rem;
}
.cell-input-price {
  width: 6rem;
  text-align: right;
}
.cell-input-qty {
  width: 5rem;
  text-align: right;
}
.cell-input-case {
  width: 3.5rem;
  text-align: right;
}
.cell-input-unit {
  width: 3rem;
}
.cell-qty-sep {
  color: var(--text-muted);
  padding: 0 1px;
}

/* Note cell truncation */
.invoice-note-cell {
  color: var(--text-muted);
}

/* Smaller action buttons in invoice table */
.invoice-table .icon-button {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
}

/* Invoice flat table – month divider rows */
.invoice-month-divider td {
  padding: 0.9rem 1rem 0.5rem;
  background: var(--surface-strong);
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.invoice-month-body:first-of-type .invoice-month-divider td {
  border-top: none;
}

.invoice-month-divider .month-divider-label {
  margin-right: 0.75rem;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0;
}

/* 代付貨款 — drawer section */
.proxy-vendor-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(245, 158, 11, 0.06);
  border: 1.5px solid rgba(245, 158, 11, 0.2);
  border-radius: 8px;
  margin-top: 0.25rem;
}
.proxy-vendor-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
/* 代付貨款 — list row */
.proxy-deduction-row {
  background: rgba(245, 158, 11, 0.04);
}
.proxy-deduction-row td {
  opacity: 0.88;
}
.proxy-deduction-amount {
  color: #dc2626;
  font-weight: 600;
}
.proxy-deduction-badge {
  display: inline-block;
  font-size: 0.72rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  color: #92400e;
  white-space: nowrap;
  margin-left: 0.25rem;
}
.invoice-discount-icon {
  font-size: 0.82rem;
  margin-right: 0.3rem;
  cursor: default;
  vertical-align: middle;
}
.invoice-discount-icon.is-individual {
  color: #2563eb;
}
.invoice-discount-icon.is-batch {
  color: #d97706;
}

.month-divider-qty {
  margin-left: 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(100, 116, 139, 0.08);
  border: 1px solid rgba(100, 116, 139, 0.18);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}
.month-divider-subtotal {
  margin-left: 0.6rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(51, 102, 255, 0.07);
  border: 1px solid rgba(51, 102, 255, 0.15);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* Mono text for order numbers */
.mono-text {
  font-family: "Noto Sans Mono TC", ui-monospace, monospace;
  font-size: 1rem;
  color: var(--text-muted);
}

/* ── Column visibility toggle ── */
.col-hidden {
  display: none !important;
}

/* ── Invoice table: status cell – dot only, no pill ── */
.invoice-table .status-lamp {
  padding: 0.28rem;
  background: transparent;
  gap: 0;
  cursor: default;
}

/* ── Project customer name shown under project name in invoice row ── */
.project-customer-pill {
  display: block;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.1rem;
}

/* ── Order number tag (shown above item name in payable rows) ── */
.order-no-tag {
  display: inline-block;
  flex-shrink: 0;
  font-size: 1rem;
  font-weight: 700;
  font-family: "Noto Sans Mono TC", ui-monospace, monospace;
  padding: 0.1rem 0.52rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  background: rgba(100, 116, 139, 0.13);
  color: #475569;
}
.invoice-order-no-cell {
  white-space: nowrap;
}
.invoice-order-no-cell .order-no-cont {
  display: inline-block;
  width: 1rem;
  height: 1.1em;
  border-left: 2px solid rgba(100, 116, 139, 0.3);
  margin-left: 0.55rem;
  vertical-align: middle;
}
.order-no-context-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.5rem;
  background: rgba(51, 102, 255, 0.07);
  border: 1px solid rgba(51, 102, 255, 0.2);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--primary);
}

/* ── JS tooltip (floating, avoids table overflow clipping) ── */
.js-tooltip {
  position: fixed;
  z-index: 9999;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.88);
  color: #ffffff;
  border-radius: 7px;
  font-size: 1rem;
  font-weight: 500;
  white-space: pre-line;
  max-width: 240px;
  word-break: break-word;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
  line-height: 1.55;
}

.code-name-tooltip {
  border-bottom: 1px dotted var(--text-muted);
  cursor: help;
}

/* ── Entity info icon (next to vendor/customer names) ── */
.entity-info-btn {
  display: inline-flex;
  align-items: center;
  margin-left: 0.3rem;
  color: var(--text-muted, #94a3b8);
  cursor: default;
  opacity: 0.55;
  transition:
    opacity 0.15s,
    color 0.15s;
  vertical-align: middle;
}
.entity-info-btn:hover {
  opacity: 1;
  color: var(--primary, #3366ff);
}
.entity-info-btn .fa-circle-info {
  font-size: 0.85em;
}

.entity-info-btn.auto-pay-icon {
  color: #7c3aed;
  opacity: 0.85;
}
.entity-info-btn.auto-pay-icon:hover {
  opacity: 1;
  color: #7c3aed;
}
.entity-info-btn.auto-pay-icon .fa-credit-card {
  font-size: 0.85em;
}

/* ── 客戶/廠商欄位「顯示代碼或名稱」偏好（見 workspace_entity_identity() PHP 版／
   flipbook.js 的 appendEntityIdentity()）——兩個 span 都輸出，預設顯示代碼，切換到
   「顯示名稱」時由 .invoice-table-wrap／#flipbook-stage 上的 entity-display-name
   class 決定要換成顯示哪一個；旁邊的 icon 不受影響，滑入永遠是完整資訊。 ── */
.entity-fullname {
  display: none;
}
.entity-code {
  display: inline;
}
.invoice-table-wrap.entity-display-name .entity-code,
#flipbook-stage.entity-display-name .entity-code {
  display: none;
}
.invoice-table-wrap.entity-display-name .entity-fullname,
#flipbook-stage.entity-display-name .entity-fullname {
  display: inline;
}

/* ── Note cell in lists ── */
.note-cell {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted, #94a3b8);
  font-size: 0.9em;
}

/* ── Column picker panel (fixed popover) ── */
.col-picker-panel {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 14px;
  box-shadow:
    0 8px 32px rgba(15, 23, 42, 0.13),
    0 1px 0 rgba(255, 255, 255, 0.9) inset;
  padding: 0.35rem 0 0.4rem;
  width: 160px;
  max-height: 70vh;
  overflow-y: auto;
}

.col-picker-head {
  padding: 0.28rem 0.85rem 0.32rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.15rem;
}

.col-picker-body {
  display: block;
}

.col-picker-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.22rem 0.85rem;
  font-size: 0.87rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.col-picker-row:hover {
  background: var(--surface-strong);
}

.col-picker-divider {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0;
}

/* ── Sticky month badge (position: fixed, updated by JS) ── */
.sticky-month-badge {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.28rem 1.1rem;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
  pointer-events: none;
  white-space: nowrap;
}

.back-to-top-btn {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 20;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
  transition:
    background 0.15s ease,
    transform 0.15s ease;
}
.back-to-top-btn:hover {
  background: var(--accent);
  transform: translateY(-2px);
}

.count-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.78rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-weight: 800;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.count-link:hover,
.count-link:focus-visible {
  transform: translateY(-1px);
  background: rgba(37, 99, 235, 0.14);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.1);
}

.count-link .count-value {
  min-width: 1.5rem;
  text-align: center;
}

.project-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (min-width: 1121px) {
  body:not(.sidebar-collapsed) .sidebar {
    position: sticky;
    top: 5.25rem;
    align-self: start;
    max-height: calc(100dvh - 6.75rem);
    overflow-y: auto;
  }
}

.list-toolbar-top {
  justify-content: space-between;
  align-items: flex-start;
}

.list-toolbar-leading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 560px;
  min-width: 0;
  flex-wrap: wrap;
}

.list-select {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 1 220px;
  min-width: 180px;
  margin: 0;
  padding: 0.65rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.list-select i {
  color: #2563eb;
  font-size: 1rem;
}

.list-select select {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  width: 100%;
  min-width: 0;
}

.list-select select:focus {
  box-shadow: none;
}

.mode-switch {
  margin-left: auto;
}

.filter-chip small {
  min-width: 1.65rem;
  padding: 0.18rem 0.38rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 800;
}

.invoice-custom-field-group {
  display: grid;
  gap: 0.9rem;
  margin-top: 0.4rem;
  padding: 0.75rem;
  border-radius: 22px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: linear-gradient(
    180deg,
    rgba(245, 250, 255, 0.98),
    rgba(236, 246, 255, 0.94)
  );
}

.invoice-custom-field-group.is-empty .invoice-custom-field-grid {
  display: none;
}

.invoice-custom-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.custom-field {
  display: grid;
  gap: 0.35rem;
}

.custom-field-label {
  font-weight: 700;
  color: #475569;
}

/* ── Select / multiselect custom fields ── */
.custom-field-choice {
  display: grid;
  gap: 0.35rem;
}
.custom-field-radios,
.custom-field-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
}
.choice-opt {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-strong);
  transition:
    border-color 0.15s,
    background 0.15s;
}
.choice-opt:has(input:checked) {
  border-color: var(--primary);
  background: rgba(51, 102, 255, 0.07);
  color: var(--primary);
  font-weight: 600;
}
.choice-opt input {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}
.choice-opt-link {
  color: var(--primary);
  border-style: dashed;
  text-decoration: none;
}
.choice-opt-link:hover {
  background: rgba(51, 102, 255, 0.07);
  border-color: var(--primary);
}
.choice-opt-link i {
  font-size: 0.72em;
}

.project-metric-link {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: inherit;
}

.project-metric-link strong {
  font-size: 1rem;
}

.project-metric-meta {
  font-size: 1rem;
  color: var(--text-muted);
}

.project-reference {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.project-reference .ref-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.05);
  color: #334155;
  font-size: 1rem;
  font-weight: 700;
}

@media (max-width: 720px) {
  .list-toolbar-leading {
    width: 100%;
  }

  .list-select,
  .list-search {
    flex: 1 1 100%;
  }

  .invoice-custom-field-grid {
    grid-template-columns: 1fr;
  }
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 1121px) {
  body:not(.sidebar-collapsed) .sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
  }
}

.sidebar-bottom {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 0.45rem;
  padding-top: 0.8rem;
  padding-bottom: 0.15rem;
  background: linear-gradient(
    180deg,
    rgba(7, 23, 51, 0),
    rgba(7, 23, 51, 0.88) 18%,
    #071733 100%
  );
}

.sidebar-bottom-link.is-active {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.92),
    rgba(6, 182, 212, 0.92)
  );
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.22);
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.legend-pill strong {
  font-size: 1rem;
  font-weight: 800;
  color: #1d4ed8;
}

.legend-pill small {
  font-size: 1rem;
  color: var(--text-muted);
}

.schema-page,
.architecture-page {
  gap: 1.1rem;
}

.schema-link {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.92;
  filter: drop-shadow(0 4px 8px rgba(15, 23, 42, 0.08));
}

.schema-link.is-dashed {
  stroke-dasharray: 8 8;
}

.schema-link-label {
  font-size: 1rem;
  font-weight: 800;
  fill: #334155;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.schema-table-card {
  --tone-start: #3b82f6;
  --tone-end: #06b6d4;
  --tone-border: rgba(59, 130, 246, 0.24);
  position: absolute;
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border-radius: 24px;
  border: 1px solid var(--tone-border);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(248, 252, 255, 0.94)
  );
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
}

.schema-table-card.tone-amber {
  --tone-start: #f59e0b;
  --tone-end: #fbbf24;
  --tone-border: rgba(245, 158, 11, 0.24);
}

.schema-table-card.tone-pink {
  --tone-start: #ec4899;
  --tone-end: #f472b6;
  --tone-border: rgba(236, 72, 153, 0.24);
}

.schema-table-card.tone-gold {
  --tone-start: #d97706;
  --tone-end: #f59e0b;
  --tone-border: rgba(217, 119, 6, 0.24);
}

.schema-table-card.tone-blue {
  --tone-start: #3b82f6;
  --tone-end: #06b6d4;
  --tone-border: rgba(59, 130, 246, 0.24);
}

.schema-table-card.tone-violet {
  --tone-start: #8b5cf6;
  --tone-end: #c084fc;
  --tone-border: rgba(139, 92, 246, 0.24);
}

.schema-table-card.tone-cyan {
  --tone-start: #06b6d4;
  --tone-end: #22d3ee;
  --tone-border: rgba(6, 182, 212, 0.24);
}

.schema-table-card.tone-emerald {
  --tone-start: #10b981;
  --tone-end: #34d399;
  --tone-border: rgba(16, 185, 129, 0.24);
}

.schema-table-card.tone-slate {
  --tone-start: #64748b;
  --tone-end: #94a3b8;
  --tone-border: rgba(100, 116, 139, 0.22);
}

.schema-table-card.tone-indigo {
  --tone-start: #6366f1;
  --tone-end: #818cf8;
  --tone-border: rgba(99, 102, 241, 0.24);
}

.schema-table-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.8rem 0.9rem;
  border-radius: 18px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--tone-start), var(--tone-end));
}

.schema-table-head strong {
  font-size: 1rem;
  font-weight: 900;
}

.schema-table-head span {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.88);
  text-align: right;
}

.schema-table-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.schema-field-list {
  display: grid;
  gap: 0.4rem;
}

.schema-field {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.42rem 0.55rem;
  border: 0;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.03);
  color: #0f172a;
  text-align: left;
  cursor: help;
  overflow: visible;
}

.schema-field:hover,
.schema-field:focus-visible {
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
}

.schema-field-name {
  display: grid;
  gap: 0.05rem;
  font-size: 1rem;
  font-weight: 800;
}

.schema-field-name small {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.schema-field-type {
  font-size: 1rem;
  font-weight: 800;
  color: #2563eb;
}

.schema-tooltip {
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.55rem);
  z-index: 6;
  display: grid;
  gap: 0.25rem;
  min-width: 220px;
  max-width: 280px;
  padding: 0.8rem 0.85rem;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  box-shadow: 0 22px 40px rgba(15, 23, 42, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.schema-tooltip strong {
  font-size: 1rem;
  color: #93c5fd;
}

.schema-tooltip span {
  font-size: 1rem;
  line-height: 1.45;
  color: rgba(248, 250, 252, 0.92);
}

.schema-field:hover .schema-tooltip,
.schema-field:focus .schema-tooltip,
.schema-field:focus-visible .schema-tooltip,
.schema-field:active .schema-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.schema-docs {
  display: grid;
  gap: 0.9rem;
}

.schema-doc-card {
  padding: 0;
  overflow: hidden;
}

.schema-doc-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  cursor: pointer;
  list-style: none;
}

.schema-doc-card summary::-webkit-details-marker {
  display: none;
}

.schema-doc-title {
  display: grid;
  gap: 0.15rem;
}

.schema-doc-title strong {
  font-size: 1rem;
  font-weight: 900;
}

.schema-doc-title small {
  font-size: 1rem;
  color: var(--text-muted);
}

.schema-doc-body {
  padding: 0 1.15rem 1.15rem;
}

.schema-doc-note {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.schema-doc-table-wrap {
  overflow: auto;
}

.schema-doc-table th,
.schema-doc-table td {
  white-space: nowrap;
}

.architecture-principles-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.architecture-principle {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: 22px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(243, 249, 255, 0.94)
  );
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.architecture-principle-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 16px;
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.14),
    rgba(6, 182, 212, 0.14)
  );
  color: #1d4ed8;
  flex: 0 0 auto;
}

.architecture-principle-copy {
  display: grid;
  gap: 0.35rem;
}

.architecture-principle-copy h3 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 900;
}

.architecture-principle-copy p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.65;
}

.architecture-timeline {
  display: grid;
  gap: 0.9rem;
}

.architecture-entry {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  border-radius: 22px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(245, 250, 255, 0.94)
  );
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.architecture-entry-date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: fit-content;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 800;
}

.architecture-entry-body {
  display: grid;
  gap: 0.65rem;
}

.architecture-entry-head {
  display: grid;
  gap: 0.55rem;
}

.architecture-entry-head h3 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 900;
}

.architecture-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.architecture-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.05);
  color: #334155;
  font-size: 1rem;
  font-weight: 800;
}

.architecture-entry-summary {
  margin: 0;
  color: #334155;
  line-height: 1.7;
}

.architecture-entry-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.architecture-entry-list li + li {
  margin-top: 0.2rem;
}

@media (max-width: 1120px) {
  .architecture-principles-grid,
  .architecture-entry {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .schema-table-card {
    padding: 0.85rem;
  }
}

/* -------------------------------------------------------------------------- */
/* Workspace refresh: sidebar, invoices, projects, schema                     */
/* -------------------------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 96px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: calc(100vh - 112px);
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.sidebar-top {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-title {
  display: grid;
  gap: 0.1rem;
}

.sidebar-section-title {
  margin-bottom: 0.4rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(219, 234, 254, 0.65);
}

.sidebar-quick-grid,
.sidebar-quick {
  display: none !important;
}

.sidebar ul {
  display: grid;
  gap: 0.28rem;
}

.sidebar li + li {
  margin-top: 0;
}

.sidebar a {
  padding: 0.78rem 0.85rem;
  border-radius: 18px;
  font-size: 1rem;
}

.sidebar a i {
  font-size: 1.5rem;
}

.sidebar-bottom {
  margin-top: auto;
  position: static;
  background: transparent;
  padding-top: 0.6rem;
  padding-bottom: 0;
}

.sidebar-bottom-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

.sidebar-bottom-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 4.4rem;
  padding: 0.6rem 0.3rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fbff;
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
}

.sidebar-bottom-link span {
  font-weight: 700;
  font-size: 0.7rem;
  line-height: 1.15;
}

.sidebar-bottom-link i {
  font-size: 1.35rem;
  color: #dbeafe;
}

.workspace-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
  align-self: start;
  width: 100%;
}

.invoice-page .invoice-years {
  display: grid;
  gap: 1rem;
}

.invoice-year-group {
  display: grid;
  gap: 1rem;
}

.invoice-year-head,
.invoice-month-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.invoice-year-head h2,
.invoice-month-head h3 {
  margin: 0;
}

.invoice-year-head p {
  margin: 0.25rem 0 0;
}

.invoice-months {
  display: grid;
  gap: 0.9rem;
}

.invoice-month-group {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 20px;
  background: rgba(248, 252, 255, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.project-page .project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1rem;
}

.project-card {
  gap: 0.95rem;
}

.project-meta {
  display: grid;
  gap: 0.35rem;
  color: var(--text);
}

.project-meta strong {
  color: var(--text-muted);
}

.project-reference {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.ref-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  font-size: 1rem;
  font-weight: 800;
}

.project-actions {
  display: flex;
  gap: 0.55rem;
}

.project-metric-link {
  display: grid;
  gap: 0.35rem;
}

.project-metric-meta {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 700;
}

.schema-page,
.architecture-page {
  gap: 1rem;
}

.schema-jump-card,
.schema-diagram-card,
.schema-doc-card {
  display: grid;
  gap: 1rem;
}

.schema-jump-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.schema-jump-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 0.95rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  border: 1px solid rgba(37, 99, 235, 0.16);
  font-weight: 800;
}

.schema-jump-link:hover,
.schema-jump-link:focus-visible {
  background: rgba(37, 99, 235, 0.14);
}

.schema-diagram-stage {
  position: relative;
  overflow: visible;
  isolation: isolate;
}

.schema-links-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 30;
  color: rgba(71, 85, 105, 0.72);
}

.schema-diagram-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.schema-table-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border-radius: 22px;
  overflow: visible;
  scroll-margin-top: 120px;
  break-inside: avoid;
}

.schema-table-head {
  padding: 0.85rem 0.95rem;
}

.schema-field {
  z-index: 1;
}

.schema-field .schema-tooltip {
  z-index: 40;
}

.schema-docs {
  display: grid;
  gap: 0.9rem;
}

.schema-doc-card summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  padding: 0;
}

.schema-doc-card summary::-webkit-details-marker {
  display: none;
}

.schema-doc-card {
  scroll-margin-top: 120px;
}

.schema-doc-title {
  display: grid;
  gap: 0.15rem;
}

.schema-doc-body {
  display: grid;
  gap: 0.85rem;
  padding-top: 0.75rem;
}

.schema-doc-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.schema-doc-table {
  min-width: 920px;
}

@media (max-width: 1200px) {
  .schema-diagram-grid {
    grid-template-columns: 1fr;
  }
}

.schema-field:hover .schema-tooltip,
.schema-field:focus-visible .schema-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

.schema-tooltip {
  position: absolute;
  left: 50%;
  top: calc(100% + 0.6rem);
  transform: translate(-50%, 0.3rem);
  min-width: 230px;
  max-width: 320px;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  color: #ffffff;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: grid;
  gap: 0.25rem;
  transition:
    opacity 0.16s ease,
    transform 0.16s ease,
    visibility 0.16s ease;
}

.schema-tooltip strong {
  font-size: 1rem;
}

.schema-tooltip span {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.86);
  line-height: 1.4;
}

@media (max-width: 1120px) {
  .sidebar {
    position: fixed;
    top: 76px;
    left: 0;
    bottom: 0;
    width: min(340px, 88vw);
    height: calc(100vh - 76px);
    max-height: none;
    overflow-y: auto;
  }

  .sidebar-bottom-links {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .sidebar-bottom-links {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .invoice-table {
    min-width: 760px;
  }

  .schema-diagram-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Customer tabs ─────────────────────────────────────── */
.customer-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem 0 0.5rem;
}
.tab-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}
.tab-pill:hover {
  background: rgba(51, 102, 255, 0.07);
  border-color: rgba(51, 102, 255, 0.32);
  color: var(--primary);
}
.tab-pill.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ─── Project badges ─────────────────────────────────────── */
.project-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.project-badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ─── Image upload ─────────────────────────────────────── */
.image-upload-wrap {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.image-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: var(--surface-strong);
}
.image-upload-wrap input[type="file"] {
  margin-bottom: 0;
  padding: 0.6rem 1rem;
  border-radius: 16px;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: var(--surface-strong);
  cursor: pointer;
}

/* ─── Project settings section ─────────────────────────── */
.project-settings-section {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.settings-group {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 16px;
  background: rgba(51, 102, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.18);
}
.settings-group-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.03em;
}
.settings-row {
  display: grid;
  gap: 0.4rem;
}
.settings-row-key {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
}
.settings-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.settings-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: #fff;
  cursor: pointer;
  font-size: 1rem;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.settings-pill input[type="checkbox"],
.settings-pill input[type="radio"] {
  display: none;
  margin: 0;
  width: auto;
  padding: 0;
  border: none;
  background: none;
}
.settings-pill.is-checked {
  border-color: var(--primary);
  background: rgba(51, 102, 255, 0.07);
  color: var(--primary);
  font-weight: 700;
}
.settings-qty-input {
  width: 4rem;
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  text-align: center;
  margin: 0;
}
.settings-size-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  overflow-x: auto;
}
.settings-size-table th,
.settings-size-table td {
  padding: 0.3rem 0.4rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  text-align: center;
  white-space: nowrap;
}
.settings-size-table thead th {
  background: rgba(51, 102, 255, 0.06);
  font-weight: 800;
}
.settings-size-table .settings-qty-input {
  width: 3.5rem;
}

/* ─── Autocomplete ─────────────────────────────────────── */
.autocomplete {
  position: relative;
  margin-bottom: 1rem;
}
.autocomplete .autocomplete-input {
  margin-bottom: 0;
  padding-right: 2.4rem;
}
.autocomplete::after {
  content: "\f078";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 1rem;
  transition: transform 0.2s ease;
}
.autocomplete.is-open::after {
  transform: translateY(-50%) rotate(180deg);
}
.autocomplete.is-open .autocomplete-input {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-color: rgba(51, 102, 255, 0.8);
  border-bottom-color: transparent;
  box-shadow: 0 0 0 4px rgba(51, 102, 255, 0.08);
}
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: -2px;
  background: var(--surface);
  border: 1px solid rgba(51, 102, 255, 0.8);
  border-top: none;
  border-radius: 0 0 16px 16px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}
.autocomplete-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  transition: background 0.12s;
}
.autocomplete-option:hover,
.autocomplete-option.is-active {
  background: rgba(51, 102, 255, 0.07);
  color: var(--primary);
}
.autocomplete-option:last-child {
  border-radius: 0 0 14px 14px;
}
.autocomplete-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.autocomplete-option-cat {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0 0.3rem;
}
.vendor-cat-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -0.15rem;
  padding: 0 0.1rem;
}
.vendor-cat-hint[hidden] {
  display: none;
}
.autocomplete-option-edit {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  color: var(--text-muted);
  opacity: 0;
  transition:
    opacity 0.15s,
    background 0.15s;
  text-decoration: none;
}
.autocomplete-option:hover .autocomplete-option-edit {
  opacity: 1;
}
.autocomplete-option-edit:hover {
  background: rgba(51, 102, 255, 0.12);
  color: var(--primary);
}
.autocomplete-add-new {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-size: 1rem;
  color: #0369a1;
  border-top: 1px dashed rgba(3, 105, 161, 0.25);
  border-radius: 0 0 14px 14px;
  transition: background 0.12s;
}
.autocomplete-add-new::before {
  content: "+";
  font-weight: 700;
  font-size: 1.1rem;
}
.autocomplete-add-new:hover {
  background: rgba(3, 105, 161, 0.07);
}
.autocomplete-no-results {
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-size: 1rem;
}
.drawer-form .autocomplete .autocomplete-input {
  background: #f8fbff;
  border-color: rgba(148, 163, 184, 0.24);
}
.drawer-form .autocomplete.is-open .autocomplete-input {
  border-color: rgba(51, 102, 255, 0.8);
  border-bottom-color: transparent;
}

/* ── 預設製作規格 (spec_settings) ── */
.spec-settings-page {
}

/* Tab bar */
.spec-tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}
.spec-tab {
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition:
    color 0.15s,
    border-color 0.15s;
  cursor: pointer;
}
.spec-tab:hover {
  color: var(--primary);
}
.spec-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Garment type filter chips row */
.spec-type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

/* Spec item cards */
.spec-item-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.spec-item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.spec-item-card.is-inactive {
  opacity: 0.55;
}

.spec-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.spec-item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.spec-item-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

/* Badges */
.spec-type-tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  background: rgba(51, 102, 255, 0.1);
  color: var(--primary);
  font-weight: 500;
}
.spec-type-tag.is-universal {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-muted);
}
.spec-badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.spec-badge-2d {
  background: #fef3c7;
  color: #92400e;
}
.spec-badge-off {
  background: #fee2e2;
  color: #991b1b;
}
.spec-badge-single {
  background: #dbeafe;
  color: #1e40af;
}
.spec-badge-multi {
  background: #dcfce7;
  color: #166534;
}

/* Options row */
.spec-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.2rem;
}
.spec-option-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
}
.spec-option-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Drawer: radio group */
.radio-group {
  display: flex;
  gap: 1.2rem;
  margin-top: 0.1rem;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1rem;
  cursor: pointer;
}

/* Drawer: field hint text */
.field-hint {
  margin: 0.15rem 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f0f9ff 55%, #fdf4ff 100%);
  padding: 2rem 1rem;
  position: relative;
  overflow: hidden;
}

.login-bg-shape {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.login-bg-shape-1 {
  width: 520px;
  height: 520px;
  top: -160px;
  left: -160px;
  background: radial-gradient(
    circle,
    rgba(99, 102, 241, 0.12) 0%,
    transparent 70%
  );
}
.login-bg-shape-2 {
  width: 420px;
  height: 420px;
  bottom: -120px;
  right: -100px;
  background: radial-gradient(
    circle,
    rgba(6, 182, 212, 0.1) 0%,
    transparent 70%
  );
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 28px;
  box-shadow:
    0 24px 64px rgba(15, 23, 42, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
  border: 1px solid rgba(255, 255, 255, 0.7);
  padding: 2.5rem 2.25rem 2.25rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 2rem;
}
.login-brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3366ff 0%, #06b6d4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.3rem;
  flex-shrink: 0;
  box-shadow: 0 8px 20px rgba(51, 102, 255, 0.3);
}
.login-brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.login-brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.login-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}
.login-alert i {
  margin-top: 0.1rem;
  flex-shrink: 0;
}
.login-alert-error {
  background: rgba(239, 68, 68, 0.09);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.18);
}
.login-alert-success {
  background: rgba(16, 185, 129, 0.09);
  color: #065f46;
  border: 1px solid rgba(16, 185, 129, 0.18);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.login-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}
.login-input-wrap {
  position: relative;
}
.login-input-wrap input {
  width: 100%;
  padding: 0.7rem 1rem 0.7rem 2.6rem;
  border: 1.5px solid rgba(15, 23, 42, 0.12);
  border-radius: 12px;
  font-size: 0.95rem;
  background: rgba(248, 250, 252, 0.8);
  color: var(--text);
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background 0.15s;
  outline: none;
}
.login-input-wrap input:focus {
  border-color: #3366ff;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.1);
}
.login-input-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
  pointer-events: none;
}

.login-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  margin-top: 0.25rem;
  background: linear-gradient(135deg, #3366ff 0%, #06b6d4 100%);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(51, 102, 255, 0.28);
  transition:
    opacity 0.15s,
    box-shadow 0.15s,
    transform 0.12s;
}
.login-submit-btn:hover {
  opacity: 0.92;
  box-shadow: 0 12px 32px rgba(51, 102, 255, 0.32);
  transform: translateY(-1px);
}
.login-submit-btn:active {
  transform: translateY(0);
  box-shadow: 0 4px 16px rgba(51, 102, 255, 0.22);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: #94a3b8;
  font-size: 0.82rem;
}
.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(15, 23, 42, 0.09);
}

.google-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  background: #ffffff;
  color: #374151;
  border: 1.5px solid rgba(15, 23, 42, 0.12);
  border-radius: 14px;
  padding: 0.72rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background 0.15s,
    box-shadow 0.15s,
    border-color 0.15s,
    transform 0.12s;
}
.google-login-btn:hover {
  background: #f8faff;
  border-color: rgba(66, 133, 244, 0.35);
  box-shadow: 0 4px 16px rgba(66, 133, 244, 0.12);
  transform: translateY(-1px);
}
.google-login-btn:active {
  transform: translateY(0);
}

/* Detach order zone */
.detach-order-zone {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.detach-warning {
  font-size: 0.875rem;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin: 0 0 0.75rem;
  line-height: 1.5;
}
.detach-warning.detach-final {
  color: #991b1b;
  background: #fee2e2;
  border-color: #fca5a5;
}
.detach-step-actions {
  display: flex;
  gap: 0.5rem;
}

/* Merge orders panel */
.merge-panel-overlay[hidden] {
  display: none;
}
.merge-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.merge-panel {
  background: var(--surface, #fff);
  border-radius: 16px;
  padding: 1.5rem;
  width: min(480px, 95vw);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.merge-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 1.05rem;
}
.merge-panel-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 0.25rem;
}
.merge-panel-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}
.merge-label {
  font-size: 0.875rem;
  font-weight: 500;
  display: block;
  margin-bottom: 0.25rem;
}
.merge-panel-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.25rem;
}
.merge-error-msg {
  font-size: 0.875rem;
  color: #991b1b;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

/* Locked autocomplete (project-driven customer field) */
.autocomplete.is-locked .autocomplete-input {
  background: var(--surface-alt, #f4f5f7);
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}
.autocomplete.is-locked::after {
  content: "\f023";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Pricing base toggle (pbase) */
/* ── 單價 / 小計 mode toggle ── */
.price-mode-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.1rem;
}
.price-mode-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-right: 0.2rem;
}
.price-mode-btn {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface-strong);
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s;
  user-select: none;
}
.price-mode-btn:has(input:checked) {
  border-color: var(--primary);
  background: rgba(51, 102, 255, 0.08);
  color: var(--primary);
  font-weight: 700;
}
.price-mode-btn input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.pf-auto-row {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: var(--surface-strong);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.pf-auto-row strong {
  color: var(--text);
}

/* Payment status radio pills */
.ps-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.unit-price-avg-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 3px;
  vertical-align: middle;
  line-height: 1.5;
  letter-spacing: 0.02em;
}

.pbase-section {
  margin-top: 0.5rem;
}

/* 折扣計算輔助 */
.discount-calc-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.25rem;
}
.discount-calc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.discount-calc-toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
}
.discount-calc-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt, #f1f5f9);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
}
.discount-calc-inputs[hidden] {
  display: none;
}
.discount-calc-label {
  color: var(--text-muted);
  white-space: nowrap;
}
.discount-calc-inputs input[type="number"] {
  width: 88px;
  padding: 0.2rem 0.45rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  -moz-appearance: textfield;
}
.discount-calc-inputs input[type="number"]::-webkit-inner-spin-button,
.discount-calc-inputs input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.discount-calc-sym {
  color: var(--text-muted);
}
.discount-calc-eq {
  font-weight: 600;
  color: var(--primary, #2563eb);
  white-space: nowrap;
  margin-left: 0.2rem;
}
.pbase-section[hidden] {
  display: none;
}
.pbase-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary, #555);
  cursor: pointer;
  user-select: none;
}
.pbase-label input[type="checkbox"] {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}
.pbase-preview {
  margin-top: 0.35rem;
  padding: 0.3rem 0.6rem;
  background: var(--surface-alt, #f4f5f7);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary, #555);
}
.pbase-preview[hidden] {
  display: none;
}

/* ── Drawer field group (show/hide label+input pair together) ── */
.drawer-field-group {
  display: contents;
}
.drawer-field-group[hidden] {
  display: none;
}

/* ── Vendor category multi-select checkboxes ── */
.category-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  padding: 0.35rem 0 0.5rem;
}
.category-checkboxes .checkbox-label {
  padding: 0.15rem 0;
  font-weight: 500;
}

/* 翻頁帳本設定：主分類 → 次分類 階層式選單 */
.fb-cat-divider {
  flex: 0 0 auto;
  align-self: stretch;
  width: 1px;
  background: var(--border);
  margin: 0.2rem 0.4rem;
}
.fb-subcat-row {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}
.fb-main-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── 翻頁帳本設定：欄位挑選器 ── */
.fb-field-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding: 0.35rem 0 0.5rem;
}
.fb-field-option {
  position: relative;
  padding-right: 1.5rem;
}
.fb-field-order {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
  background: var(--primary, #3366ff);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.fb-field-order:empty {
  display: none;
}

.fb-selected-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0;
  margin: 0.5rem 0 0;
  list-style: none;
}
.fb-selected-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}
.fb-selected-item span {
  flex: 1;
  font-weight: 600;
}
.fb-selected-item .icon-button {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.4;
}
.badge-green {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}
.badge-yellow {
  background: rgba(234, 179, 8, 0.15);
  color: #92400e;
}
.badge-red {
  background: rgba(239, 68, 68, 0.14);
  color: #b91c1c;
}
.badge-blue {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

/* ── Small button ── */
.button.small {
  padding: 0.3rem 0.8rem;
  font-size: 0.82rem;
  border-radius: 10px;
  height: auto;
  min-height: unset;
}

/* ── Inline form / select (for table row actions) ── */
.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.inline-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  background: #fff;
  cursor: pointer;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ── Invoice cascade category selects ── */
.invoice-cat-cascade {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

/* ── Project date filter bar ── */
.project-date-filter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.2rem;
  padding: 0.15rem 0;
  margin-bottom: 0.25rem;
}
.date-filter-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.date-filter-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.date-filter-sep {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.date-filter-input {
  width: auto !important;
  min-width: 130px;
  padding: 0.32rem 0.6rem !important;
  border: 1.5px solid var(--border) !important;
  border-radius: 8px !important;
  font-size: 0.84rem;
  background: var(--surface-strong) !important;
  color: var(--text);
  margin-bottom: 0 !important;
}
.date-filter-input:focus {
  border-color: rgba(51, 102, 255, 0.6) !important;
  box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.08) !important;
}

/* Hide project cards filtered out by date range */
[data-list-item][data-date-hidden] {
  display: none !important;
}

/* Hide invoice rows filtered out by cascade category select */
[data-list-item][data-cat-hidden] {
  display: none !important;
}

/* ── Dashboard ──────────────────────────────────────────────── */
.dash-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.dash-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.dash-kpi-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.25rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-top: 3px solid var(--kpi-color, var(--primary));
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.dash-kpi-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dash-kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.dash-kpi-value.is-positive {
  color: #16a34a;
}
.dash-kpi-value.is-negative {
  color: #dc2626;
}

.dash-kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.dash-chart-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.dash-chart-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.25rem 1.4rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.dash-chart-card.is-full {
  grid-column: 1 / -1;
}

.dash-chart-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.dash-chart-title-icon {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.dash-chart-wrap {
  position: relative;
  height: 256px;
}

.dash-chart-wrap.is-donut {
  height: 210px;
}

.dash-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Donut legend */
.dash-legend-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dash-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.83rem;
}

.dash-legend-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.dash-legend-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.dash-legend-pct {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Outstanding tables */
.dash-outstanding-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.dash-outstanding-table th {
  text-align: left;
  padding: 0.35rem 0.6rem;
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}

.dash-outstanding-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  vertical-align: middle;
}

.dash-outstanding-table tr:last-child td {
  border-bottom: none;
}

.dash-outstanding-table .td-name {
  font-weight: 600;
}

.dash-outstanding-table .td-amount {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dash-outstanding-table .td-cnt {
  text-align: right;
  color: var(--text-muted);
  font-size: 0.82rem;
}

@media (max-width: 1100px) {
  .dash-kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .dash-kpi-row {
    grid-template-columns: 1fr;
  }
  .dash-chart-row {
    grid-template-columns: 1fr;
  }
  .dash-kpi-value {
    font-size: 1.4rem;
  }
}

/* ════════════════════════════════════════════════════════════════
   PAYMENT UI
   ════════════════════════════════════════════════════════════════ */

.drawer-locked-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.06);
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: not-allowed;
}
.drawer-locked-field i {
  color: var(--border);
}

.payment-batch-notice {
  margin-top: 0.6rem;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.07);
  border: 1.5px solid rgba(59, 130, 246, 0.22);
  font-size: 0.84rem;
  color: var(--text);
  overflow: hidden;
}
.pbn-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.9rem;
  gap: 0.5rem;
}
.pbn-header span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.payment-batch-notice strong {
  color: var(--primary);
}

.pbn-body {
  border-top: 1px solid rgba(59, 130, 246, 0.18);
  padding: 0.4rem 0.9rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.pbn-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.82rem;
}
.pbn-label {
  min-width: 6rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}
.pbn-row-total .pbn-label,
.pbn-row-total .pbn-value {
  font-weight: 700;
  color: var(--text);
}
.pbn-row-discount {
  color: #16a34a;
}
.pbn-row-discount .pbn-label {
  color: #16a34a;
}
.pbn-row-overpay {
  color: var(--danger);
}
.pbn-row-overpay .pbn-label {
  color: var(--danger);
}
.pbn-row-note .pbn-value {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── Payment batch: invoice breakdown (沖銷明細) ── */
.pbn-invoices {
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.75rem 0.6rem;
}
.pbn-invoices-edit {
  margin: 0 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem 0.6rem;
  background: var(--surface-strong);
}
.pbn-invoices-head {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}
.pbn-invoice-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 2fr) auto;
  gap: 0.4rem;
  align-items: baseline;
  font-size: 0.8rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border);
}
.pbn-invoice-row:last-child {
  border-bottom: none;
}
.pbn-invoice-row.is-current {
  background: rgba(51, 102, 255, 0.06);
  border-radius: 4px;
  padding: 0.2rem 0.3rem;
  margin: 0 -0.3rem;
  font-weight: 600;
}
.pbn-inv-order {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: monospace;
}
.pbn-inv-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pbn-inv-amount {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}

.payment-batch-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--danger);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 0.15rem 0.4rem;
  transition: background 0.15s;
  flex-shrink: 0;
}
.payment-batch-delete:hover {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.2);
}

/* ── Payment info sub-row in invoice list ─────────────────── */
tr.payment-info-row td {
  padding: 0.25rem 1rem 0.55rem;
  border-top: none !important;
  border-bottom: 2px solid rgba(22, 163, 74, 0.28) !important;
}
tr.payment-info-row + tr[data-list-item]:not(.payment-info-row) td {
  border-top: 2px solid rgba(22, 163, 74, 0.28) !important;
}
.pi-outer {
  display: flex;
  justify-content: flex-start;
}
.pi-card {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(22, 163, 74, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.28);
  border-radius: 6px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  color: var(--text);
  max-width: 100%;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.pi-card:hover {
  background: rgba(22, 163, 74, 0.18);
  border-color: rgba(22, 163, 74, 0.45);
}
.pi-check-icon {
  color: #16a34a;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.pi-chip {
  background: rgba(22, 163, 74, 0.18);
  color: #166534;
  border-radius: 4px;
  padding: 0.08rem 0.42rem;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}
.pi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.pi-tax-info {
  color: var(--text-muted);
  font-size: 0.74rem;
  white-space: nowrap;
}
.pi-sep {
  color: var(--border);
  font-size: 0.85rem;
  padding: 0 0.1rem;
  flex-shrink: 0;
}
.pi-amount {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}
.pi-diff {
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0.08rem 0.42rem;
  white-space: nowrap;
}
.pi-diff.is-discount {
  background: rgba(22, 163, 74, 0.15);
  color: #16a34a;
}
.pi-diff.is-overpay {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
}
.pi-note-icon {
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: help;
  flex-shrink: 0;
  transition: color 0.15s;
}
.pi-note-icon:hover {
  color: var(--primary);
}
.pi-edit-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  opacity: 0.5;
  margin-left: 0.1rem;
}
.pi-card:hover .pi-edit-hint {
  opacity: 1;
  color: var(--primary);
}

.payment-party-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 99px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.payment-invoices-section {
  margin-top: 0.75rem;
}
.payment-invoices-section > label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.payment-invoice-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-height: 280px;
  overflow-y: auto;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
}

.payment-invoices-cc-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: #b45309;
  background: rgba(180, 83, 9, 0.06);
  border: 1px solid rgba(180, 83, 9, 0.2);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
}

.payment-invoice-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.12s;
}
.payment-invoice-row:hover {
  background: rgba(148, 163, 184, 0.08);
}
.payment-invoice-row input[type="checkbox"] {
  flex-shrink: 0;
}
.payment-invoice-row-id {
  font-weight: 600;
  color: var(--text);
}
.payment-invoice-row-amt {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.payment-invoice-row-note {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* 訂單群組行 */
.payment-invoice-group {
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 2px;
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}
.payment-group-head-row {
  background: color-mix(in srgb, var(--primary) 6%, transparent);
  border-left: 3px solid var(--primary);
}
.payment-group-head-row:hover {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.payment-group-orderno {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.01em;
}
.payment-group-count {
  font-size: 0.72rem;
  background: var(--bg-alt, rgba(148, 163, 184, 0.15));
  color: var(--text-muted);
  border-radius: 10px;
  padding: 0.05rem 0.45rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* 群組內逐筆明細 */
.payment-group-sub-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0.5rem 0.2rem 1.8rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}
.payment-group-sub-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.5;
}
.payment-group-sub-date {
  flex-shrink: 0;
}
.payment-group-sub-row .payment-invoice-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.payment-group-sub-row .payment-invoice-amount {
  margin-left: auto;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.payment-invoices-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.6rem 0.1rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}
.payment-invoices-total strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.payment-invoices-empty {
  padding: 1.2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.payment-drawer-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.payment-records-card {
  margin-bottom: 1rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  overflow: hidden;
  grid-column: 2;
}
.payment-records-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: rgba(148, 163, 184, 0.07);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.payment-record-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.payment-record-row:hover {
  background: rgba(148, 163, 184, 0.05);
}
.payment-record-date {
  color: var(--text);
  font-weight: 600;
  flex-shrink: 0;
}
.payment-record-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  flex-shrink: 0;
}
.payment-record-count {
  color: var(--text-muted);
  font-size: 0.82rem;
  flex-shrink: 0;
}
.payment-record-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
/* 不管這一列有幾個備註/銀行標籤，刪除按鈕永遠固定在最右側 */
.payment-record-row > .icon-button.danger {
  margin-left: auto;
  flex-shrink: 0;
}
.payment-record-overpay {
  font-size: 0.76rem;
  font-weight: 700;
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.payment-record-discount {
  font-size: 0.76rem;
  font-weight: 600;
  color: #16a34a;
  background: rgba(22, 163, 74, 0.1);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.payment-record-row.has-tracked-diff {
  border-left: 3px solid #dc2626;
}

/* Tracked-diff payment-info-row highlight */
.pi-card.is-tracked-diff {
  border-color: rgba(220, 38, 38, 0.45) !important;
  background: rgba(220, 38, 38, 0.06) !important;
}
.pi-card.is-tracked-diff:hover {
  background: rgba(220, 38, 38, 0.12) !important;
  border-color: rgba(220, 38, 38, 0.65) !important;
}
.pi-card.is-tracked-diff .pi-check-icon {
  color: #dc2626;
}
.pi-card.is-tracked-diff .pi-chip {
  background: rgba(220, 38, 38, 0.13);
  color: #7f1d1d;
}

/* Diff tracking decision UI in drawers */
.payment-diff-track-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.payment-diff-track-wrap[hidden] {
  display: none;
}
.payment-diff-track-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}
.payment-diff-track-options {
  display: flex;
  gap: 1rem;
}
.payment-diff-track-opt {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.payment-diff-track-opt input[type="radio"] {
  accent-color: var(--primary);
}
.payment-diff-track-opt:has(input[value="1"]:checked) {
  color: #dc2626;
  font-weight: 600;
}

/* Tracked-diffs standalone card */
.tracked-diffs-card {
  border-color: rgba(220, 38, 38, 0.3) !important;
  grid-column: 2;
}
.tracked-diffs-card .section-head h2 {
  color: #dc2626;
}
.tracked-diffs-card .section-head h2 i {
  color: #dc2626;
}
.tracked-diffs-count {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}
.tracked-diffs-list {
  padding: 0 0 0.5rem;
}
.tracked-diff-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.87rem;
}
.tracked-diff-row:hover {
  background: rgba(220, 38, 38, 0.04);
}
.tracked-diff-icon {
  color: #dc2626;
  flex-shrink: 0;
}
.tracked-diff-date {
  font-weight: 600;
  white-space: nowrap;
}
.tracked-diff-method {
  color: var(--text-muted);
  font-size: 0.82rem;
}
.tracked-diff-amt {
  font-weight: 700;
  white-space: nowrap;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.tracked-diff-amt.is-overpay {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
}
.tracked-diff-amt.is-discount {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.1);
}
.tracked-diff-hint {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-style: italic;
}

/* Month + payment-status chips on one row */
.invoice-month-status-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.invoice-month-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1 1 auto;
}

.invoice-payment-status-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 0 0 auto;
}

/* Vendor chip overflow — in DOM for JS, hidden visually */
.vendor-chip-overflow {
  display: none !important;
}

/* Vendor chip: name left + sub-cat right, same line */
.filter-chip:has(.vendor-chip-cat) {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 5rem;
}

.filter-chip .vendor-chip-name {
  display: inline;
  white-space: nowrap;
}

.filter-chip .vendor-chip-cat {
  display: inline;
  font-size: 0.67rem;
  font-weight: 500;
  opacity: 0.55;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-chip.is-active .vendor-chip-cat {
  opacity: 0.8;
}

/* Inline status dot inside filter chips */
.status-dot-inline {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot-inline.unpaid {
  background: #f59e0b;
}
.status-dot-inline.paid {
  background: #22c55e;
}
.status-dot-inline.other {
  background: #94a3b8;
}

/* Payment status chip strip */
.invoice-payment-status-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.15rem 0 0.25rem;
}

/* Fee row */
.payment-fee-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

.payment-fee-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

.payment-fee-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.payment-fee-detail {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.payment-fee-detail[hidden] {
  display: none;
}

.payment-fee-detail input[type="number"] {
  width: 6rem;
  padding: 0.25rem 0.45rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--input-bg, #fff);
  color: var(--text);
}

.payment-fee-type-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text);
}

.payment-fee-type-opt input[type="radio"] {
  cursor: pointer;
}

/* Tax toggle row */
.payment-tax-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: -0.15rem;
}

.payment-tax-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.payment-tax-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.payment-tax-rate-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.payment-tax-rate-wrap[hidden] {
  display: none;
}

.payment-tax-rate-wrap input[type="number"] {
  width: 4rem;
  padding: 0.25rem 0.45rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.84rem;
  text-align: center;
  background: var(--surface);
  color: var(--text);
}

/* Tax breakdown card */
.payment-tax-breakdown {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.85rem;
  margin-top: 0.1rem;
}

.payment-tax-breakdown[hidden] {
  display: none;
}

.tax-breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.42rem 0.85rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
}

.tax-breakdown-row:last-child {
  border-bottom: none;
}

.tax-breakdown-row strong {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.tax-breakdown-row.is-total {
  background: rgba(59, 130, 246, 0.05);
  font-weight: 700;
}

.tax-breakdown-row.is-total span,
.tax-breakdown-row.is-total strong {
  color: var(--primary);
  font-size: 0.92rem;
}

/* Payment method radio group */
.payment-method-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.payment-method-option {
  display: flex;
}

.payment-method-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.payment-method-option span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.85rem;
  border-radius: 99px;
  border: 1.5px solid var(--border);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}

.payment-method-option input[type="radio"]:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.payment-method-option span:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Proxy deduction info in payment drawer */
.payment-proxy-deduction-info {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: #0369a1;
  background: rgba(3, 105, 161, 0.06);
  border: 1px solid rgba(3, 105, 161, 0.2);
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.4rem;
}
.payment-proxy-deduction-info .proxy-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Overpayment alert in payment drawer */
.payment-overpay-alert {
  background: rgba(220, 38, 38, 0.06);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.payment-overpay-alert-head {
  font-size: 0.8rem;
  font-weight: 700;
  color: #dc2626;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.payment-overpay-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.25rem 0.1rem;
  border-radius: 4px;
  transition: background 0.12s;
}
.payment-overpay-item:hover {
  background: rgba(220, 38, 38, 0.06);
}
.payment-overpay-item input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: #dc2626;
}
.payment-overpay-date {
  color: var(--text-muted);
  white-space: nowrap;
}
.payment-overpay-method {
  flex: 1;
  color: var(--text);
}
.payment-overpay-amt {
  font-weight: 700;
  color: #dc2626;
  white-space: nowrap;
}
.payment-overpay-summary {
  font-size: 0.78rem;
  color: #dc2626;
  padding-top: 0.3rem;
  border-top: 1px solid rgba(220, 38, 38, 0.2);
}
.payment-overpay-summary[hidden] {
  display: none;
}

/* Credit-card unsettled charges: compact summary link + drawer bank select */
.payment-cc-summary-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.payment-cc-summary-row .payment-cc-summary-card {
  flex: 1 1 320px;
}
.payment-cc-summary-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: #b45309;
  text-decoration: none;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.payment-cc-summary-card:hover {
  background: rgba(180, 83, 9, 0.06);
  border-color: rgba(180, 83, 9, 0.35);
}
.payment-cc-summary-card i {
  color: #b45309;
}
.payment-cc-summary-card .button {
  margin-left: auto;
}
.payment-cc-vendor-row {
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.25);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.payment-cc-vendor-row select {
  width: 100%;
  margin-top: 0.3rem;
}

/* Diff row */
.payment-diff-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border-radius: 7px;
  font-size: 0.84rem;
  font-weight: 600;
  margin-top: -0.1rem;
}

.payment-diff-row[hidden] {
  display: none;
}

.payment-diff-row.is-exact {
  background: rgba(22, 163, 74, 0.09);
  color: #15803d;
}

.payment-diff-row.is-discount {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
}

.payment-diff-row.is-overpay {
  background: rgba(220, 38, 38, 0.09);
  color: #dc2626;
}

.payment-diff-row .diff-hint {
  font-size: 0.76rem;
  font-weight: 400;
  opacity: 0.8;
}

/* ════════════════════════════════════════════════════════════════
   PROJECT PAGE — REDESIGN
   ════════════════════════════════════════════════════════════════ */

/* KPI strip */
.proj-kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.proj-kpi-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1.1rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.15s;
}
.proj-kpi-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.proj-kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.proj-kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--text);
}
.proj-kpi-value.is-green {
  color: #16a34a;
}
.proj-kpi-value.is-red {
  color: #dc2626;
}
.proj-kpi-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Filter zone */
.proj-filter-zone {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}

/* Customer chip strip */
.proj-customer-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.proj-customer-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.75rem;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.proj-customer-chip:hover,
.proj-customer-chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.proj-customer-overflow {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  background-size: 0.55rem;
  cursor: pointer;
}

/* Filter bar */
.proj-filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Project grid */
.proj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 0.85rem;
  align-items: start;
}

/* Project card */
.proj-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
}
.proj-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.09);
  border-color: rgba(148, 163, 184, 0.5);
}
.proj-card[data-date-hidden] {
  display: none;
}

/* Card top row */
.proj-card-top {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 1.6rem;
}
.proj-card-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.15s;
}
.proj-card:hover .proj-card-actions {
  opacity: 1;
}

/* Status pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.status-pill--active {
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
}
.status-pill--inactive {
  background: rgba(148, 163, 184, 0.15);
  color: #64748b;
}
.status-pill--overdue {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

/* Tag pills */
.proj-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.71rem;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Project name */
.proj-card-name {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Meta */
.proj-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  align-items: center;
}
.proj-card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Progress bar */
.proj-card-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.proj-progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 99px;
  overflow: hidden;
  min-width: 50px;
}
.proj-progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
  transition: width 0.3s;
}
.proj-progress-fill.is-overdue {
  background: #dc2626;
}
.proj-progress-pct {
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: right;
}

/* Finance section */
.proj-card-finances {
  display: flex;
  gap: 0.5rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  padding-top: 0.5rem;
  margin-top: 0.15rem;
}
.proj-finance-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.45rem 0.6rem;
  border-radius: 7px;
  text-decoration: none;
  background: rgba(148, 163, 184, 0.06);
  border: 1px solid transparent;
  transition: all 0.15s;
  min-width: 0;
}
.proj-finance-item:hover {
  background: rgba(59, 130, 246, 0.07);
  border-color: rgba(59, 130, 246, 0.2);
}
.proj-finance-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.proj-finance-amount {
  font-size: 0.88rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.proj-finance-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Responsive overrides for project page */
@media (max-width: 1200px) {
  .proj-kpi-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 860px) {
  .proj-kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .proj-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 600px) {
  .proj-kpi-strip {
    grid-template-columns: 1fr 1fr;
  }
  .proj-kpi-value {
    font-size: 1.25rem;
  }
  .proj-card-actions {
    opacity: 1;
  }
}

/* ── School management ─────────────────────────────────────────── */
.school-card {
  cursor: default;
}
.school-card .proj-card-top {
  align-items: center;
}

/* Attribution overlay */
.merge-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.merge-panel-overlay[hidden] {
  display: none;
}

.merge-panel {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  width: min(92vw, 800px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.merge-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  gap: 0.6rem;
}
.merge-panel-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.2rem 0.4rem;
}
.merge-panel-close:hover {
  color: var(--text);
}
.merge-panel-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.6rem 1.2rem 0;
}
.merge-error-msg {
  margin: 0.6rem 1.2rem;
  padding: 0.5rem 0.8rem;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 6px;
  font-size: 0.85rem;
}
.merge-panel-actions {
  display: flex;
  gap: 0.6rem;
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
}
.merge-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.8rem 1.2rem 0.3rem;
}

/* Attribution columns */
.attribution-panel {
  width: min(92vw, 860px);
}
.attribution-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  flex: 1;
  overflow: hidden;
}
.attribution-col {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.attribution-col-head {
  padding: 0.55rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.attr-count {
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}
.attribution-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
}
.attribution-item {
  display: flex;
  align-items: center;
  padding: 0.32rem 0.7rem;
  gap: 0.5rem;
}
.attribution-item:hover {
  background: var(--surface-strong);
}
.attribution-item-label {
  flex: 1;
  font-size: 0.83rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attr-move-btn {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 600px) {
  .attribution-cols {
    grid-template-columns: 1fr;
  }
  .attribution-panel {
    width: 96vw;
    max-height: 95vh;
  }
}

/* School card — attributed project list */
.school-proj-list {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.school-proj-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  padding: 0.1rem 0.05rem;
}
.school-proj-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.school-proj-cust {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.3rem;
}
.school-proj-amt {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.school-proj-ar {
  color: #16a34a;
  font-size: 0.72rem;
}
.school-proj-ap {
  color: #dc2626;
  font-size: 0.72rem;
}

/* 信用卡代墊 ledger: 每筆代墊下方一筆一行的品名/金額明細，跟主列的欄位對齊 */
tr[data-cc-detail-row] td {
  padding: 0.22rem 0.55rem;
  border-top: none !important;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface-strong);
}
tr[data-cc-detail-row].cc-detail-row-last td {
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border) !important;
}
.cc-detail-icon {
  font-size: 0.68rem;
  opacity: 0.4;
  margin-right: 0.4rem;
}
.cc-detail-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cc-detail-amount {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #64748b;
}
.cc-reminder-card {
  border-color: rgba(220, 38, 38, 0.28);
  background: rgba(220, 38, 38, 0.04);
}
.cc-bank-type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cc-view-toggle {
  margin-left: auto;
}
.cc-reminder-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cc-reminder-chip {
  text-decoration: none;
}
.cc-installment-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.06rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(147, 51, 234, 0.12);
  color: #7e22ce;
  white-space: nowrap;
}
.cc-batch-bar {
  position: sticky;
  bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1.25rem;
  margin-top: 1rem;
}

/* ── 翻頁帳本瀏覽頁 ── */
.flipbook-page {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0;
  align-items: stretch;
  min-height: calc(100vh - 76px - 2rem);
}

.flipbook-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
  max-height: calc(100vh - 76px - 2rem);
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 5.5rem;
}
/* 跟裡面個別頁籤（.flipbook-tab）同一套規則：貼著書本那一側是平角、露出來那一側是
   圓角，整個側欄容器本身也要照做，不能只有裡面的小頁籤是這樣。 */
.flipbook-tabs-left {
  border-radius: 16px 0 0 16px;
}
.flipbook-tabs-right {
  border-radius: 0 16px 16px 0;
}

.flipbook-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.flipbook-tab:hover {
  background: var(--surface-strong);
}
.flipbook-tab.is-active {
  background: var(--primary);
  color: #fff;
}

/* 左右頁籤都像貼在書側的索引標籤：緊貼本子那一側（左頁籤的右側／右頁籤的左側）是
   平角、跟本子融成一體，另一側（露出來的那一側）保留圓角。 */
.flipbook-tabs-left .flipbook-tab,
.flipbook-tabs-left .flipbook-tab-group-toggle {
  border-radius: 10px 0 0 10px;
}
.flipbook-tabs-right .flipbook-tab,
.flipbook-tabs-right .flipbook-tab-group-toggle {
  border-radius: 0 10px 10px 0;
}

.flipbook-tab-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.flipbook-tab-group-toggle:hover {
  background: var(--surface-strong);
}
.flipbook-tab-group-icon {
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.flipbook-tab-group.is-expanded .flipbook-tab-group-icon {
  transform: rotate(90deg);
}

.flipbook-tab-group-subs {
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  padding-left: 0.75rem;
  margin-top: 0.25rem;
}
.flipbook-tab-group.is-expanded .flipbook-tab-group-subs {
  display: flex;
}

.flipbook-tabs-divider {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0.4rem;
  flex-shrink: 0;
}

.flipbook-tabs-section-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.8rem 0.1rem;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.flipbook-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  min-height: 0;
  flex: 1;
}

/* 客戶/廠商顯示偏好——左右切換鈕，放在頂欄年份左側（見 include/header.php）。 */
.fb-display-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-strong);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.fb-display-toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fb-display-toggle-btn.is-active {
  background: var(--primary);
  color: #fff;
}

.flipbook-stage-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.flipbook-side-nav {
  flex: 0 0 auto;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: auto;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  font-size: 1rem;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.flipbook-side-nav:hover {
  background: rgba(51, 102, 255, 0.08);
  color: var(--accent);
}

.flipbook-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 400px;
}
.flipbook-empty i {
  font-size: 3rem;
  opacity: 0.4;
}

.flipbook-stage-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

.flipbook-stage {
  position: relative;
  width: 100%;
  /* 18px CSS fallback for first paint before JS applies the saved/default flipbook font
     size — independent of the site-wide root font-size (see fbSetFontSize() in
     flipbook.js), matching descendants below that use em instead of rem. */
  font-size: 18px;
}

.book-page {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.5rem 1rem;
  background: #fffdf7;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.book-page-entity {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--text);
}
.book-page-entity-title {
  min-width: 0;
}
/* 本子模擬實體帳本、寬度有限，年份不重複放在每一列日期欄，改成跟廠商名稱同一排、
   靠右顯示這個本子涵蓋的年度（只有一年就顯示那一年，涵蓋跨年結轉的帳款就顯示範圍）。 */
.book-page-year {
  flex: 0 0 auto;
  font-size: 0.75em;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.book-page-body {
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
}

/* Font-size deliberately NOT set here (and not on tr/thead/tbody either) — th/td below
   set their own em value directly, so it resolves relative to the book's own font-size
   (set on #flipbook-stage by fbSetFontSize()) with no nested-em compounding to track. */
/* table-layout:fixed + a <colgroup> built in JS from a per-field weight table
   (flipbook.js FIELD_COL_WEIGHT) — column widths depend only on which fields this
   book has configured, never on the actual text in any given row. Needed because
   the page-chunking logic (measureAndChunkEntries()) measures row heights in a probe
   table built from the WHOLE entries array, then those heights are used to decide
   how many rows fit on each real (partial) page — with table-layout:auto, auto-sized
   columns come out a different width in the probe vs. a page with a smaller subset
   of rows, so the measured heights didn't match the real rendered heights and pages
   ended up under/over-filled. Fixed per-field widths make probe and real pages
   identical, so measured height always matches rendered height. */
.book-page-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.book-page-table th,
.book-page-table td {
  padding: 0.2em 0.32em;
  text-align: left;
  white-space: normal;
  word-break: break-word;
  font-size: 0.78em;
}
.book-page-table thead tr {
  border-bottom: 1px solid var(--text);
}
.book-page-table th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.72em;
}
/* 廠商自訂欄位不再各自佔一欄，接在「品名」文字後面用灰字顯示（見 flipbook.js 的
   buildInvoiceTr()）——全站共用的 .item-spec 預設是 font-size:1rem（跟著網站根字級），
   這裡蓋掉改成跟本子自己的字級一起縮放，而不是被 flipbook 自己的字級控制排除在外。 */
.book-page-table .item-spec {
  font-size: 1em;
}
.book-page-table .unit-price-avg-tag {
  font-size: 0.68em;
  /* 帳本裡「平均」放在單價數字前面（跟應付/應收帳款列表放在後面不同，見
     flipbook.js buildInvoiceTr()），間距要改到右邊。 */
  margin-left: 0;
  margin-right: 0.3em;
}
.book-page-table .cc-installment-badge {
  font-size: 0.78em;
  margin-left: 0;
}
.book-page-table .pi-note-icon {
  font-size: 0.85em;
  margin-left: 0.35em;
  display: inline-block;
}
.book-page-table .invoice-discount-icon {
  font-size: 0.85em;
  margin-right: 0.3em;
}
/* 同一張訂單接續的列，日期欄不重複印 MM-DD，改印這個小直線接續記號（比照應付/應收
   帳款列表訂單編號欄的 .order-no-cont 用法），一眼就能看出上下兩列是同一張單。 */
.book-page-table .fb-order-cont {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  border-left: 2px solid rgba(100, 116, 139, 0.4);
  vertical-align: middle;
}
/* 格線跟著每一列實際的高度畫，不是固定間距的背景 — 這樣不管某一列內容
   是單行還是換行變高，線都會準確落在那一列的下緣。 */
.book-page-table tbody tr {
  border-bottom: 1px solid var(--border);
}
/* 狀態燈號比照應付/應收帳款列表：純圓點，不要疊上 .status-lamp 原本自帶的半透明底色
   圓角方塊，兩層半透明色疊在一起顏色會不乾淨。 */
.book-page-table .status-lamp {
  padding: 0.28em;
  background: transparent;
  gap: 0;
  cursor: default;
}
/* 欄寬本身已經由 JS 產生的 <colgroup>（見上方 table-layout:fixed 的說明）決定，這裡
   只需要防止日期／狀態燈號這種本來就很短的內容意外換行。 */
.book-page-table .date-cell {
  white-space: nowrap;
}
.book-page-table .status-cell {
  white-space: nowrap;
}
.book-page-table th.num-cell,
.book-page-table td.num-cell {
  text-align: right;
}

/* 本子跨年結轉時，序列中間插入的「YYYY年」分隔列（見 flipbook.js 的
   buildYearDividerTr()）——不用格線跟一般帳款列混在一起，用置中粗體＋淡底色標示。 */
.book-page-table tr.book-year-divider td {
  text-align: center;
  font-weight: 700;
  font-size: 0.78em;
  color: var(--text-muted);
  background: rgba(51, 102, 255, 0.06);
  padding: 0.25em 0.5em;
}

/* The reused .pi-card (payables page component) assumes a wide table; flipbook pages
   are much narrower, so let it wrap onto multiple lines instead of overflowing. Nested
   inside a td (already 0.78em of the book's own size), so 0.9em here lands on ~0.7em of
   the book's size overall — matching the same visual ratio as the other text. */
.book-page-table .pi-card {
  flex-wrap: wrap;
  max-width: 100%;
  font-size: 0.9em;
}
.book-page-table .pi-outer {
  max-width: 100%;
  justify-content: flex-end;
}

.book-page-footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.7em;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

@media (max-width: 720px) {
  .flipbook-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }
  .flipbook-tabs {
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }
  /* 手機版左右頁籤都變成同一排橫向捲動的小標籤，「書背」平角的比喻在直立雙欄版面才
     說得通，這裡兩邊（容器本身跟裡面的小頁籤）都還原成圓角比較一致。 */
  .flipbook-tabs-left,
  .flipbook-tabs-right {
    border-radius: 16px;
  }
  .flipbook-tabs-left .flipbook-tab,
  .flipbook-tabs-left .flipbook-tab-group-toggle,
  .flipbook-tabs-right .flipbook-tab,
  .flipbook-tabs-right .flipbook-tab-group-toggle {
    border-radius: 10px;
  }
}
