:root {
  --ink: #1c2418;
  --muted: #5c6754;
  --paper: #f3eee4;
  --panel: #fffdf8;
  --line: #d9d0c0;
  --accent: #3d6b4f;
  --accent-deep: #244233;
  --gold: #b0893c;
  --empty: #9aa392;
  --danger: #a33;
  --content-max: 1180px;
  --thead-bg: #eef4ef;
  --sticky-head-2: 2.6rem;
  --rank-w: 3.25rem;
  --gutter: 16px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 10px 30px rgba(36, 66, 51, 0.05);
  --shadow-dialog: 0 20px 50px rgba(36, 66, 51, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overflow-x: clip;
  width: 100%;
}

@supports not (overflow: clip) {
  html {
    overflow-x: hidden;
  }
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at top right, rgba(176, 137, 60, 0.08), transparent 32%),
    linear-gradient(180deg, #efe8d9 0%, var(--paper) 220px);
}

.page-shell {
  width: min(var(--content-max), calc(100% - (var(--gutter) * 2)));
  margin-left: auto;
  margin-right: auto;
  min-width: 0;
  max-width: 100%;
}

.site-header {
  padding: 36px 0 8px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.header-brand {
  min-width: 0;
}

.header-actions,
.userbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.userbar button,
.login-card button {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.userbar button {
  background: transparent;
  color: var(--accent-deep);
}

.nav-link {
  color: var(--accent-deep);
  font-weight: 700;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-link:hover {
  text-decoration: underline;
  background: #eef4ef;
}

.toolbar button:hover:not(:disabled),
.section-head button:hover:not(:disabled),
.pager button:hover:not(:disabled),
.userbar button:hover:not(:disabled) {
  background: #eef4ef;
}

.btn-file:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toolbar,
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.btn-primary,
.section-head button,
.pager button,
.actions button,
.toolbar button {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.section-head button,
.pager button,
.actions button,
.toolbar button:not(.btn-primary) {
  background: transparent;
  color: var(--accent-deep);
}

.actions button.danger,
#confirm-ok.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn-file {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: inherit;
  font-weight: 700;
  color: var(--accent-deep);
  cursor: pointer;
  background: #fff;
}

.filter-grid {
  display: grid;
  gap: var(--space-3);
  align-items: end;
  justify-content: start;
}

.filter-grid.hub-filters,
.filter-grid.admin-filters {
  grid-template-columns: repeat(auto-fill, minmax(12.5rem, 16rem));
}

.filter-grid .toolbar,
.filter-grid .btn-row,
.filter-grid .hint {
  grid-column: 1 / -1;
}

.filter-grid .hint {
  margin: 4px 0 0;
}

.use-filter,
.dataset-filter {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  min-width: 0;
}

.use-filter legend,
.dataset-filter legend {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-deep);
  margin-right: 0.5rem;
}

.filter-grid input[type="search"],
.filter-grid input[type="text"],
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.table-scroll {
  overflow: auto;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.table-scroll-hint {
  display: none;
  font-size: 11.5px;
  color: var(--accent-deep);
  background: #eef4ef;
  border: 1px solid #d2e4d6;
  border-radius: 12px;
  padding: 3px 10px;
  margin-top: 6px;
  width: fit-content;
  align-items: center;
  gap: 4px;
  user-select: none;
}

.admin-table-wrap {
  max-height: 520px;
}

td.actions {
  white-space: nowrap;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: var(--space-3);
  padding: var(--space-2) 0;
}

.pager-info {
  font-size: 14px;
  color: var(--muted);
  margin-right: auto;
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pager-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: var(--radius);
}

.pager button.active,
.pager-btn.active {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
  font-weight: 700;
}

.pager-size-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.pager-size-wrap select {
  padding: 5px 8px;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.pager-ellipsis {
  padding: 0 4px;
  color: var(--muted);
  user-select: none;
}

.pager-view-all-btn {
  margin-left: 8px;
  font-size: 13px;
  padding: 6px 12px;
  background: #f0f7f2;
  color: var(--accent-deep);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s ease;
}

.pager-view-all-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Table Header Drag & Drop (Note: do NOT use position: relative; it overrides sticky positioning on thead th and breaks multi-row headers) */
th.th-draggable {
  cursor: grab;
  user-select: none;
  transition: background-color 0.15s ease;
}

th.th-draggable:hover {
  background-color: #e8efe9;
}

th.th-draggable:active,
th.th-draggable.th-dragging {
  cursor: grabbing;
  opacity: 0.5;
  background-color: #d8e5da;
}

th.drag-over-left {
  border-left: 3px solid var(--accent) !important;
  background-color: #f0f7f2 !important;
}

th.drag-over-right {
  border-right: 3px solid var(--accent) !important;
  background-color: #f0f7f2 !important;
}

.th-drag-handle {
  display: inline-block;
  opacity: 0.4;
  font-size: 11px;
  margin-right: 3px;
  vertical-align: baseline;
  cursor: grab;
}

th.th-draggable:hover .th-drag-handle {
  opacity: 0.85;
  color: var(--accent-deep);
}

/* Column Reorder Modal & Chips */
.col-order-section {
  margin-bottom: var(--space-3);
}

.col-order-section h4 {
  margin: 0 0 var(--space-2);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.col-order-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px;
  background: #fbfcfb;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.col-order-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.col-order-chip:hover {
  border-color: var(--accent);
  background: #f4f8f5;
}

.col-order-chip.chip-dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.col-order-chip.drag-over-left {
  border-left: 3px solid var(--accent);
}

.col-order-chip.drag-over-right {
  border-right: 3px solid var(--accent);
}

.chip-handle {
  color: var(--muted);
  font-size: 12px;
}

.chip-arrow-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 10px;
  color: var(--muted);
  line-height: 1;
  border-radius: 3px;
}

.chip-arrow-btn:hover {
  color: var(--accent-deep);
  background: rgba(0, 0, 0, 0.08);
}

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: min(720px, calc(100vw - 32px));
  width: calc(100vw - 32px);
  box-shadow: var(--shadow-dialog);
}

dialog::backdrop {
  background: rgba(28, 36, 24, 0.35);
}

dialog form {
  padding: var(--space-5);
}

dialog h3 {
  margin: 0 0 var(--space-3);
  font-family: "Noto Serif TC", serif;
}

.form-grid {
  display: grid;
  gap: 12px;
  max-height: 50vh;
  overflow: auto;
}

.form-grid label input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.login-card {
  width: min(420px, 100%);
  margin: 40px auto;
}

.login-card form {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.login-card button {
  margin-top: 4px;
  padding: 12px;
  width: 100%;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: none;
  font-size: 12px;
  color: var(--gold);
  font-weight: 700;
}

h1,
h2 {
  font-family: "Noto Serif TC", "Noto Sans TC", serif;
  font-weight: 700;
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0.04em;
}

.lede,
.sub,
.hint,
footer p {
  color: var(--muted);
  line-height: 1.7;
}

.lede {
  max-width: 42em;
  margin: 12px 0 0;
}

main.page-shell {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5) 0 48px;
  min-width: 0;
  max-width: 100%;
}

main.page-shell > *,
#view-rankings,
#view-summary,
#view-usage {
  min-width: 0;
  max-width: 100%;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: var(--space-1);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-deep);
}

label.inline {
  grid-auto-flow: column;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: 100%;
}

label.inline select {
  width: max-content;
  min-width: 12rem;
  max-width: 18rem;
}

select {
  appearance: none;
  width: auto;
  max-width: 100%;
  padding: 10px 12px;
  padding-right: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23244233' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  font: inherit;
  color: var(--ink);
}

.filter-grid > label select {
  width: 100%;
}

.toolbar > label {
  width: max-content;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: end;
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.section-meta {
  min-width: 0;
  flex: 1 1 12rem;
}

h2 {
  font-size: 22px;
}

.sub {
  margin: 6px 0 0;
  font-size: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

#month-table,
#pivot-table {
  min-width: 720px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

thead th {
  background: var(--thead-bg);
  color: var(--accent-deep);
  font-size: 13px;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 4;
}

thead tr:nth-child(2) th {
  top: var(--sticky-head-2);
}

.table-scroll td.name,
.table-scroll th.col-name,
.table-scroll td.sticky-col,
.table-scroll th.sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
  box-shadow: 4px 0 8px rgba(36, 66, 51, 0.08);
}

.table-scroll thead th.col-name,
.table-scroll thead th.sticky-col,
.table-scroll thead th.col-rank {
  z-index: 5;
  background: var(--thead-bg);
}

.table-scroll th.sticky-col-check,
.table-scroll td.sticky-col-check {
  position: sticky;
  left: 0;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  text-align: center;
  z-index: 3;
  background: var(--panel);
}

.table-scroll th.sticky-col-actions,
.table-scroll td.sticky-col-actions {
  position: sticky;
  left: 40px;
  width: 185px;
  min-width: 185px;
  z-index: 3;
  background: var(--panel);
  box-shadow: 4px 0 8px rgba(36, 66, 51, 0.08);
}

.table-scroll thead th.sticky-col-check,
.table-scroll thead th.sticky-col-actions {
  z-index: 6;
  background: var(--thead-bg);
}

#month-table .col-rank,
#month-table td.rank {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
}

#month-table thead .col-rank {
  z-index: 5;
  background: var(--thead-bg);
}

