:root {
  --bg: #f3f8fd;
  --panel: #ffffff;
  --line: #d8e6f4;
  --line-strong: #b8cee4;
  --text: #17324b;
  --muted: #5c7289;
  --primary: #1d6fdc;
  --primary-deep: #0f4f9f;
  --primary-soft: #e9f2ff;
  --shadow: 0 10px 30px rgba(21, 48, 75, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

#app { min-height: 100vh; }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(29, 111, 220, 0.06), rgba(29, 111, 220, 0)),
    linear-gradient(135deg, #f8fbff 0%, #eef5fb 100%);
}

.auth-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--primary), #57a4ff);
  color: #fff;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.15;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab,
.navtab,
.primary-btn,
.secondary-btn,
.ghost-btn,
.mini-btn,
.chip-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 10px;
  transition: 0.15s ease;
}

.primary-btn svg,
.secondary-btn svg,
.ghost-btn svg,
.mini-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.tab,
.navtab {
  padding: 12px 14px;
  font-weight: 600;
}

.tab.active,
.navtab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.auth-form,
.content {
  display: grid;
  gap: 14px;
}

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

.field label {
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 12px;
  color: var(--text);
}

.combo-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.combo-field input {
  border: 0;
  border-radius: 0;
  min-height: 44px;
}

.combo-select {
  width: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  background: #f3f8ff;
  color: var(--primary);
  border-radius: 0;
  padding: 0 24px 0 10px;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.combo-field:focus-within {
  outline: 2px solid rgba(29, 111, 220, 0.12);
  border-color: var(--primary);
}

.combo-field input:focus,
.combo-select:focus {
  outline: none;
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(29, 111, 220, 0.12);
  border-color: var(--primary);
}

.remember-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  user-select: none;
}

.remember-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.primary-btn,
.secondary-btn {
  min-height: 46px;
  padding: 12px 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  text-align: center;
}

.primary-btn {
  background: linear-gradient(180deg, #2a7df0, var(--primary));
  color: #fff;
  border-color: var(--primary);
}

.secondary-btn {
  background: #fff;
}

.ghost-btn,
.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  line-height: 1;
}

.ghost-btn {
  background: #fff;
}

.mini-btn {
  width: 40px;
  height: 40px;
  padding: 0;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(243, 248, 253, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.title {
  font-size: 18px;
  font-weight: 800;
}

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

.userchip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  color: var(--muted);
}

.navtabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 14px 0;
  position: sticky;
  top: 65px;
  z-index: 18;
  background: rgba(243, 248, 253, 0.94);
  backdrop-filter: blur(10px);
}

.navtab {
  white-space: nowrap;
}

.content {
  padding: 14px;
}

.notice {
  display: none;
  border: 1px solid rgba(29, 111, 220, 0.18);
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-radius: var(--radius);
  padding: 12px 14px;
  line-height: 1.5;
}

.notice.show { display: block; }

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.panel h2,
.panel h3 {
  margin: 0;
  font-size: 17px;
}

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

.panel-head.compact h3 {
  font-size: 15px;
}

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

.grid {
  display: grid;
  gap: 12px;
}

.cols-1 { grid-template-columns: minmax(0, 1fr); }

.repeat-list {
  display: grid;
  gap: 12px;
}

.repeat-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fcff;
  padding: 12px;
}

.repeat-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.repeat-row.chemical-row {
  grid-template-columns: 32px minmax(0, 1.1fr) minmax(0, 0.65fr) minmax(0, 0.75fr) minmax(0, 1fr) auto;
  align-items: stretch;
}

.repeat-row.chemical-row .field input,
.repeat-row.chemical-row .field select {
  width: 100%;
  min-height: 46px;
}

.repeat-row.chemical-row .field {
  min-width: 0;
}

.repeat-index {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #eaf2ff;
  color: var(--primary-deep);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

.grow { min-width: 0; }

.time-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fcff;
}

.time-card-head {
  display: grid;
  gap: 4px;
}

.time-card-title {
  font-weight: 700;
  color: var(--text);
}

.time-actions {
  display: grid;
  gap: 8px;
}

.time-modal {
  width: min(760px, 100%);
}

.map-modal {
  width: min(760px, 100%);
}

.map-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: end;
}

.map-stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #e9f2ff;
  min-height: 320px;
}

.map-canvas {
  width: 100%;
  height: 320px;
}

.map-center-pin {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -100%);
  color: var(--primary);
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(21, 48, 75, 0.2));
}

.map-center-pin svg {
  width: 34px;
  height: 34px;
}

.map-meta {
  display: grid;
  gap: 6px;
}

.map-results {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
}

.result-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.result-title {
  font-weight: 700;
  color: var(--text);
}

.result-sub {
  color: var(--muted);
  font-size: 12px;
}

.time-list {
  display: grid;
  gap: 10px;
  max-height: min(58vh, 520px);
  overflow: auto;
  padding-right: 2px;
}

.time-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fcff;
}

.time-label {
  font-weight: 700;
  color: var(--primary-deep);
  padding-bottom: 12px;
}

.muted,
.meta-line,
.record-meta {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  background: #f9fcff;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-top: 8px;
}

.list {
  display: grid;
  gap: 12px;
}

.record {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.record-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.record-title {
  font-weight: 700;
  font-size: 15px;
}

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

.modal {
  display: none;
  position: fixed;
  inset: 0;
  padding: 18px;
  background: rgba(8, 22, 39, 0.34);
  z-index: 50;
  place-items: center;
}

.modal.show {
  display: grid;
}

.share-modal {
  z-index: 60;
}

.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.preview-card {
  width: min(920px, 100%);
  max-height: min(90vh, 980px);
}

.preview-scroll {
  max-height: min(66vh, 720px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preview-scroll .wrap {
  padding: 0;
}

.quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  padding: 10px 12px;
  background: #f7fbff;
}

.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (min-width: 900px) {
  .content {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
  }

  .cols-1 {
    gap: 14px;
  }

  .form-actions {
    grid-template-columns: 160px 1fr;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-inline: 12px;
  }

  .navtabs {
    padding-inline: 12px;
  }

  .content {
    padding: 12px;
  }

  .repeat-row {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .repeat-row.chemical-row {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .repeat-row .mini-btn {
    grid-column: 2 / -1;
    justify-self: end;
  }

  .repeat-row.chemical-row .field {
    grid-column: 2 / -1;
  }

  .repeat-row.chemical-row .field:nth-of-type(2),
  .repeat-row.chemical-row .field:nth-of-type(3),
  .repeat-row.chemical-row .field:nth-of-type(4),
  .repeat-row.chemical-row .mini-btn {
    grid-column: 2 / -1;
  }

  .time-row {
    grid-template-columns: 1fr;
  }

  .time-label {
    padding-bottom: 0;
  }

  .map-search {
    grid-template-columns: 1fr;
  }

  .map-canvas {
    height: 280px;
  }

  .record-head {
    flex-direction: column;
  }

  .form-actions {
    grid-template-columns: 1fr 1fr;
  }
}
