:root {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-strong: #eef4ef;
  --ink: #202421;
  --muted: #65706a;
  --line: #dbe3dd;
  --teal: #0b6b61;
  --teal-dark: #084f48;
  --teal-soft: #d9ece8;
  --rust: #a94c3d;
  --rust-soft: #f3dfdc;
  --amber: #b98218;
  --amber-soft: #f3e6c8;
  --violet: #5c5a95;
  --violet-soft: #e3e2f1;
  --shadow: 0 18px 50px rgba(32, 36, 33, 0.12);
  --radius: 8px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

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

.login-brand {
  color: var(--ink);
  margin-bottom: 4px;
}

.app-shell.locked {
  filter: blur(2px);
  pointer-events: none;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: #24312c;
  color: #f6faf7;
}

.brand-block {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 46px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e5efe8;
  color: var(--teal-dark);
  font-weight: 800;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.brand-subtitle {
  margin-top: 3px;
  color: #bdcbc4;
  font-size: 12px;
  line-height: 1.35;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  height: 42px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #e7f0eb;
  text-align: left;
}

.nav-item:hover,
.nav-item:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.nav-item.active {
  background: #f6faf7;
  color: #1f2a25;
}

.nav-icon {
  display: grid;
  place-items: center;
  color: currentColor;
  font-size: 14px;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.current-user-card {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
}

.current-user-card span {
  color: #bdcbc4;
  font-size: 12px;
}

.sidebar-logout {
  color: #f6faf7;
  border-color: rgba(255, 255, 255, 0.22);
}

.role-label {
  color: #bdcbc4;
  font-size: 12px;
}

.sidebar-footer select {
  width: 100%;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #f6faf7;
  padding: 0 10px;
}

.sidebar-footer option {
  color: var(--ink);
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 7px;
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.3;
}

.topbar-actions,
.dialog-actions,
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.period-control {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
}

.period-control input {
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
}

.primary-button,
.secondary-button,
.ghost-button,
.small-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--teal-dark);
}

.secondary-button {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  background: var(--surface-strong);
  color: var(--teal-dark);
}

.icon-button {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.view {
  display: none;
  padding: 28px;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.view-heading p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.metric-card,
.panel,
.table-wrap,
.export-controls,
.project-card,
.summary-pill {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-card {
  min-height: 116px;
  padding: 16px;
  display: grid;
  gap: 9px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  font-size: 25px;
  font-weight: 800;
  line-height: 1.2;
}

.metric-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--teal);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 16px;
}

.panel {
  padding: 16px;
  min-height: 310px;
}

.panel-header {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.info-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfb;
}

.info-main {
  min-width: 0;
}

.info-title {
  margin-bottom: 4px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.info-subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.amount-strong {
  font-weight: 800;
  text-align: right;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe6;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.progress-fill.warning {
  background: var(--amber);
}

.progress-fill.danger {
  background: var(--rust);
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar input,
.toolbar select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 12px;
}

.toolbar input {
  min-width: min(420px, 100%);
  flex: 1;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf8;
  color: #43504a;
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover {
  background: #fbfcfb;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.number-cell {
  text-align: right;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.tag.ok {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.tag.wait {
  background: var(--amber-soft);
  color: #74500c;
}

.tag.bad {
  background: var(--rust-soft);
  color: #7d3027;
}

.tag.neutral {
  background: var(--violet-soft);
  color: #3f3c73;
}

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

.text-button {
  min-height: 29px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--teal-dark);
  font-weight: 800;
}

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

.summary-pill {
  min-height: 76px;
  padding: 13px;
}

.summary-pill span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}

.summary-pill strong {
  display: block;
  font-size: 21px;
}

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

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

.form-panel {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.form-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.danger-panel {
  border-color: #e5c6c0;
}

.project-card {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.project-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.project-title-row h3 {
  margin-bottom: 5px;
}

.project-title-row p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.project-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.project-stat {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfb;
}

.project-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.project-stat strong {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.export-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
}

.export-controls {
  padding: 16px;
  align-self: start;
  display: grid;
  gap: 14px;
}

.sync-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.sync-panel h3 {
  margin: 0;
}

.sync-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sync-status {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfb;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.sync-status.ok {
  border-color: #b8d7cf;
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.sync-status.bad {
  border-color: #e3b9b2;
  background: var(--rust-soft);
  color: #7d3027;
}

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

label input,
label select,
label textarea,
.export-controls select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

label textarea,
#csvPreview {
  padding: 10px;
  resize: vertical;
}

#csvPreview {
  min-height: 520px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #17201c;
  color: #edf7f1;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.export-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(21, 28, 25, 0.52);
}

.entry-dialog {
  width: min(860px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.compact-dialog {
  width: min(560px, 100%);
}

.dialog-header {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px 20px;
}

.single-column {
  grid-template-columns: 1fr;
}

.wide-field {
  grid-column: 1 / -1;
}

.dialog-actions {
  justify-content: flex-end;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

.inline-actions {
  padding: 0;
  border-top: 0;
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.file-link {
  color: var(--teal-dark);
  font-weight: 800;
  text-decoration: none;
}

.file-link:hover,
.file-link:focus-visible {
  text-decoration: underline;
}

.role-hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: #202421;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1100px) {
  .metric-grid,
  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .project-grid,
  .settings-grid,
  .export-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

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

  .sidebar-footer {
    display: none;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .topbar-actions,
  .toolbar,
  .view-heading {
    width: 100%;
  }

  .view-heading {
    flex-direction: column;
  }

  .view {
    padding: 18px;
  }

  .metric-grid,
  .summary-strip,
  .project-stats,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .period-control,
  .topbar-actions button {
    width: 100%;
    justify-content: center;
  }

  .period-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .modal-backdrop {
    align-items: start;
    padding: 12px;
  }
}