#month-table .col-name,
#month-table td.name,
#month-table tfoot th.name {
  left: var(--rank-w);
}

#month-table tfoot {
  position: sticky;
  bottom: 0;
  z-index: 3;
}

#month-table tfoot th {
  background: #f0f4f1;
  color: var(--accent-deep);
  font-weight: 700;
  border-top: 2px solid var(--line);
  box-shadow: 0 -2px 6px rgba(36, 66, 51, 0.05);
}

#month-table tfoot .col-rank,
#month-table tfoot th.name {
  background: #f0f4f1;
  z-index: 4;
}

.num,
td.num,
th.num {
  text-align: right;
}

.col-name,
td.name {
  min-width: 180px;
}

tbody tr:hover {
  background: #f7f3ea;
}

tbody tr:hover td.name,
tbody tr:hover td.rank,
tbody tr:hover td.sticky-col,
tbody tr:hover td.sticky-col-check,
tbody tr:hover td.sticky-col-actions {
  background: #f7f3ea;
}

.rank {
  color: var(--gold);
  font-weight: 700;
}

.empty {
  margin: var(--space-3) 0 0;
  color: var(--empty);
}

footer.page-shell {
  padding-bottom: 40px;
  font-size: 13px;
}

.heat {
  font-weight: 700;
  background: rgba(61, 107, 79, var(--heat-alpha, 0));
}

