:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d9e2ec;
  --blue: #1f4e79;
  --blue-2: #305496;
  --green: #0f766e;
  --red: #b42318;
  --amber: #a16207;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

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

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

.shell {
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
}

.topbar {
  align-items: center;
  background: var(--blue);
  color: #fff;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 22px;
  max-width: 100%;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.userbar {
  align-items: center;
  display: flex;
  gap: 12px;
}

.page {
  margin: 0 auto;
  max-width: 1440px;
  overflow-x: hidden;
  padding: 20px;
  width: 100%;
}

.login {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-panel,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.login-panel {
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

.panel {
  margin-bottom: 18px;
  overflow: hidden;
  max-width: 100%;
}

.panel-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
}

.panel-body {
  padding: 16px;
}

.grid {
  display: grid;
  gap: 14px;
  max-width: 100%;
}

.grid > * {
  min-width: 0;
}

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

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

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

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

.stat .label {
  color: var(--muted);
  font-size: 12px;
}

.stat .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
}

label {
  color: #374151;
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

input,
select,
textarea {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

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

.form-row {
  margin-bottom: 12px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 6px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 100%;
}

.company-actions {
  margin-bottom: 12px;
}

.company-search {
  align-items: stretch;
}

.company-search input {
  max-width: 520px;
}

button {
  background: var(--blue-2);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 8px 14px;
}

button.secondary {
  background: #475569;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  max-width: 100%;
}

.tabs button {
  background: #e2e8f0;
  color: #1e293b;
}

.tabs button.active {
  background: var(--blue-2);
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #e8eef5;
  color: #1f3a5f;
  font-weight: 700;
  white-space: nowrap;
}

tr:nth-child(even) td {
  background: #fbfdff;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #eaf2ff;
}

.detail-panel {
  background: #ffffff;
  border: 1px solid #bdd7ee;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  margin-bottom: 18px;
  overflow: hidden;
  max-width: 100%;
}

.detail-header {
  align-items: center;
  background: #f0f7ff;
  border-bottom: 1px solid #bdd7ee;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px 16px;
  max-width: 100%;
}

.detail-title {
  color: var(--blue);
  font-size: 17px;
  font-weight: 700;
}

.detail-grid {
  display: grid;
  gap: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 8px 16px 16px;
}

.detail-item {
  border-bottom: 1px solid #e5edf5;
  min-height: 54px;
  padding: 10px 12px;
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
}

.detail-value {
  overflow-wrap: anywhere;
}

.detail-related {
  border-top: 1px solid #e5edf5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 16px;
  max-width: 100%;
}

.detail-section {
  border-top: 1px solid #e5edf5;
  padding: 14px 16px 16px;
}

.detail-section-title {
  color: var(--blue);
  font-weight: 700;
  margin-bottom: 10px;
}

.table-wrap.compact table {
  min-width: 720px;
}

.table-wrap.compact th,
.table-wrap.compact td {
  padding: 8px 9px;
}

.assignment-panel {
  border-top: 1px solid #e5edf5;
  padding: 14px 16px 16px;
}

.assignment-list {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  max-width: 100%;
}

.check-row {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  gap: 8px;
  margin: 0;
  min-height: 38px;
  padding: 8px 10px;
}

.check-row input {
  min-height: auto;
  padding: 0;
  width: auto;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.badge.bad {
  background: #fee2e2;
  color: #991b1b;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--red);
  font-weight: 700;
  margin-top: 10px;
}

.notice {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e3a8a;
  margin-bottom: 16px;
  padding: 12px;
}

@media (max-width: 900px) {
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-6 {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 900px) {
  html,
  body,
  #app,
  .shell,
  .page {
    max-width: 100vw;
    overflow-x: hidden;
  }

  body {
    font-size: 15px;
  }

  .page {
    padding: 12px;
  }

  .brand {
    font-size: 16px;
  }

  .userbar,
  .panel-header,
  .detail-header,
  .actions,
  .tabs {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs button,
  .actions button,
  .actions input,
  .actions select {
    width: 100%;
  }

  .table-wrap {
    overflow-x: visible;
  }

  table,
  .table-wrap.compact table {
    min-width: 0 !important;
    table-layout: fixed;
    width: 100% !important;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 10px 0;
    overflow: hidden;
  }

  tr:nth-child(even) td {
    background: transparent;
  }

  td {
    border-bottom: 1px solid #eef2f7;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    overflow-wrap: anywhere;
    word-break: break-word;
    padding: 10px 12px;
    white-space: normal;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-weight: 700;
  }

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

  .clickable-row:hover td {
    background: transparent;
  }

  .detail-panel,
  .panel {
    border-radius: 6px;
  }

  .detail-section,
  .assignment-panel,
  .panel-body,
  .detail-grid {
    padding-left: 12px;
    padding-right: 12px;
  }

  .badge,
  button,
  .detail-value,
  .muted {
    overflow-wrap: anywhere;
    white-space: normal;
  }
}

#printHost {
  display: none;
}

@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  body.print-mode > :not(#printHost) {
    display: none !important;
  }

  body.print-mode {
    background: #fff;
  }

  body.print-mode #printHost {
    color: #000;
    display: block;
    font-family: "Microsoft JhengHei", Arial, sans-serif;
  }

  .print-sheet {
    width: 100%;
  }

  .print-title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
  }

  .print-subtitle {
    font-size: 13px;
    margin: 4px 0 12px;
    text-align: center;
  }

  .print-grid {
    display: grid;
    gap: 0;
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 10px;
  }

  .print-grid div,
  .print-table th,
  .print-table td {
    border: 1px solid #000;
    min-height: 32px;
    padding: 6px 8px;
  }

  .print-grid b {
    display: inline-block;
    min-width: 72px;
  }

  .print-table {
    border-collapse: collapse;
    min-width: 0;
    width: 100%;
  }

  .print-table th {
    background: #eee;
    width: 140px;
  }

  .signature-row {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr 1fr;
    margin-top: 22px;
  }

  .signature-row div {
    font-size: 16px;
  }

  .signature-row span {
    border-bottom: 1px solid #000;
    display: inline-block;
    height: 36px;
    width: 70%;
  }
}
