:root {
  --brand: #f97316;
  --brand-dark: #ea580c;
  --brand-soft: #fff1e6;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e8eaee;
  --text: #1f2329;
  --text-2: #5c6470;
  --text-3: #8a919c;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
}

.shell {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.side {
  width: 208px;
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  padding: 4px 10px 14px;
  border-bottom: 1px solid var(--line);
}
.brand b {
  display: block;
  font-size: 17px;
  letter-spacing: 0.5px;
  color: var(--brand-dark);
}
.brand span {
  font-size: 12px;
  color: var(--text-3);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text-2);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.nav button:hover {
  background: #f7f8fa;
}
.nav button.on {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 600;
}

.side-foot {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-3);
  padding: 0 10px;
}

/* 主区域 */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-title {
  font-size: 17px;
  font-weight: 650;
}
.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.view {
  padding: 20px 22px 90px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* 通用组件 */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  font-weight: 650;
  margin: 0 0 4px;
  font-size: 15px;
}
.card-desc {
  color: var(--text-3);
  font-size: 12px;
  margin: 0 0 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.spacer {
  flex: 1;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  transition: 0.15s;
}
.btn:hover {
  border-color: #d6dae0;
}
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover {
  background: var(--brand-dark);
}
.btn.ghost {
  background: transparent;
}
.btn.sm {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 8px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .label {
  color: var(--text-3);
  font-size: 12px;
}
.stat .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: 0.3px;
}
.stat .hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.stat.warn .value {
  color: var(--amber);
}
.stat.bad .value {
  color: var(--red);
}

.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.subtabs button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.subtabs button.on {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}
th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 13px;
}
th {
  background: #fafbfc;
  color: var(--text-3);
  font-weight: 600;
  font-size: 12px;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover td {
  background: #fcfcfd;
}
td.empty {
  text-align: center;
  color: var(--text-3);
  padding: 34px 0;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f3f5;
  color: var(--text-2);
}
.tag.green {
  background: #e9f8ef;
  color: var(--green);
}
.tag.red {
  background: #fdecec;
  color: var(--red);
}
.tag.amber {
  background: #fdf1e3;
  color: var(--amber);
}
.tag.blue {
  background: #eaf2fe;
  color: #2563eb;
}

.num-pos {
  color: var(--green);
  font-weight: 600;
}
.num-neg {
  color: var(--red);
  font-weight: 600;
}

/* 表单 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field > span {
  font-size: 12px;
  color: var(--text-2);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

/* 明细行 */
.lines {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fafbfc;
  margin-bottom: 12px;
}
.lines-head,
.line-row {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 0.9fr 34px;
  gap: 8px;
  align-items: center;
}
.lines-head.no-price,
.line-row.no-price {
  grid-template-columns: 1.6fr 0.8fr 34px;
}
.lines-head {
  font-size: 12px;
  color: var(--text-3);
  padding: 0 2px 8px;
}
.line-row {
  margin-bottom: 8px;
}
.line-row select,
.line-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  background: #fff;
  min-width: 0;
}
.line-row .del {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
#addLine {
  margin-top: 2px;
}

/* 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  width: min(620px, 100%);
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.modal-head h3 {
  margin: 0;
  font-size: 16px;
}
.modal-head .x {
  border: 0;
  background: transparent;
  font-size: 22px;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
}
.modal-body {
  padding: 6px 18px 14px;
  overflow-y: auto;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

/* 登录 */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #ffe8d6 0%, var(--bg) 60%);
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 {
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--brand-dark);
}
.login-card p {
  color: var(--text-3);
  font-size: 13px;
  margin: 0 0 22px;
}
.login-card .btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}
.login-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-3);
  word-break: break-all;
}
.login-note.err {
  color: var(--red);
}

.empty-hero {
  text-align: center;
  color: var(--text-3);
  padding: 60px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 12px);
  background: rgba(31, 35, 41, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  z-index: 200;
  max-width: 80vw;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tabbar {
  display: none;
}

@media (max-width: 900px) {
  .side {
    display: none;
  }
  .topbar {
    padding: 0 16px;
  }
  .view {
    padding: 14px 14px 96px;
  }
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 50;
    overflow-x: auto;
  }
  .tabbar button {
    flex: 1;
    min-width: 56px;
    border: 0;
    background: transparent;
    color: var(--text-3);
    padding: 6px 2px;
    font-size: 11px;
    cursor: pointer;
  }
  .tabbar button.on {
    color: var(--brand-dark);
    font-weight: 600;
  }
}