.metric-sub {
  font-weight: 500;
  color: var(--muted);
}

.banner {
  margin: 0;
}

@media (prefers-contrast: more), print {
  .heat {
    --heat-alpha: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@media (max-width: 900px) {
  :root {
    --gutter: 14px;
  }

  .header-row,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions,
  .userbar {
    justify-content: flex-start;
  }

  .filter-grid.hub-filters,
  .filter-grid.admin-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-head .toolbar,
  .section-head label.inline,
  .section-head button {
    width: 100%;
  }

  .section-head label.inline select,
  .section-head button {
    width: 100%;
  }
}

@media (max-width: 768px) {
  :root {
    --rank-w: 2.2rem;
    --sticky-head-2: 2.15rem;
  }

  .table-scroll-hint {
    display: inline-flex;
  }

  #month-table,
  #pivot-table {
    min-width: 580px;
  }

  /* 數值單元格微緊湊化，有效縮減橫向總寬度 */
  th,
  td {
    padding: 7px 6px;
    font-size: 12.5px;
  }

  th.num,
  td.num {
    padding: 7px 5px;
    font-size: 12.5px;
  }

  /* 凍結欄位緊湊化：排名欄縮減至 35px，建案名稱縮減至 105px-125px */
  #month-table .col-rank,
  #month-table td.rank {
    width: var(--rank-w);
    min-width: var(--rank-w);
    max-width: var(--rank-w);
    padding: 7px 2px;
    text-align: center;
    font-size: 11.5px;
  }

  .col-name,
  td.name {
    min-width: 105px;
    max-width: 125px;
    padding: 7px 6px;
  }

  .project-name-cell {
    gap: 3px;
  }

  .project-name-text {
    font-size: 12.5px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.25;
  }

  .name-edit-btn {
    font-size: 11px;
    padding: 1px 2px;
  }

  /* 凍結欄右側邊界深層立體陰影，讓滑動資料有極清晰的下潛層次 */
  #month-table .col-name,
  #month-table td.name,
  #month-table tfoot th.name,
  .table-scroll td.name,
  .table-scroll th.col-name,
  .table-scroll td.sticky-col,
  .table-scroll th.sticky-col {
    box-shadow: 6px 0 12px -2px rgba(36, 66, 51, 0.18);
  }

  /* Admin 表格操作欄緊湊化 */
  .table-scroll th.sticky-col-actions,
  .table-scroll td.sticky-col-actions {
    width: 135px;
    min-width: 135px;
    padding: 4px;
    box-shadow: 6px 0 12px -2px rgba(36, 66, 51, 0.18);
  }

  .sticky-col-actions button {
    padding: 3px 5px;
    font-size: 11px;
  }
}

