:root {
  --primary: #007aff;
  --primary-hover: #0056b3;
  --bg: #f2f2f7;
  --card-bg: #ffffff;
  --text: #1c1c1e;
  --text-sub: #8e8e93;
  --border: #e5e5ea;
  --radius: 12px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --cyber-glow: 0 0 10px rgba(0, 122, 255, 0.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  position: relative;
  text-align: center;
  margin-bottom: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* ？ Help 按鈕樣式 */
.help-btn {
  position: absolute;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #e3e3e8;
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.help-btn:active {
  background: var(--primary);
  color: #fff;
}

/* Tab Switching */
.tab-container {
  display: flex;
  background: #e3e3e8;
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Input Areas */
#file-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

#drop-zone {
  border: 2px dashed #c7c7cc;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: var(--card-bg);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}

#drop-zone.hover {
  border-color: var(--primary);
  background: #eef6ff;
}

#drop-zone p {
  margin: 0 0 4px 0;
  font-size: 15px;
  font-weight: 600;
}

#drop-zone small {
  color: var(--text-sub);
  font-size: 12px;
}

#file-input { display: none; }

.enc-submit-btn {
  width: 100%;
  padding: 10px;
  background: #34c759;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: background-color 0.2s ease;
}

.enc-submit-btn:active {
  background: #28a745;
}

#paste-section {
  display: none;
  background: var(--card-bg);
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

#paste-input {
  width: 100%;
  height: 110px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  resize: none;
  outline: none;
  background: #fafafa;
}

#paste-input:focus {
  border-color: var(--primary);
  background: #fff;
}

#file-badge {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-top: 10px;
  margin-bottom: 2px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.file-icon {
  font-size: 13px;
}

#file-name-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Row Settings */
.row-settings {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 8px;
  background: var(--card-bg);
  padding: 10px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.row-setting-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.row-setting-item label {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
  white-space: nowrap;
}

.row-setting-item input {
  width: 100%;
  padding: 6px 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  outline: none;
  font-weight: 600;
  background: #fafafa;
}

#btn-reparse {
  padding: 7px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  height: 33px;
  transition: background-color 0.2s ease;
}

#btn-reparse:active {
  background: var(--primary-hover);
}

/* Viewer Container */
#viewer {
  display: none;
  margin-top: 12px;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.search-box { 
  margin-bottom: 8px;
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

/* 單行分頁 Controls */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 6px 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  gap: 8px;
  flex-shrink: 0;
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: #1c1c1e;
  color: #00f0ff;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.92);
  box-shadow: var(--cyber-glow);
  background: var(--primary);
  color: #fff;
}

.icon-btn:disabled {
  background: #e5e5ea;
  color: #a1a1a6;
  cursor: not-allowed;
  box-shadow: none;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

#page-info {
  font-weight: 700;
  font-size: 14px;
  font-family: monospace;
  letter-spacing: 0.5px;
  color: var(--text);
  white-space: nowrap;
}

.jump-box {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #f2f2f7;
  padding: 2px 2px 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.2s ease;
}

.jump-box:focus-within {
  border-color: var(--primary);
  background: #fff;
}

.jump-box input {
  width: 36px;
  padding: 2px 0;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  outline: none;
  color: var(--text);
}

.jump-box input::-webkit-outer-spin-button,
.jump-box input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
.jump-box input[type=number] {
  -moz-appearance: textfield;
  appearance: none;
}

.jump-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #1c1c1e;
  color: #30d158;
  box-shadow: none;
}

.jump-btn svg {
  width: 13px;
  height: 13px;
}

/* 資料區獨立 Scrollbar */
#form-container {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

#form-container::-webkit-scrollbar {
  width: 6px;
}

#form-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 10px;
}

#form-container::-webkit-scrollbar-thumb {
  background: #c7c7cc;
  border-radius: 10px;
}

#form-container::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.field-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: transform 0.1s ease, border-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-card:active {
  transform: scale(0.98);
  border-color: var(--primary);
  background: #f8fbfd;
}

.field-label {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  width: 35%;
  flex-shrink: 0;
  word-break: break-word;
  margin-bottom: 0;
}

.field-value {
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.3;
  width: 65%;
  text-align: right;
}

.field-value.is-empty {
  color: var(--text-sub);
  opacity: 0.5;
  font-style: italic;
}

/* Modal 彈窗樣式 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--text-sub);
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.modal-body h3 {
  font-size: 14px;
  margin: 16px 0 6px 0;
  color: var(--primary);
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body ul, .modal-body ol {
  margin: 0;
  padding-left: 20px;
}

.modal-body li {
  margin-bottom: 6px;
}

/* Toast Notification */
#toast {
  visibility: hidden;
  min-width: 160px;
  background-color: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(10px);
  color: #fff;
  text-align: center;
  border-radius: 20px;
  padding: 10px 18px;
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 1000;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast.show {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}