:root {
  --bg: #f6f3ed;
  --paper: #fffefb;
  --ink: #1f2328;
  --muted: #70757d;
  --grid: #ff969f;
  --grid-soft: #ffd9dd;
  --line: #e5e1d8;
  --accent: #1f5f56;
  --accent-2: #e9f1ef;
  --danger: #b43a3a;
  --shadow: 0 12px 36px rgba(36, 38, 41, .08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(255,255,255,.85), transparent 35%),
    var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(31,35,40,.92);
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  transition: .2s ease;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(255,254,251,.95);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border: 2px solid var(--grid);
  background-image:
    linear-gradient(var(--grid-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-soft) 1px, transparent 1px);
  background-size: 13px 13px;
  font-weight: 800;
  font-size: 23px;
}
.login-card h1 { margin: 18px 0 8px; font-size: 30px; }
.login-card p { color: var(--muted); line-height: 1.7; margin: 0 0 26px; }
.login-card label span, .field span, .plain-wrap label span {
  display:block; font-size: 13px; color: var(--muted); margin-bottom: 7px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #d8d4ca;
  background: #fff;
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31,95,86,.1);
}
.form-error { min-height: 22px; color: var(--danger); margin-top: 12px; font-size: 14px; }

.btn {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 650;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-2); color: #214c47; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: #fff0f0; color: var(--danger); }
.btn.wide { width:100%; margin-top: 18px; padding: 12px; }

.app-shell { width: min(1180px, 100%); margin: 0 auto; padding: 0 20px 60px; }
.topbar {
  height: 88px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom: 1px solid rgba(0,0,0,.06);
}
.topbar h1 { margin: 0; font-size: 22px; }
.eyebrow { letter-spacing: .18em; font-size: 10px; color: var(--muted); margin-bottom: 4px; }

.dashboard { padding-top: 28px; }
.dashboard-actions {
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:20px;
}
.dashboard-actions h2 { margin: 0 0 6px; font-size: 28px; }
.dashboard-actions p { margin:0; color: var(--muted); }
.search-row { margin: 22px 0 16px; }
.search-row input { max-width: 420px; }