@media (max-width: 600px) {
  :root {
    --gutter: 12px;
  }

  .panel {
    padding: 14px 10px;
    border-radius: var(--radius);
  }

  .table-scroll {
    border-radius: 8px;
  }

  .site-header {
    padding-top: 24px;
  }

  .header-actions,
  .userbar {
    gap: 8px;
    font-size: 13px;
  }

  .userbar button,
  .userbar .nav-link {
    padding: 6px 10px;
    font-size: 13px;
  }

  .view-tabs {
    gap: 6px;
    margin-left: calc(var(--gutter) * -1);
    margin-right: calc(var(--gutter) * -1);
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }

  .tab-btn {
    padding: 8px 14px;
    font-size: 13.5px;
  }

  .filter-grid.hub-filters,
  .filter-grid.admin-filters {
    grid-template-columns: 1fr;
  }

  .toolbar .btn-primary,
  .toolbar button,
  .btn-file {
    flex: 1 1 auto;
  }

  .dialog-actions {
    justify-content: stretch;
  }

  .dialog-actions button {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Import Modal & Dropzone --- */
.import-modal {
  max-width: 620px;
}

.import-dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: #fbfdfb;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin: var(--space-3) 0;
}

.import-dropzone:hover,
.import-dropzone.dragover {
  border-color: var(--accent);
  background: #f0f7f2;
}

.dropzone-icon {
  font-size: 36px;
  line-height: 1;
  margin-bottom: 8px;
}

.dropzone-text {
  font-weight: 500;
  color: var(--ink);
  font-size: 15px;
}

.dropzone-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.dropzone-filename {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 12px;
  background: #e6f0e8;
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 14px;
  border-radius: 6px;
}

.import-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: var(--space-3) 0;
  padding: 12px;
  background: #f6f8f6;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.import-options label {
  font-size: 13.5px;
}

.import-progress-wrap {
  margin: var(--space-3) 0;
}

.import-progress-bar-bg {
  width: 100%;
  height: 14px;
  background: #e4ebe5;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}

.import-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-deep) 100%);
  border-radius: 7px;
  transition: width 0.3s ease;
}

.import-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.import-status-text {
  font-weight: 700;
  color: var(--accent-deep);
  font-size: 14px;
  margin: 8px 0;
}

.import-success-banner {
  padding: 14px 16px;
  background: #eef7f0;
  border: 1px solid #b7deb9;
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}

.import-success-banner h4 {
  margin: 0 0 6px;
  color: var(--accent-deep);
  font-size: 16px;
}

.import-success-banner p {
  margin: 0;
  font-size: 13px;
  color: var(--ink);
}

.import-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: var(--space-3) 0;
}

@media (max-width: 500px) {
  .import-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.import-stat-card {
  padding: 10px;
  background: #fafbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.import-stat-card .num {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}

.import-stat-card .label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* View Tabs */
.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: var(--space-3);
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  background: transparent;
  padding: 10px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s ease;
  border-radius: var(--radius) var(--radius) 0 0;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--accent-deep);
  background: rgba(61, 107, 79, 0.05);
}

.tab-btn.active {
  color: var(--accent-deep);
  border-bottom-color: var(--accent);
  background: var(--panel);
}

/* Other Row Highlight */
tr.is-other-row {
  background-color: #fcf8f0;
  font-style: italic;
  color: #705b38;
}

tr.is-other-row td.name {
  font-weight: 700;
}

/* Badges */
.badge-cat {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  background: #e8f0eb;
  color: var(--accent-deep);
}

/* Summary and Usage Tables */
.summary-total-row {
  background: #f0f4f1;
  font-weight: 700;
  border-top: 2px solid var(--line);
}

#summary-table th,
#summary-table td,
#usage-table th,
#usage-table td {
  white-space: nowrap;
}

