:root {
  --bg: #070c16;
  --bg-2: #0b1422;
  --sidebar: #07181a;
  --panel: #0a1020;
  --panel-2: #0b1728;
  --line: rgba(102, 246, 211, 0.18);
  --line-soft: rgba(148, 163, 184, 0.16);
  --text: #f5f8fb;
  --muted: #95a4b7;
  --dim: #64748b;
  --mint: #68f7c7;
  --cyan: #34d8ff;
  --warn: #f6c45f;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(6, 78, 59, 0.16), transparent 24rem),
    linear-gradient(135deg, var(--bg) 0%, #090d1b 42%, #0b1628 100%);
  font-family: "Noto Sans TC", system-ui, sans-serif;
}

body.auth-locked .shell {
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, rgba(104, 247, 199, 0.14), transparent 34%),
    linear-gradient(135deg, #061414 0%, #070c16 48%, #0b1628 100%);
}

.auth-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 16, 32, 0.98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.auth-card h2 {
  margin: 8px 0 0;
  font-size: 28px;
}

.auth-card p,
.auth-card small {
  margin: 6px 0 0;
  color: var(--muted);
}

.auth-card label {
  display: grid;
  gap: 8px;
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
}

.auth-card input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  color: var(--text);
  background: rgba(7, 12, 22, 0.92);
  outline: none;
}

body.modal-open {
  overflow: hidden;
}

button {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  padding: 20px 12px;
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #071b1c 0%, #070b17 62%);
}

.brand-card {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: auto;
  padding: 28px 14px 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.eyebrow {
  color: var(--mint);
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.34em;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 1px solid rgba(104, 247, 199, 0.45);
  border-radius: 18px;
  color: #06201a;
  background: linear-gradient(135deg, var(--mint), #d7fff4);
  box-shadow: 0 0 28px rgba(104, 247, 199, 0.18);
  font-family: "Space Grotesk", sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-logo strong,
.brand-logo small {
  display: block;
}

.brand-logo strong {
  color: var(--text);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-logo small {
  margin-top: 6px;
  color: var(--mint);
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.panel-head p,
.task-main span,
.task-meta,
.metric-card small {
  color: var(--muted);
}

.nav {
  margin-top: 34px;
}

.nav-group {
  margin: 28px 10px 14px;
  color: var(--dim);
  font-size: 14px;
  font-weight: 700;
}

.nav-item {
  position: relative;
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 8px 16px 8px 34px;
  border: 0;
  border-radius: 12px;
  color: #cbd5e1;
  background: transparent;
  text-align: left;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.nav-item::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #56657a;
  transform: translateY(-50%);
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
  background: rgba(104, 247, 199, 0.06);
}

.nav-item.active::before {
  background: var(--mint);
  box-shadow: 0 0 16px rgba(104, 247, 199, 0.7);
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 94px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line-soft);
}

.topbar h1 {
  margin: 8px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: #d7e1ef;
  background: rgba(15, 23, 42, 0.72);
  font-weight: 700;
}

.primary-button {
  color: var(--mint);
  border-color: rgba(104, 247, 199, 0.26);
  background: rgba(20, 83, 75, 0.46);
  cursor: pointer;
}

.metric-grid,
.content-grid,
.ledger-panel {
  width: min(1414px, calc(100% - 84px));
  margin-inline: auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-top: 36px;
}

.metric-card {
  position: relative;
  min-height: 188px;
  padding: 28px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(10, 16, 32, 0.98), rgba(11, 23, 40, 0.96));
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--mint), var(--cyan), transparent 80%);
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.metric-head b {
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--mint);
  background: rgba(20, 83, 75, 0.45);
  font-size: 14px;
}

.metric-card strong {
  display: block;
  margin-top: 22px;
  font-family: "Space Grotesk", "Noto Sans TC", sans-serif;
  font-size: 42px;
}

.metric-card small {
  display: block;
  margin-top: 16px;
  font-size: 15px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 524px;
  gap: 20px;
  margin-top: 30px;
  margin-bottom: 48px;
}

.content-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(10, 16, 32, 0.92);
}

.panel-head {
  margin-bottom: 24px;
}

.panel-head h2 {
  margin: 0;
  font-size: 26px;
}

