:root {
  --bg-root: #f7f7f7;
  --surface: #ffffff;
  --primary-text: #000000;
  --muted-text: #666666;
  --border: #e5e5e5;
  --success: #1c7d37;
  --danger: #b42318;
  --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.06);
  --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.2);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(120deg, #ffffff, #f3f3f3);
  color: var(--primary-text);
  font-family: "MiSans", "Noto Sans TC", "PingFang TC", sans-serif;
}

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

main {
  min-height: 100vh;
  padding: 24px;
}

.hidden {
  display: none !important;
}

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

.card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.is-loading {
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.7s linear infinite;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-primary {
  background: #000000;
  color: #ffffff;
}

.btn-primary:hover {
  background: #1a1a1a;
}

.btn-secondary {
  background: #ffffff;
  border-color: #bdbdbd;
}

.btn-secondary:hover {
  border-color: #000000;
}

.btn-ghost {
  background: transparent;
  border-color: #d8d8d8;
}

.btn-ghost:hover {
  background: #f2f2f2;
}

.btn-sm {
  padding: 7px 12px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-only {
  width: 40px;
  height: 40px;
  padding: 0;
}

.login-wrap {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(460px, 100%);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
}

.login-card form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.login-card input {
  width: 100%;
}

.error-text {
  margin: 12px 0 0;
  color: var(--danger);
}

input,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
}

input:focus,
select:focus {
  outline: 2px solid #000000;
  outline-offset: 1px;
}

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  min-height: calc(100vh - 48px);
}

.sidebar {
  border: 1px solid var(--border);
  background: #fcfcfc;
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-head h2 {
  margin: 0 0 4px;
}

.sidebar-head p {
  margin: 0;
}

.page-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.page-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  flex: 1;
}

.nav-item-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.page-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.page-nav-row.active .page-nav-item {
  border-color: #000000;
  background: #f0f0f0;
}

.record-count {
  color: var(--muted-text);
  font-size: 12px;
}

.page-rename-btn {
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.workspace-header {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.page-scope-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.scope-switch {
  gap: 10px;
}

.scope-switch.active {
  background: #111111;
  border-color: #111111;
  color: #ffffff;
}

.scope-switch.active .record-count {
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.breadcrumbs {
  color: var(--muted-text);
  font-size: 13px;
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group.grow {
  min-width: 0;
}

.search-wrap {
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  background: #ffffff;
}

.search-wrap input {
  border: 0;
  outline: 0;
  border-radius: 0;
}

.creation-result {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.creation-result-main h3 {
  margin: 0 0 4px;
}

.creation-result-main p {
  margin: 0;
}

.creation-result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-banner {
  padding: 12px 14px;
  border-color: #f0c36d;
  background: #fff9eb;
  color: #7a5200;
}

.sync-banner strong {
  font-weight: 700;
}

.qr-preview {
  width: 72px;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  background: #ffffff;
}

.table-card {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.table-scroll {
  overflow: auto;
}

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

th,
td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}

thead th {
  font-size: 13px;
  color: var(--muted-text);
  background: #fafafa;
}

tbody tr:hover {
  background: #fafafa;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 100px;
  border: 1px solid var(--border);
  padding: 3px 10px;
  font-size: 12px;
}

.status-badge.published {
  border-color: #96d1a7;
  color: var(--success);
  background: #f3fff6;
}

.status-badge.draft {
  border-color: #d8d8d8;
  color: var(--muted-text);
  background: #fcfcfc;
}

.publish-switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
  cursor: pointer;
}

.publish-switch-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.publish-switch-slider {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #d8d8d8;
  border: 1px solid #cfcfcf;
  transition: background 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.publish-switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease;
}

.publish-switch-input:checked + .publish-switch-slider {
  background: #34c759;
  border-color: #2faa4d;
}

.publish-switch-input:checked + .publish-switch-slider::after {
  transform: translateX(20px);
}

.publish-switch-input:disabled + .publish-switch-slider {
  opacity: 0.6;
}

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

.empty-state {
  padding: 38px 12px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
  color: var(--muted-text);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: min(560px, 100%);
  padding: 18px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-head h3 {
  margin: 0;
}

.modal-form {
  display: grid;
  gap: 11px;
  overflow-y: auto;
  padding-right: 6px;
}

.modal-form label {
  display: grid;
  gap: 6px;
}

.module-fields {
  display: grid;
  gap: 11px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.module-fields-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted-text);
}

.form-status {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
}

.form-status.error {
  border-color: #e8b5ad;
  background: #fff4f1;
  color: var(--danger);
}

.form-status.success {
  border-color: #abd5b7;
  background: #f3fff6;
  color: var(--success);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
  padding-top: 10px;
  position: sticky;
  bottom: 0;
  background: #ffffff;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 110;
}

.toast {
  width: min(340px, calc(100vw - 36px));
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow-strong);
  padding: 12px;
}

.toast.success {
  border-color: #abd5b7;
}

.toast.error {
  border-color: #e8b5ad;
}

.toast p {
  margin: 0;
}

.toast-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.stamp-preview-wrap {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fafafa;
}

.stamp-preview {
  display: block;
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
}

@media (max-width: 980px) {
  main {
    padding: 10px;
  }

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

  .sidebar {
    padding: 12px;
    gap: 12px;
  }

  .page-nav {
    flex-direction: row;
    overflow: auto;
    padding-bottom: 4px;
  }

  .page-nav .btn {
    min-width: 150px;
  }

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

  .toolbar-group {
    flex-wrap: wrap;
  }

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