/* --- Danger Button --- */
.btn-danger {
  appearance: none;
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-danger:hover:not(:disabled) {
  background: #8b2525;
  border-color: #8b2525;
}

.btn-danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --- Sortable Headers --- */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

th.sortable:hover {
  background: #dfece1;
}

.sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
  opacity: 0.4;
  vertical-align: middle;
}

th.sorted .sort-icon {
  opacity: 1;
  color: var(--accent-deep);
  font-weight: 700;
}

/* --- Detail Modal & Cards --- */
.detail-modal {
  max-width: 860px;
  width: calc(100vw - 32px);
}

.detail-dialog-inner {
  padding: var(--space-4) var(--space-5);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  padding: 2px;
}

.detail-card {
  background: #fbf9f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.detail-card:hover {
  background: #f5efe3;
  border-color: #c4b9a3;
}

.detail-card .detail-key {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-deep);
}

.detail-card .detail-val {
  font-size: 13.5px;
  color: var(--ink);
  word-break: break-all;
  user-select: text;
}

.detail-card .detail-val.empty {
  color: var(--muted);
  font-style: italic;
}

/* Field Filter Input */
.field-filter-bar {
  margin-bottom: 12px;
  position: relative;
}

.field-filter-bar input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  background: #fff;
}

/* Action button icons */
.actions button {
  padding: 4px 8px;
  font-size: 12px;
  margin-right: 4px;
}

.actions button.btn-view {
  border-color: #3d6b4f;
  color: #244233;
}

.actions button.btn-view:hover {
  background: #eef4ef;
}

/* --- Excel Import Page Styles --- */
.excel-import-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

@media (max-width: 900px) {
  .excel-import-grid {
    grid-template-columns: 1fr;
  }
}

.template-card {
  background: #fbf9f4;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-3);
}

.template-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.template-card-icon {
  font-size: 32px;
}

.template-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.template-card-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.col-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.col-tag {
  display: inline-block;
  padding: 2px 8px;
  background: #eee8db;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent-deep);
  font-weight: 500;
}

.caveat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin-top: var(--space-3);
}

.caveat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 6px;
  padding: 12px 14px;
}

.caveat-card.caution {
  border-left-color: var(--danger);
}

.caveat-card.info {
  border-left-color: var(--accent);
}

.caveat-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.caveat-text {
  font-size: 13px;
  line-height: 1.55;
  color: #4a5445;
  margin: 0;
}

.caveat-text code {
  background: #f0ebe0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* --- Summary Table Meta Editing --- */
#summary-table tbody tr {
  transition: background 0.12s ease;
}

#summary-table tbody tr:hover {
  background: #f3f8f4;
}

.col-action {
  text-align: center;
  white-space: nowrap;
}

.btn-edit-meta {
  appearance: none;
  border: 1px solid var(--accent);
  background: #eef6f0;
  color: var(--accent-deep);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-edit-meta:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
  box-shadow: 0 2px 6px rgba(36, 66, 51, 0.2);
}

td.cell-editable {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

td.cell-editable:hover {
  background-color: #eef6f0 !important;
  color: var(--accent-deep);
}

.manual-badge {
  display: inline-block;
  font-size: 11px;
  margin-left: 4px;
  opacity: 0.75;
  vertical-align: middle;
}

.project-name-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}

.project-name-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.35;
  transition: all 0.15s ease;
  line-height: 1;
  flex-shrink: 0;
}

td.name:hover .name-edit-btn,
tr:hover .name-edit-btn,
td.cell-editable:hover .name-edit-btn {
  opacity: 0.85;
  color: var(--accent-deep);
}

.name-edit-btn:hover {
  opacity: 1 !important;
  color: var(--accent-deep);
  background: rgba(43, 89, 54, 0.12);
  transform: scale(1.15);
}

.meta-edit-dialog {
  max-width: min(660px, calc(100vw - 32px));
  width: calc(100vw - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow-dialog);
}

.meta-edit-dialog.modal-wide {
  max-width: min(1080px, calc(100vw - 32px));
}

.meta-edit-dialog .modal-inner {
  padding: 20px 24px;
}

.meta-edit-dialog form {
  padding: 0;
}

#deal-edit-dialog form,
#project-rename-dialog form {
  padding: 20px 24px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head-title h3,
.modal-head h3 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--ink);
}

.modal-head-title .sub,
.modal-head .sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-close-icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close-icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink);
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 16px;
}

