:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d9dee7;
  --line-soft: #e8edf3;
  --brand: #d85d27;
  --brand-dark: #aa4219;
  --accent: #176b68;
  --accent-soft: #e4f4f2;
  --warn: #fff5d6;
  --warn-text: #755800;
  --error: #fee4e2;
  --error-text: #b42318;
  --ok: #dcfae6;
  --ok-text: #067647;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(16px, 4vw, 44px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

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

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

h2 {
  font-size: 18px;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 22px auto 0;
}

.auth-panel,
.query-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(30, 41, 59, 0.08);
}

.auth-panel {
  display: grid;
  gap: 18px;
  max-width: 620px;
  margin: 68px auto 0;
  padding: 24px;
}

.muted {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

label {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.input-row {
  display: flex;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd6e2;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  padding: 0 11px;
}

input,
select {
  height: 40px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

textarea {
  min-height: 104px;
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 104, 0.16);
}

.query-panel {
  padding: 14px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 8px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.mode-tab {
  min-height: 36px;
  border: 1px solid #cfd6e2;
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 0 14px;
}

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

.view-section {
  padding-top: 10px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr) minmax(196px, 1.1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.field {
  display: grid;
  gap: 6px;
}

.limit-controls {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) minmax(88px, 1fr);
  gap: 8px;
}

input:disabled {
  background: #eef2f6;
  color: #98a2b3;
}

.button-group {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 0 14px;
  white-space: nowrap;
}

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

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

.button.secondary {
  background: #ffffff;
  border-color: #cfd6e2;
  color: #344054;
}

.button.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.button.compact {
  min-height: 34px;
  padding: 0 11px;
}

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

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 8px 12px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  padding: 0 12px;
}

.message {
  display: none;
  margin: 0 8px 12px;
  border-radius: 8px;
  border: 1px solid #f0d999;
  background: var(--warn);
  color: var(--warn-text);
  font-size: 14px;
  line-height: 1.55;
  padding: 12px 14px;
}

.message.visible {
  display: block;
}

.message.error {
  border-color: #fecdca;
  background: var(--error);
  color: var(--error-text);
}

.message.ok {
  border-color: #abefc6;
  background: var(--ok);
  color: var(--ok-text);
}

.notice {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.entry-form {
  padding: 8px;
}

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

.span-2 {
  grid-column: 1 / -1;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

legend {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
}

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

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid #cfd6e2;
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  padding: 0 10px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px;
}

.import-layout {
  display: grid;
  gap: 12px;
  padding: 8px;
}

.import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.compact-header {
  padding-top: 8px;
}

.preview-wrap {
  max-height: 340px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 260px);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #ffffff;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f3f7;
}

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

th {
  color: #475467;
  font-weight: 800;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: #fafbfc;
}

tbody tr:hover {
  background: #fff7ed;
}

.letter-no {
  color: var(--brand-dark);
  font-weight: 800;
  white-space: nowrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  min-height: 22px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #175cd3;
  font-size: 12px;
  font-weight: 700;
  padding: 0 8px;
}

.signed {
  background: var(--ok);
  color: var(--ok-text);
}

.pending {
  background: #f2f4f7;
  color: #667085;
}

.clip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.footer {
  color: #98a2b3;
  font-size: 12px;
  padding: 24px 16px 30px;
  text-align: center;
}

@media (max-width: 980px) {
  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .search-field,
  .button-group,
  .span-2 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .app-header,
  .session-bar,
  .input-row,
  .button-group,
  .form-actions,
  .import-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .form-grid,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .limit-field,
  .search-field,
  .button-group,
  .span-2 {
    grid-column: auto;
  }

  .limit-controls {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: calc(100% - 20px);
    margin-top: 12px;
  }

  .auth-panel {
    margin-top: 24px;
    padding: 18px;
  }

  .button {
    width: 100%;
  }
}
