* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #1a1a1a;
  color: #fff;
}

#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Tab 导航 */
.tabs {
  display: flex;
  align-items: center;
  background: #222;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.settings-icon {
  padding: 8px 10px;
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.settings-icon:active {
  color: #4ecca3;
}


/* 设置面板 */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.settings-overlay.open {
  display: flex;
}

.settings-panel {
  width: 100%;
  max-width: 500px;
  background: #222;
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #333;
  font-size: 17px;
  font-weight: 500;
  color: #fff;
}

.settings-close {
  background: none;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.settings-body {
  padding: 8px 0;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
}

.setting-label {
  font-size: 15px;
  color: #ccc;
}

.setting-value-text {
  font-size: 13px;
  color: #666;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 28px;
  cursor: pointer;
  transition: background 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider {
  background: #4ecca3;
}

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

.tab {
  flex: 1;
  padding: 12px 0;
  background: none;
  border: none;
  color: #888;
  font-size: 15px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.tab.active {
  color: #4ecca3;
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #4ecca3;
  border-radius: 1px;
}

.tab:disabled {
  color: #555;
  cursor: not-allowed;
}

/* Tab 内容 */
.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
}

#tab-calculator {
  background: linear-gradient(to top, #e0e0e0 env(safe-area-inset-bottom), #1a1a1a env(safe-area-inset-bottom));
}

/* 显示区域 */
.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px 20px;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 0;
}

.history-item {
  text-align: right;
  font-size: 16px;
  color: #aaa;
  padding: 3px 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.result-part {
  white-space: nowrap;
}

/* 历史操作 */
.history-toggle {
  position: absolute;
  left: 8px;
  bottom: 60px;
  background: none;
  border: none;
  color: #555;
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: transform 0.3s;
  z-index: 1;
}

.history-toggle.expanded {
  transform: rotate(180deg);
}

.history-actions {
  display: none;
  flex-shrink: 0;
  gap: 1px;
}

.history-actions.open {
  display: flex;
}

.history-action-btn {
  flex: 1;
  padding: 14px 0;
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.history-action-btn.save {
  background: #4ecca3;
  color: #1a1a1a;
}

.history-action-btn.clear {
  background: #e0e0e0;
  color: #1a1a1a;
}

.current-expr {
  text-align: right;
  font-size: 18px;
  color: #999;
  min-height: 24px;
  margin-top: 8px;
}

.current-value {
  text-align: right;
  font-size: 48px;
  font-weight: 300;
  color: #fff;
  margin-top: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  direction: rtl;
  scrollbar-width: none;
}

.current-value::-webkit-scrollbar {
  display: none;
}

.current-value span {
  direction: ltr;
  display: inline-block;
}

/* 键盘区域 */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 1px;
  background: #333;
  flex-shrink: 0;
  height: 45%;
  min-height: 280px;
  max-height: 400px;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  border: none;
  cursor: pointer;
}

.key.num.pressing {
  background: #bbb;
}

.key.op.pressing {
  background: #3ab88a;
}

.key.num {
  background: #e0e0e0;
  color: #1a1a1a;
}

.key.op {
  background: #4ecca3;
  color: #1a1a1a;
  font-weight: 500;
}

.key.wide {
  grid-column: span 2;
}

.key.tall {
  grid-row: span 2;
}

/* ===== 过账/税率页面 ===== */
.tax-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.tax-form {
  padding: 12px 16px 4px;
}

.tax-field {
  margin-bottom: 12px;
}

.tax-label {
  display: block;
  font-size: 13px;
  color: #888;
  margin-bottom: 8px;
}

/* 类型切换 */
.tax-toggle {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #444;
}

.toggle-btn {
  flex: 1;
  padding: 10px 0;
  background: #2a2a2a;
  border: none;
  color: #999;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: #4ecca3;
  color: #1a1a1a;
  font-weight: 500;
}

/* 金额输入 */
.tax-input {
  width: 100%;
  padding: 12px 14px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  outline: none;
  -webkit-appearance: none;
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  background: #1a1a1a;
  border: 2px solid #333;
  border-radius: 12px;
  padding: 4px 16px;
  transition: border-color 0.2s;
}

.amount-input-wrap:focus-within {
  border-color: #4ecca3;
}

.amount-prefix {
  font-size: 28px;
  font-weight: 300;
  color: #4ecca3;
  margin-right: 4px;
  flex-shrink: 0;
}

.amount-input {
  border: none !important;
  background: transparent !important;
  padding: 10px 0 !important;
  font-size: 32px !important;
  font-weight: 500;
  letter-spacing: 1px;
}

.amount-input::placeholder {
  color: #444;
  font-weight: 300;
}

.tax-input:focus {
  border-color: #4ecca3;
}

.tax-input::placeholder {
  color: #555;
}

/* 选项按钮组 */
.tax-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-btn {
  flex: 1;
  min-width: 0;
  padding: 10px 4px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  color: #ccc;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.option-btn .option-desc {
  font-size: 10px;
  color: #666;
  display: block;
}

.option-btn.active {
  border-color: #4ecca3;
  background: rgba(78, 204, 163, 0.15);
  color: #4ecca3;
}

.option-btn.active .option-desc {
  color: rgba(78, 204, 163, 0.6);
}

/* 结果区域 */
.tax-result {
  margin: 0 16px;
  padding: 16px;
  background: #252525;
  border-radius: 12px;
  border: 1px solid #333;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.result-row + .result-row {
  border-top: 1px solid #333;
}

.result-row .result-label {
  font-size: 14px;
  color: #888;
}

.result-row .result-value {
  font-size: 22px;
  font-weight: 500;
  color: #fff;
}

.result-row.result-detail .result-value {
  font-size: 14px;
  color: #999;
}

/* 生成话术 */
.gen-script-btn {
  display: block;
  width: calc(100% - 32px);
  margin: 16px 16px 0;
  padding: 14px;
  background: #4ecca3;
  color: #1a1a1a;
  border: none;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.gen-script-btn:active {
  filter: brightness(0.85);
}

.script-box {
  margin: 12px 16px 16px;
  padding: 14px;
  background: #252525;
  border: 1px solid #333;
  border-radius: 12px;
}

.script-text {
  font-size: 14px;
  color: #ccc;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  background: #333;
  color: #4ecca3;
  border: 1px solid #444;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.copy-btn:active {
  filter: brightness(0.85);
}

/* Toast */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 15px;
  z-index: 999;
  pointer-events: none;
  animation: toastFade 1.5s ease forwards;
}

@keyframes toastFade {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== 汇率页面 ===== */
.exchange-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.exchange-status {
  text-align: center;
  font-size: 12px;
  color: #666;
  margin-bottom: 16px;
}

.exchange-card {
  background: #252525;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #333;
}

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

.currency-btn {
  min-width: 90px;
  padding: 10px 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  flex-shrink: 0;
}

.currency-btn.active {
  border-color: #4ecca3;
}

.exchange-input {
  flex: 1;
  padding: 10px 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  font-weight: 500;
  outline: none;
  text-align: right;
  -webkit-appearance: none;
  min-width: 0;
}

.exchange-input:focus {
  border-color: #4ecca3;
}

.exchange-input::placeholder {
  color: #555;
}

.exchange-input[readonly] {
  color: #4ecca3;
  border-color: #333;
}

.exchange-swap {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

.swap-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #333;
  border: 1px solid #444;
  color: #4ecca3;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.swap-btn:active {
  filter: brightness(0.8);
}

/* 货币选择面板 */
.currency-picker {
  margin-top: 12px;
  background: #252525;
  border-radius: 12px;
  border: 1px solid #333;
  overflow: hidden;
}

.currency-option {
  display: block;
  width: 100%;
  padding: 14px 16px;
  background: none;
  border: none;
  color: #ccc;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.currency-option + .currency-option {
  border-top: 1px solid #333;
}

.currency-option:active {
  background: #333;
}

/* 汇率表 */
.rate-table {
  margin-top: 16px;
}

.rate-table-title {
  font-size: 13px;
  color: #888;
  margin-bottom: 8px;
}

.rate-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 14px;
  color: #aaa;
  border-bottom: 1px solid #2a2a2a;
}

.rate-item-value {
  color: #fff;
  font-weight: 500;
}

/* 滚动条 */
.history::-webkit-scrollbar {
  width: 0;
}

.tax-page::-webkit-scrollbar {
  width: 0;
}

.exchange-page::-webkit-scrollbar {
  width: 0;
}