.modal-tab-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.modal-tab-btn:hover {
  color: var(--accent-deep);
}

.modal-tab-btn.active {
  color: var(--accent-deep);
  border-bottom-color: var(--accent);
}

.tab-badge {
  background: #e0eee4;
  color: var(--accent-deep);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
}

/* Deals Pane */
.modal-pane {
  display: flex;
  flex-direction: column;
}

.modal-pane[hidden] {
  display: none !important;
}

.deals-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.deals-info-text {
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}

.deals-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.deals-search-input {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 220px;
}

.btn-primary-sm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary-sm:hover {
  background: var(--accent-deep);
}

.btn-sm {
  background: #f4f6f4;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-sm:hover {
  background: #e8ede9;
}

.deals-table-wrap {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 14px;
}

.deals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.deals-table th,
.deals-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.deals-table th {
  background: #f8faf8;
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 600;
  color: var(--ink);
}

.deals-table tbody tr:hover {
  background: #f0f7f2;
}

.deal-actions-wrap {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.btn-deal-edit,
.btn-deal-del {
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-deal-edit:hover {
  background: #e0eee4;
  border-color: var(--accent);
  color: var(--accent-deep);
}

.btn-deal-del:hover {
  background: #fee;
  border-color: #e57373;
  color: var(--danger, #c62828);
}


.meta-form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .form-row-2col {
    grid-template-columns: 1fr;
  }
}

.form-row-1col {
  display: grid;
  grid-template-columns: 1fr;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.form-field input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(43, 89, 54, 0.15);
}

.input-readonly {
  background: #f4f6f4;
  color: var(--text-muted);
  cursor: default;
}

.input-project-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-deep);
  background: #f0f6f2;
}

.meta-stats-preview {
  background: #eef6f0;
  border: 1px solid #d2e6d6;
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.preview-item {
  font-size: 13px;
  color: var(--text);
}

.preview-rem-val {
  color: var(--accent-deep);
  font-size: 16px;
}

.preview-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* --- Floating Toast Notification --- */
.app-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1b3824;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.app-toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.app-toast.toast-error {
  background: var(--danger);
}

/* --- Card View System (Stage 3 Mobile UX) --- */
.view-mode-toggle {
  display: inline-flex;
  background: #eef4ef;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.view-mode-btn {
  appearance: none;
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  padding: 5px 10px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  border-radius: 6px !important;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.2;
}

.view-mode-btn:hover {
  color: var(--accent-deep) !important;
}

.view-mode-btn.active {
  background: var(--panel) !important;
  color: var(--accent-deep) !important;
  box-shadow: 0 1px 4px rgba(36, 66, 51, 0.12);
  font-weight: 700 !important;
}

.project-cards-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 6px;
}

@media (min-width: 601px) and (max-width: 1024px) {
  .project-cards-container {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

.project-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 2px 8px rgba(36, 66, 51, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.project-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(36, 66, 51, 0.08);
}

.project-card.is-other {
  background: #fcf8f0;
  border-color: #e8ddca;
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(217, 208, 192, 0.5);
  padding-bottom: 8px;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.card-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 26px;
  padding: 0 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.card-rank-badge.top-1 {
  background: #c59b27;
}

.card-rank-badge.top-2 {
  background: #78909c;
}

.card-rank-badge.top-3 {
  background: #a1744b;
}

.card-project-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-deep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  background: #fbfdfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.card-metric-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-metric-label {
  font-size: 11.5px;
  color: var(--muted);
}

.card-metric-value {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.card-metric-value.highlight {
  color: var(--accent-deep);
  font-size: 16px;
}

.card-rooms-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.room-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eef4ef;
  border: 1px solid #d4e2d7;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--ink);
}

.room-chip strong {
  color: var(--accent-deep);
}

.room-chip.empty {
  opacity: 0.45;
  background: #f8f8f8;
  border-color: #e5e5e5;
}

.card-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px dashed rgba(217, 208, 192, 0.6);
}

.btn-card-expand {
  appearance: none;
  background: transparent !important;
  border: none !important;
  color: var(--accent) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  padding: 4px 6px !important;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.card-expanded-content {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f6f8f6;
  border-radius: 8px;
  font-size: 12.5px;
  border: 1px solid #e2ece4;
}

.card-expanded-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  padding-bottom: 4px;
}

.card-expanded-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
