:root {
  --bg: #f6f5f1;
  --ink: #202124;
  --muted: #6f6f68;
  --line: #d9d5ca;
  --panel: #ffffff;
  --accent: #315f62;
  --accent-2: #9b6b35;
  --danger: #b64040;
  --shadow: 0 16px 40px rgba(25, 29, 31, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-btn,
.nav-link {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.file-btn:hover,
.nav-link:hover {
  border-color: var(--accent);
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px);
  background: #202124;
  color: #fff;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
}

h2 {
  font-size: clamp(22px, 3vw, 30px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.top-actions,
.filters,
.period,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  position: relative;
  background: transparent;
  color: #fff;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: #fff;
}

.report-jumps {
  position: sticky;
  top: 12px;
  z-index: 5;
}

main {
  padding: 24px clamp(14px, 4vw, 56px) 56px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
}

.portal-card {
  min-height: 240px;
  display: grid;
  align-content: space-between;
  padding: 24px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  text-decoration: none;
}

.portal-card:hover {
  border-color: var(--accent);
}

.portal-card span {
  color: var(--accent-2);
  font-weight: 800;
}

.portal-card p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
  overflow-x: auto;
}

.tab {
  white-space: nowrap;
  background: transparent;
}

.tab.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 18px;
}

.section-head.spaced {
  margin-top: 34px;
}

.anchor-section {
  scroll-margin-top: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-grid.compact {
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: span 2;
}

.form-actions {
  align-self: end;
  grid-column: span 2;
}

.summary-strip,
.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.kpi {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi strong {
  font-size: 24px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}

.report-table table {
  min-width: 1500px;
}

.full-analysis table {
  min-width: 2800px;
}

.full-analysis th,
.full-analysis td {
  padding: 8px 7px;
  font-size: 12px;
}

.full-analysis thead th {
  border-right: 1px solid #b9b3a6;
  text-align: center;
  vertical-align: middle;
}

.full-analysis thead tr:first-child th {
  background: #fffbd1;
  border-bottom: 2px solid #222;
}

.full-analysis .red-head {
  color: #d01818;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

td.note {
  max-width: 360px;
  white-space: normal;
  line-height: 1.45;
  text-align: left;
}

thead th {
  position: sticky;
  top: 0;
  background: #ebe7dd;
  color: #3b3d3c;
  font-size: 13px;
}

tbody tr:hover {
  background: #fbfaf7;
}

.full-analysis tbody tr.project-online-light {
  background: #fff;
}

.full-analysis tbody tr.project-online-gray {
  background: #e4e4e4;
}

.full-analysis tbody tr.project-pending,
.full-analysis tbody tr.subtotal-year,
.full-analysis tbody tr.subtotal-total {
  background: #fffbe6;
}

.full-analysis tbody tr.project-paused,
.full-analysis tbody tr.subtotal-partial {
  background: #e3f1dd;
}

.full-analysis tbody tr.project-closed,
.full-analysis tbody tr.subtotal-closed {
  background: #ffe3cf;
}

.full-analysis tbody tr.subtotal-online {
  background: #eef4ff;
}

.full-analysis tbody tr.subtotal-row td {
  border-top: 2px solid #222;
  font-weight: 800;
}

.full-analysis tbody tr.subtotal-row + tr.subtotal-row td {
  border-top: 1px solid #222;
}

.raw-check {
  margin-top: 14px;
  margin-bottom: 28px;
}

.raw-check summary {
  cursor: pointer;
  font-weight: 800;
  padding: 10px 0;
}

.raw-table table {
  min-width: 2400px;
}

.raw-table th,
.raw-table td {
  padding: 7px 8px;
  font-size: 12px;
}

.raw-table tbody tr:nth-child(odd) {
  background: #fff;
}

.raw-table tbody tr:nth-child(even) {
  background: #eeeeee;
}

.raw-table tbody tr.raw-subtotal {
  background: #fffbe6;
  font-weight: 800;
}

.workflow-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

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

.admin-mode-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
}

.admin-tabs-top {
  justify-content: flex-end;
  margin-left: auto;
}

.admin-mode-switch button {
  border-color: rgba(255, 255, 255, .35);
  background: transparent;
  color: #fff;
}

.admin-mode-switch button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: #243a63;
  font-weight: 800;
}

.status-badge[data-status="已送出"] {
  background: #fffbe6;
}

.status-badge[data-status="已核准"] {
  background: #e3f1dd;
}

.status-badge[data-status="退回修改"] {
  background: #ffe3cf;
}

.full-entry-fields {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.full-entry-fields summary {
  cursor: pointer;
  font-weight: 800;
}

.field-note {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.danger-note {
  color: var(--danger);
  font-weight: 800;
}

.entry-reference {
  grid-column: 1 / -1;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.reference-grid article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf7;
}

.reference-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.reference-grid strong {
  font-size: 16px;
}

.reference-alert {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid #f0b5a8;
  border-radius: 6px;
  background: #fff0ec;
  color: var(--danger);
  font-weight: 800;
}

.mini-input {
  min-width: 86px;
  padding: 6px 7px;
}

.weekly-entry-sections {
  grid-column: 1 / -1;
  display: grid;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.entry-block {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.entry-block-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.entry-block-head span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.entry-block-head h3 {
  margin: 0;
  font-size: 18px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  height: 18px;
}

.nested-grid {
  box-shadow: none;
  background: #fff;
}

.preview-panel,
.profit-focus,
.sync-panel,
.password-panel {
  margin: 0 0 18px;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sync-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.sync-status {
  min-width: min(100%, 320px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f4ee;
  color: var(--muted);
  font-weight: 800;
}

.sync-status[data-status="pending"] {
  border-color: #d8b76b;
  background: #fff8df;
  color: #7b5a13;
}

.sync-status[data-status="success"] {
  border-color: #9bc68b;
  background: #e9f5e3;
  color: #315f39;
}

.sync-status[data-status="error"] {
  border-color: #e3a08e;
  background: #fff0ec;
  color: var(--danger);
}

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

.top-button {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.logout-link {
  margin-left: auto;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(49, 95, 98, .16), transparent 34%), var(--bg);
}

.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  color: var(--ink);
  font-size: 28px;
}

.login-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #f0b5a8;
  border-radius: 6px;
  background: #fff0ec;
  color: var(--danger);
  font-weight: 800;
}

body[data-print-section] .topbar,
body[data-print-section] .dashboard-tools,
body[data-print-section] .kpis,
body[data-print-section] .top-button {
  display: none !important;
}

body[data-print-section="annualSection"] #huangSection,
body[data-print-section="annualSection"] #huangSection + .kpis,
body[data-print-section="annualSection"] #huangSection + .kpis + .table-wrap,
body[data-print-section="annualSection"] #yeSection,
body[data-print-section="annualSection"] #yeSection + .kpis,
body[data-print-section="annualSection"] #yeSection + .kpis + .table-wrap {
  display: none !important;
}

body[data-print-section="huangSection"] #annualSection,
body[data-print-section="huangSection"] #annualKpis,
body[data-print-section="huangSection"] #annualKpis + .table-wrap,
body[data-print-section="huangSection"] #yeSection,
body[data-print-section="huangSection"] #yeSection + .kpis,
body[data-print-section="huangSection"] #yeSection + .kpis + .table-wrap {
  display: none !important;
}

body[data-print-section="yeSection"] #annualSection,
body[data-print-section="yeSection"] #annualKpis,
body[data-print-section="yeSection"] #annualKpis + .table-wrap,
body[data-print-section="yeSection"] #huangSection,
body[data-print-section="yeSection"] #huangSection + .kpis,
body[data-print-section="yeSection"] #huangSection + .kpis + .table-wrap,
body[data-print-section="yeSection"] #huangSection ~ .raw-check {
  display: none !important;
}

.negative {
  color: var(--danger);
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 920px) {
  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .summary-strip,
  .kpis {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .portal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main {
    padding-inline: 12px;
  }

  .form-grid,
  .summary-strip,
  .kpis {
    grid-template-columns: 1fr;
  }

  .wide,
  .form-actions {
    grid-column: span 1;
  }
}

@media print {
  @page {
    size: A3 landscape;
    margin: 6mm;
  }

  .topbar,
  .tabs,
  .filters,
  #entry,
  #team,
  #settings {
    display: none !important;
  }

  main {
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .table-wrap,
  .kpi,
  .form-grid {
    box-shadow: none;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  table,
  .report-table table,
  .full-analysis table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;
  }

  th,
  td,
  .full-analysis th,
  .full-analysis td {
    padding: 3px 2px;
    font-size: 6px;
    line-height: 1.2;
    white-space: normal;
    word-break: keep-all;
  }

  .full-analysis thead th {
    font-size: 5.5px;
  }

  td.note {
    max-width: none;
  }

  .section-head {
    margin: 0 0 6px;
  }

  h2 {
    font-size: 16px;
  }
}
