:root {
  color-scheme: light;
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --ink: #17212b;
  --muted: #687582;
  --line: #d9e2ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d8f3ee;
  --warn: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(21, 34, 47, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

body.locked {
  overflow: hidden;
}

body.locked .sidebar,
body.locked .workspace {
  filter: blur(3px);
  pointer-events: none;
  user-select: none;
}

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

button {
  cursor: pointer;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(238, 243, 247, 0.9);
}

body.authenticated .login-screen {
  display: none;
}

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

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

.login-brand p {
  color: var(--muted);
}

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

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

.sidebar {
  min-height: 100vh;
  padding: 28px 20px;
  background: #10202c;
  color: #f5fbff;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d7f5ee;
  color: #10202c;
  font-weight: 800;
  font-size: 24px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel-heading h3,
.panel-heading p,
.table-heading h3,
.table-heading p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  color: #bdd0dc;
  margin-top: 4px;
  font-size: 14px;
}

.category-tabs {
  display: grid;
  gap: 10px;
}

.side-menu {
  gap: 4px;
}

.tab-button {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border-radius: 8px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
}

.menu-parent {
  margin-bottom: 4px;
}

.submenu {
  display: grid;
  gap: 2px;
  padding: 0 0 4px 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  margin-left: 8px;
}

.submenu-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: #d7e4ed;
  text-align: left;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.submenu-button strong {
  min-width: 24px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 12px;
  text-align: center;
}

.submenu-button:hover,
.submenu-button.active {
  background: rgba(255, 255, 255, 0.1);
  color: #f8c537;
}

.workspace {
  min-width: 0;
  padding: 28px;
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
}

.topbar,
.panel-heading,
.table-heading {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  gap: 18px;
}

.table-pagination-tools {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  justify-self: center;
}

.topbar h2 {
  font-size: 34px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 10px;
  flex-wrap: wrap;
}

.page-size-controls,
.pagination-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.pagination-controls {
  margin-inline: 0;
}

.page-size-controls span,
.pagination-controls span {
  color: var(--muted);
  font-weight: 700;
}

.page-nav-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent-dark);
  padding: 6px 10px;
  font-weight: 700;
}

.page-size-controls select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 28px 6px 10px;
  font-weight: 700;
}

.page-numbers {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.page-number-button {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-dark);
  padding: 6px 8px;
  font-weight: 700;
}

.page-number-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.page-ellipsis {
  min-width: 24px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.page-nav-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.notice-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  background: #e5e7eb;
  color: #111827;
  padding: 3px 8px;
  font-weight: 700;
  white-space: nowrap;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 3px 8px;
  font-weight: 700;
  white-space: nowrap;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  display: none;
}

.inline-date-input {
  width: 150px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

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

.risk-summary-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
  white-space: nowrap;
}

.risk-summary-line span:last-child {
  min-width: 120px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 3px 8px;
  font-weight: 800;
}

.status-badge.expired {
  background: #e5e7eb;
  color: #111827;
}

.status-badge.underwriting {
  background: #ffedd5;
  color: #9a3412;
}

.status-badge.issued {
  background: #dcfce7;
  color: #166534;
}

.status-badge.stopped {
  background: #7f1d1d;
  color: #ffffff;
}

.status-badge.default {
  background: #e0f2fe;
  color: #075985;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  min-height: 42px;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.readonly-field {
  background: #f4f7f9;
  color: #4b5b68;
  cursor: default;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-field input {
  width: min(38vw, 360px);
}

#card-month-filter-wrap {
  grid-template-columns: auto 150px 150px 150px;
  align-items: center;
}

#card-month-filter-wrap span {
  grid-column: 1 / -1;
}

#card-month-filter-wrap input,
#card-month-filter-wrap select {
  width: 100%;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 700;
}

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

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: var(--surface);
  color: var(--accent-dark);
  border-color: var(--line);
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 100px);
  gap: 8px;
  align-items: start;
  justify-content: start;
}

.summary-grid[hidden] {
  display: none;
}

.summary-card[hidden] {
  display: none;
}

.summary-card,
.entry-panel,
.table-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-card {
  width: 100px;
  height: 100px;
  min-height: 100px;
  padding: 8px;
  display: grid;
  place-items: center;
  gap: 4px;
  text-align: center;
  box-shadow: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.summary-card:hover,
.summary-card.active {
  border-color: var(--accent);
  background: #ecfdf5;
}

.summary-grid span {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.15;
}

.summary-grid strong {
  font-size: 20px;
  line-height: 1;
}

.entry-panel,
.table-section {
  padding: 20px;
}

body.form-modal-open::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 24;
  background: rgba(0, 0, 0, 0.68);
}