.panel-head p {
  margin: 8px 0 0;
  font-size: 17px;
  font-weight: 600;
}

.overview-table {
  display: grid;
  gap: 0;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.25fr;
  gap: 18px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid var(--line-soft);
  color: #cbd5e1;
}

.table-row:last-child {
  border-bottom: 0;
}

.table-head {
  min-height: 54px;
  color: var(--dim);
  font-weight: 700;
}

.table-row strong {
  color: var(--text);
  font-size: 19px;
}

.table-row a {
  color: var(--mint);
  text-decoration: none;
  font-weight: 700;
}

.task-list {
  display: grid;
  gap: 16px;
}

.task-row {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(7, 12, 22, 0.58);
}

.task-main b,
.task-main span {
  display: block;
}

.task-main b {
  color: #dbe7f4;
  font-size: 17px;
}

.task-main span {
  margin-top: 6px;
  line-height: 1.55;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--mint);
  background: rgba(20, 83, 75, 0.45);
  font-size: 13px;
  font-weight: 700;
}

.badge.alert {
  color: var(--warn);
  background: rgba(113, 63, 18, 0.36);
}

.flow-chip {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(104, 247, 199, 0.2);
  border-radius: 999px;
  color: var(--mint);
  background: rgba(20, 83, 75, 0.18);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.ledger-panel {
  margin-top: 30px;
  margin-bottom: 48px;
}

.content-grid + .ledger-panel {
  margin-top: -18px;
}

.ledger-card {
  overflow: hidden;
}

.ledger-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.export-button {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid rgba(104, 247, 199, 0.28);
  border-radius: 999px;
  color: var(--mint);
  background: rgba(20, 83, 75, 0.42);
  font-weight: 800;
  cursor: pointer;
}

.export-button:hover {
  background: rgba(20, 83, 75, 0.62);
}

.ledger-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.ledger-summary div {
  min-height: 86px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(7, 12, 22, 0.5);
}

.ledger-summary span,
.ledger-row-head {
  color: var(--dim);
  font-weight: 700;
}

.ledger-summary strong {
  display: block;
  margin-top: 10px;
  font-family: "Space Grotesk", "Noto Sans TC", sans-serif;
  font-size: 26px;
}

.ledger-form {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(240px, 1.7fr) 1fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 22px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: rgba(7, 12, 22, 0.5);
}

.ledger-form label {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.ledger-form label span {
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
}

.ledger-form input,
.ledger-form select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  color: var(--text);
  background: rgba(10, 16, 32, 0.95);
  outline: none;
}

.ledger-form input:focus,
.ledger-form select:focus {
  border-color: rgba(104, 247, 199, 0.48);
}

.settings-block {
  display: grid;
  gap: 18px;
}

.module-block {
  display: grid;
  gap: 18px;
}

.module-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: rgba(7, 12, 22, 0.5);
}

.module-form label {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.module-form label span,
.inline-hint {
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
}

.module-form input,
.module-form select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  color: var(--text);
  background: rgba(10, 16, 32, 0.95);
  outline: none;
}

.module-form select[multiple] {
  min-height: 94px;
  padding: 10px 12px;
}

.module-form input:focus,
.module-form select:focus {
  border-color: rgba(104, 247, 199, 0.48);
}

.wide-field {
  grid-column: span 2;
}

.module-table {
  display: grid;
}

.module-row {
  display: grid;
  gap: 14px;
  align-items: center;
  min-height: 64px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  color: #cbd5e1;
}

.module-row:last-child {
  border-bottom: 0;
}

.module-row-head {
  min-height: 54px;
  color: var(--dim);
  font-weight: 700;
}

.module-row-customer {
  grid-template-columns: 1.45fr 0.8fr 1.25fr 0.5fr 1.25fr;
}

.module-row-contract {
  grid-template-columns: 1.3fr 0.7fr 0.8fr 0.7fr 0.8fr 0.9fr;
}

.module-row-dispatch {
  grid-template-columns: 0.8fr 1.1fr 1fr 1.1fr 0.7fr 0.9fr;
}