.record-list {
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.record-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 5px 20px rgba(36,38,41,.04);
  cursor:pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.record-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.record-card h3 { margin: 0 0 8px; font-size: 17px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.record-card .label { color: var(--accent); font-size: 12px; font-weight: 700; }
.record-card .preview { min-height: 44px; color: var(--muted); font-size: 13px; line-height: 1.65; margin: 12px 0; }
.record-card .card-meta { display:flex; justify-content:space-between; gap:8px; color:#8b8e93; font-size:12px; }
.record-card .mini-progress { height:4px; background:#eeeae2; border-radius:999px; overflow:hidden; margin-top:12px; }
.record-card .mini-progress > i { display:block; height:100%; background:var(--grid); width:0; }

.empty { text-align:center; padding: 72px 20px; color:var(--muted); }
.empty-grid {
  width:80px; height:80px; margin:0 auto 18px;
  border:1px solid var(--grid);
  background-image:
    linear-gradient(var(--grid-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-soft) 1px, transparent 1px);
  background-size:16px 16px;
  border-radius:10px;
}

.editor { padding-top: 18px; }
.editor-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display:grid;
  grid-template-columns: 1fr auto 1fr;
  align-items:center;
  gap:10px;
  padding: 10px 0;
  background: rgba(246,243,237,.94);
  backdrop-filter: blur(12px);
}
.editor-top .btn:last-child { justify-self:end; }
.save-state { color:var(--muted); font-size:13px; display:flex; gap:7px; align-items:center; }
.save-dot { width:8px; height:8px; border-radius:50%; background:#3e9a71; }
.save-dot.dirty { background:#d59b31; }
.save-dot.error { background:var(--danger); }

.editor-meta {
  display:grid;
  grid-template-columns: minmax(220px, 1fr) 150px minmax(230px, 260px);
  gap:12px;
  padding: 16px 0 14px;
}
.field.grow { min-width:0; }

.capacity-field { min-width: 0; }
.capacity-control {
  position: relative;
  display: flex;
  align-items: center;
}
.capacity-control input {
  padding-right: 42px;
  font-variant-numeric: tabular-nums;
}
.capacity-unit {
  position: absolute;
  right: 13px;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
.capacity-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.capacity-preset {
  border: 1px solid #ddd8cf;
  background: #fff;
  color: #555b61;
  border-radius: 8px;
  padding: 4px 7px;
  min-width: 38px;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
}
.capacity-preset:hover,
.capacity-preset.active {
  border-color: var(--accent);
  background: var(--accent-2);
  color: var(--accent);
}
.field-help {
  display: block;
  margin-top: 6px;
  color: #8b8e93;
  font-size: 11px;
  line-height: 1.4;
}
.capacity-control input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180,58,58,.1);
}

.stats-bar {
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stats-bar > div {
  background: rgba(255,255,255,.72);
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px 14px;
}
.stats-bar strong { display:block; font-size:22px; }
.stats-bar span { display:block; color:var(--muted); font-size:12px; margin-top:2px; }
.danger-stat { border-color:#efb9b9 !important; background:#fff5f5 !important; color:var(--danger); }

.sheet-toolbar {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin: 8px 0 12px;
}
.hint { font-size:13px; color:var(--muted); line-height:1.6; }
.toolbar-actions { display:flex; gap:8px; align-items:center; }
.zoom-select { width:auto; padding:9px 10px; background:#fff; }

.plain-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius:16px;
  padding:14px;
  margin-bottom:12px;
}
.plain-wrap textarea { min-height:180px; resize:vertical; line-height:1.8; }

.sheet-scroller {
  overflow:auto;
  overscroll-behavior: contain;
  padding-bottom:4px;
}
.sheet {
  --sheet-scale: 1;
  width: min(900px, 100%);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid #e7e2d9;
  border-radius: 3px;
  box-shadow: 0 16px 48px rgba(35,35,35,.08);
  padding: 22px 24px 30px;
  min-width: 0;
}
.sheet.zoomed { width: calc(min(900px, 100%) * var(--sheet-scale)); min-width: 620px; }
.sheet-heading {
  display:flex; justify-content:space-between; align-items:flex-end;
  gap:10px; margin-bottom:14px;
}
.sheet-heading > div:first-child { font-weight:750; }
.sheet-heading > div:last-child { color:#8b8e93; font-size:12px; }
.grid-host { user-select:none; -webkit-user-select:none; }
.hundred-block {
  position: relative;
  width: calc(100% - 44px);
  margin-bottom: 10px;
}
.grid100 {
  display:grid;
  grid-template-columns: repeat(25, minmax(0, 1fr));
  width:100%;
  border-top: 1px solid var(--grid);
  border-left: 1px solid var(--grid);
}
.grid-cell {
  aspect-ratio: 1 / 1;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  display:grid;
  place-items:center;
  overflow:hidden;
  font-size: clamp(9px, 1.28vw, 17px);
  line-height:1;
  cursor:text;
  position:relative;
  background:#fff;
}
.grid-cell.overflow { background:#fff3f3; }
.grid-cell.caret::after {
  content:"";
  position:absolute;
  width:2px;
  height:70%;
  background:var(--accent);
  animation:blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity:0; } }
.marker {
  position:absolute;
  left: calc(100% + 7px);
  bottom:-2px;
  width:38px;
  color:#777;
  font-size:10px;
  white-space:nowrap;
}
.keyboard-proxy {
  position: fixed !important;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  width: 2px !important;
  height: 2px !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: .01;
  z-index: 1;
  resize:none;
}

.export-bar {
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:center;
  padding: 18px 0 max(18px, env(safe-area-inset-bottom));
}

@media (max-width: 900px) {
  .record-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .app-shell { padding: 0 10px 42px; }
  .topbar { height:72px; }
  .dashboard { padding-top:20px; }
  .dashboard-actions { align-items:stretch; flex-direction:column; }
  .dashboard-actions .btn { width:100%; }
  .record-list { grid-template-columns: 1fr; }
  .editor-meta { grid-template-columns: 1fr 1fr; }
  .editor-meta .grow { grid-column: 1 / -1; }
  .stats-bar { grid-template-columns: repeat(3, 1fr); gap:6px; }
  .stats-bar > div { padding:9px 8px; text-align:center; }
  .stats-bar strong { font-size:18px; }
  .danger-stat { grid-column:1 / -1; }
  .sheet-toolbar { align-items:flex-start; flex-direction:column; }
  .toolbar-actions { width:100%; overflow-x:auto; padding-bottom:2px; }
  .sheet { padding:14px 9px 22px; }
  .sheet-heading { margin-bottom:10px; }
  .hundred-block { width: calc(100% - 32px); margin-bottom:7px; }
  .marker { left:calc(100% + 4px); width:28px; font-size:8px; }
  .grid-cell { font-size: clamp(7px, 2.65vw, 12px); }
  .export-bar {
    position: sticky;
    bottom: 0;
    z-index: 15;
    margin: 0 -10px;
    padding: 10px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom));
    background: rgba(246,243,237,.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0,0,0,.06);
  }
  .export-bar .btn { flex:1 1 calc(50% - 8px); }
}