.entry-panel.form-modal-panel {
  position: fixed;
  inset: 28px auto auto 50%;
  z-index: 25;
  width: min(1040px, calc(100vw - 64px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  transform: translateX(-50%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field.row-start {
  grid-column-start: 1;
}

.form-field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field.checkbox {
  align-content: end;
}

.form-field.checkbox label {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--surface-soft);
}

.form-field.checkbox input {
  min-height: auto;
  width: 18px;
  height: 18px;
}

.form-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.match-results {
  display: grid;
  gap: 8px;
}

.match-option {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
}

.match-option:hover {
  border-color: var(--accent);
  background: #eefaf6;
}

.match-option span,
.match-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.table-checkbox {
  width: 18px;
  height: 18px;
  min-height: auto;
}

.check-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: #ecfdf5;
  color: #047857;
  font-size: 18px;
  font-weight: 800;
}

.checkbox-field label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  min-height: auto;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: start center;
  padding: 42px 24px;
  background: rgba(0, 0, 0, 0.72);
  overflow: auto;
}

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

.detail-modal {
  width: min(1280px, 100%);
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 84px);
  min-height: min(760px, calc(100vh - 84px));
  border: 1px solid #b8c2cc;
  background: #f7f8f8;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
}

.import-modal {
  width: min(1280px, calc(100vw - 48px));
}

.detail-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  flex: 0 0 auto;
}

.detail-modal-header h3 {
  margin: 0;
  font-size: 20px;
}

.import-mapping {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
  gap: 16px;
  margin-top: 18px;
  min-width: 0;
}

.import-mode-wrap {
  margin-bottom: 14px;
}

.import-mode-wrap label {
  display: grid;
  gap: 6px;
  max-width: 320px;
  font-size: 13px;
  color: var(--muted);
}

.import-mode-wrap select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 0 10px;
}

.import-mapping h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.mapping-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mapping-zones {
  min-width: 0;
}

.mapping-chip {
  border: 1px solid #c9d6e2;
  border-radius: 6px;
  background: #ffffff;
  color: #0f172a;
  padding: 8px 10px;
  cursor: grab;
  user-select: none;
}

.mapping-chip:active {
  cursor: grabbing;
}

.mapping-zone {
  min-width: 138px;
  height: 58px;
  border: 1px dashed #a9bac9;
  border-radius: 6px;
  background: #f8fafc;
  padding: 6px 8px;
  vertical-align: top;
}

.mapping-zone.filled {
  border-style: solid;
  background: #eef9f6;
}

.mapping-zone-label {
  font-weight: 700;
  color: #475569;
}

.mapping-zone-value {
  display: block;
  margin-top: 4px;
  color: #0f172a;
}

.mapping-clear {
  display: block;
  margin-top: 4px;
  border: 0;
  background: transparent;
  color: #b91c1c;
  cursor: pointer;
  font-size: 13px;
}

.mapping-empty {
  margin: 0;
  color: #64748b;
}

.import-preview-wrap {
  max-width: 100%;
  max-height: calc(100vh - 280px);
  overflow: auto;
  border: 1px solid #d6e0ea;
  border-radius: 6px;
  background: #ffffff;
}

.import-preview-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.import-preview-table th,
.import-preview-table td {
  border: 1px solid #cfd8e3;
  padding: 8px 10px;
  white-space: nowrap;
  text-align: left;
}

.import-preview-table td {
  background: #ffffff;
}

.import-row-marker {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f1f5f9;
  color: #334155;
}

.import-preview-table thead .import-row-marker {
  z-index: 2;
}

.import-start-row td,
.import-start-row th {
  background: #fff7e6;
}

.select-column {
  width: 88px;
  text-align: center;
}

.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #5d6670;
  font-size: 30px;
  line-height: 1;
}

.detail-body {
  display: grid;
  gap: 14px;
  padding: 16px;
  min-width: 0;
  overflow: auto;
  flex: 1 1 auto;
}

.detail-section {
  border: 1px solid #d7dde3;
  background: #fffdf0;
  padding: 14px;
  min-width: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.detail-item {
  display: grid;
  gap: 5px;
}

.detail-item.row-start {
  grid-column-start: 1;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.detail-label {
  color: #4f5b66;
  font-size: 13px;
  font-weight: 700;
}

.detail-value {
  min-height: 34px;
  border-radius: 4px;
  background: #e5e7e9;
  padding: 8px 10px;
  white-space: pre-wrap;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  flex: 0 0 auto;
}

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

.detail-subtitle {
  margin: 0 0 12px;
  font-size: 16px;
}

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

.nested-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px dashed #b7bdc4;
  background: #fff;
  padding: 10px;
}

.nested-item > div:first-child {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.table-wrap {
  margin-top: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  white-space: nowrap;
}

td.status-cell {
  min-width: 280px;
  max-width: 380px;
  white-space: pre-wrap;
  line-height: 1.5;
}

th {
  background: var(--surface-soft);
  color: #41515e;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:hover {
  background: #f2fbf8;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.pill.yes {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.pill.no {
  background: #fff4df;
  color: var(--warn);
}

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

.icon-button {
  min-height: 34px;
  padding: 6px 10px;
  background: #f2f6f9;
  color: #263847;
  border-color: var(--line);
}

.icon-button.delete {
  color: var(--danger);
}

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

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  .category-tabs,
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 720px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .table-heading {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .table-pagination-tools,
  .table-actions {
    justify-content: flex-start;
    justify-self: stretch;
  }

  .toolbar,
  .toolbar > *,
  .search-field input,
  .search-field select,
  .summary-grid,
  .category-tabs,
  .form-grid {
    width: 100%;
  }

  .summary-grid,
  .category-tabs,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