.module-row-revenue,
.module-row-inventory,
.module-row-staff,
.module-row-access,
.module-row-invoice,
.module-row-service,
.module-row-site {
  grid-template-columns: 0.8fr 1.1fr 1fr 0.8fr 0.7fr 0.9fr;
}

.module-row strong,
.module-row small {
  display: block;
}

.module-row strong {
  color: var(--text);
  font-size: 16px;
}

.module-row small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.inline-hint {
  padding: 12px 16px;
  border: 1px dashed rgba(104, 247, 199, 0.24);
  border-radius: 14px;
  background: rgba(20, 83, 75, 0.12);
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: rgba(7, 12, 22, 0.5);
}

.settings-form label {
  display: grid;
  gap: 8px;
}

.settings-form label span {
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
}

.settings-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  color: var(--text);
  background: rgba(10, 16, 32, 0.95);
  outline: none;
}

.settings-table {
  display: grid;
}

.settings-row {
  display: grid;
  grid-template-columns: 1.2fr 0.6fr 0.8fr 1.5fr;
  gap: 14px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid var(--line-soft);
  color: #cbd5e1;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row-head {
  color: var(--dim);
  font-weight: 700;
}

.settings-row strong {
  color: var(--text);
}

.muted-state {
  color: var(--dim);
  font-weight: 800;
}

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.form-launcher {
  justify-self: start;
}

.form-modal[hidden] {
  display: none;
}

.form-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.form-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 22, 0.72);
  backdrop-filter: blur(10px);
}

.form-modal-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 18px;
  width: min(1040px, 100%);
  max-height: min(780px, calc(100vh - 48px));
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 16, 32, 0.98);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45);
}

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

.form-modal-head h3 {
  margin: 0;
  font-size: 22px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.72);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.form-modal .module-form,
.form-modal .ledger-form,
.form-modal .settings-form {
  margin: 0;
}

.submit-button,
.cancel-button,
.row-action {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(104, 247, 199, 0.28);
  border-radius: 999px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}

.submit-button {
  color: #06201a;
  background: var(--mint);
}

.cancel-button,
.row-action {
  color: var(--mint);
  background: rgba(20, 83, 75, 0.32);
}

.row-action {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.danger-action {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.28);
  background: rgba(127, 29, 29, 0.28);
}

.ledger-table {
  display: grid;
  min-width: 940px;
}

.ledger-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.9fr 1fr 1fr 1fr 0.7fr;
  gap: 14px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid var(--line-soft);
  color: #cbd5e1;
}

.ledger-row:last-child {
  border-bottom: 0;
}

.ledger-row strong {
  color: var(--text);
}

.amount-out {
  color: var(--warn);
  font-weight: 800;
}

.amount-in {
  color: var(--mint);
  font-weight: 800;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.report-grid div {
  min-height: 96px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(7, 12, 22, 0.5);
}

.report-grid span {
  display: block;
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
}

.report-grid strong {
  display: block;
  margin-top: 12px;
  font-family: "Space Grotesk", "Noto Sans TC", sans-serif;
  font-size: 28px;
}

.report-export {
  justify-self: start;
}

.backup-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.file-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  padding: 0 16px;
  overflow: hidden;
  border: 1px solid rgba(104, 247, 199, 0.28);
  border-radius: 999px;
  color: var(--mint);
  background: rgba(20, 83, 75, 0.32);
  font-weight: 900;
  cursor: pointer;
}

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

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .metric-grid,
  .content-grid,
  .ledger-panel {
    width: calc(100% - 40px);
  }

  .metric-grid,
  .content-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid .large {
    grid-column: span 2;
  }
}

@media (max-width: 820px) {
  .shell {
    display: block;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .brand-card {
    min-height: 0;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 10px;
  }

  .nav-group {
    grid-column: 1 / -1;
    margin-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .content-grid,
  .content-grid .large {
    grid-template-columns: 1fr;
    grid-column: auto;
  }

  .table-row {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 14px 0;
  }

  .ledger-head,
  .ledger-summary {
    grid-template-columns: 1fr;
  }

  .ledger-form {
    grid-template-columns: 1fr;
  }

  .module-form,
  .settings-form,
  .settings-row,
  .module-row,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }

  .ledger-head {
    align-items: flex-start;
    flex-direction: column;
  }

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