:root {
  color-scheme: light;
  --primary: #1769e0;
  --primary-dark: #0f56bd;
  --primary-soft: #eaf2ff;
  --danger: #d92d20;
  --line: #d8e0ea;
  --line-strong: #c8d3df;
  --muted: #667085;
  --text: #1f2937;
  --panel: #ffffff;
  --page: #ffffff;
  --field: #fbfcfe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

.shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.app-loading .shell {
  visibility: hidden;
}

.topbar {
  display: flex;
  align-items: center;
}

.brand-logo {
  display: block;
  width: 34px;
  height: 28px;
  object-fit: contain;
  opacity: 0.92;
}

.brand-mark {
  display: grid;
  place-items: center;
  min-width: 50px;
  min-height: 38px;
  padding: 0 9px;
  border-right: 1px solid var(--line);
}

.toolbar {
  display: inline-flex;
  gap: 4px;
  width: auto;
  max-width: 100%;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6fa;
}

.tab {
  min-height: 38px;
  min-width: 112px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 16px;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
}

.tab.active {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(23, 105, 224, 0.18);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 14px 34px rgba(31, 41, 55, 0.08);
}

.calculator-panel {
  margin-top: 16px;
}

.history-panel {
  margin-top: 16px;
}

.form {
  display: grid;
  gap: 20px;
}

.hidden {
  display: none;
}

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

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
}

label span {
  color: #263445;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--field);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input,
select {
  min-height: 46px;
}

textarea {
  resize: vertical;
  overflow: hidden;
  line-height: 1.55;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--line-strong);
  background: #fff;
}

input:focus,
textarea:focus,
select:focus {
  outline: 0;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.14);
}

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

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

.result-row div {
  display: grid;
  gap: 7px;
  min-height: 86px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faff;
}

.result-row span {
  color: var(--muted);
  font-size: 13px;
}

.result-row strong {
  color: var(--primary);
  font-size: 24px;
  line-height: 1.15;
}

.primary {
  justify-self: end;
  min-width: 132px;
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(23, 105, 224, 0.24);
  transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 12px 26px rgba(15, 86, 189, 0.26);
  transform: translateY(-1px);
}

.primary:active {
  transform: translateY(0);
  box-shadow: 0 6px 16px rgba(15, 86, 189, 0.22);
}

.ghost {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.ghost:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.formula-box {
  padding: 15px;
  border: 1px solid #f0d58a;
  border-radius: 8px;
  background: #fff4cf;
  color: #344054;
  line-height: 1.7;
}

.formula-box p {
  margin: 6px 0 0;
}

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

.history-head h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.site-footer {
  padding: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.records {
  display: grid;
  gap: 10px;
}

.records.empty {
  display: block;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.record {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.record:hover {
  border-color: var(--primary);
  background: #f8fbff;
  box-shadow: 0 8px 20px rgba(31, 41, 55, 0.06);
}

.record-main {
  display: grid;
  width: 100%;
  gap: 8px;
  border: 0;
  padding: 12px 76px 12px 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.record-title,
.record-result {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.record-title time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.record-title strong {
  color: #172334;
}

.record-detail {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.record-result span {
  color: var(--muted);
}

.record-result b {
  color: var(--primary);
}

.delete-record {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  border: 1px solid rgba(217, 45, 32, 0.3);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.delete-record:hover {
  background: #fff3f0;
  border-color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 18px;
  background: transparent;
  pointer-events: auto;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  position: absolute;
  width: min(270px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);
  pointer-events: auto;
}

.modal::before {
  content: "";
  position: absolute;
  top: -7px;
  right: 28px;
  width: 12px;
  height: 12px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: #fff;
  transform: rotate(45deg);
}

.modal.modal-above::before {
  top: auto;
  bottom: -7px;
  border-top: 0;
  border-left: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.modal.modal-mobile::before {
  display: none;
}

.modal-text {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.password-field {
  display: block;
}

.password-field input {
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
}

.modal-error {
  min-height: 18px;
  margin-top: 6px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.danger-button {
  border: 0;
  border-radius: 8px;
  padding: 8px 11px;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.danger-button:hover {
  background: #b42318;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 980px);
    padding: 12px 0 18px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: max-content repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 2px;
    padding: 3px;
  }

  .tab {
    min-height: 34px;
    min-width: 0;
    padding: 0 2px;
    font-size: 12px;
    white-space: nowrap;
  }

  .topbar {
    align-items: stretch;
  }

  .brand-logo {
    width: auto;
    height: 26px;
    max-width: 30px;
  }

  .brand-mark {
    min-width: 0;
    min-height: 34px;
    padding: 0 4px;
  }

  .modal {
    position: fixed;
  }

  .panel {
    padding: 14px;
    border-radius: 8px;
    box-shadow: 0 8px 18px rgba(31, 41, 55, 0.06);
  }

  .calculator-panel {
    margin-top: 10px;
  }

  .history-panel {
    margin-top: 10px;
  }

  .form {
    gap: 12px;
  }

  .grid {
    gap: 10px;
  }

  label {
    gap: 5px;
    font-size: 13px;
  }

  input,
  textarea,
  select {
    padding: 9px 10px;
    font-size: 15px;
  }

  input,
  select {
    min-height: 40px;
  }

  textarea {
    min-height: 86px;
    overflow: hidden;
  }

  .result-row,
  .result-row-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

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

  label:has(textarea),
  .formula-box {
    grid-column: 1 / -1;
  }

  .result-row div {
    min-height: 70px;
    padding: 11px;
  }

  .result-row strong {
    font-size: 21px;
  }

  .primary {
    width: 100%;
    min-height: 42px;
    padding: 10px 14px;
  }

  .formula-box {
    padding: 11px;
    font-size: 14px;
  }

  .history-head {
    margin-bottom: 10px;
  }

  .history-head h1 {
    font-size: 16px;
  }

  .ghost {
    padding: 7px 10px;
    font-size: 13px;
  }

  .records {
    gap: 8px;
  }

  .record-main {
    padding: 10px 62px 10px 10px;
  }

  .delete-record {
    top: 8px;
    right: 8px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .record-title,
  .record-result {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-result {
    align-items: center;
    flex-direction: row;
    width: 100%;
  }
}

@media (max-width: 380px) {
  .grid,
  .result-row,
  .result-row-wide {
    grid-template-columns: 1fr;
  }
}
