:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0066cc;
  --primary-dark: #0052a3;
  --amber: #d97706;
  --green: #059669;
  --danger: #dc2626;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); min-height: 100%; }
button, input, select, textarea { font: inherit; }

.toast {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 999; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; max-width: calc(100vw - 32px); text-align: center; opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 22px; box-shadow: 0 12px 30px rgba(15, 23, 42, .08);
  text-align: center;
}
.brand-badge {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #0066cc, #0284c7); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.subtitle { color: var(--muted); font-size: 13px; margin: 6px 0 20px; }
.login-card .form-stack { text-align: left; }
.login-tip { color: var(--muted); font-size: 11.5px; margin: 16px 0 0; line-height: 1.5; }
.error-text { color: var(--danger); font-size: 13px; margin: 0; }

.app-shell {
  min-height: 100vh; display: flex; flex-direction: column;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.app-header strong { display: block; font-size: 17px; }
.app-header small { display: block; font-size: 12px; color: var(--muted); }
.header-actions { display: flex; gap: 8px; }
.btn-chip {
  background: #f1f5f9; color: #334155; border: 0; border-radius: 8px;
  padding: 7px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; text-decoration: none;
}

.app-main { padding: 14px; max-width: 680px; width: 100%; margin: 0 auto; flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; margin-bottom: 12px; box-shadow: 0 2px 10px rgba(15, 23, 42, .03);
}
.card h2 { margin: 0 0 12px; font-size: 14.5px; color: #1e293b; }
.form-stack { display: flex; flex-direction: column; gap: 11px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: #475569; font-weight: 600; }
input, select, textarea {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 11px 12px;
  background: #f8fafc; color: var(--ink); font-size: 15px; outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(0, 102, 204, .12);
}
.code-input { color: var(--primary); font-weight: 700; letter-spacing: .04em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.lookup-hint {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: #eff6ff; color: #1d4ed8; font-size: 12.5px; line-height: 1.4;
}
.banner-warn {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px;
}

.mode-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.mode-btn {
  border: 1px solid #cbd5e1; background: #f8fafc; color: #334155;
  padding: 9px 4px; border-radius: 9px; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.mode-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.mode-btn.mode-perpetual.active { background: var(--green); border-color: var(--green); }
.mode-panel { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.preset-btn {
  border: 1px solid #e2e8f0; background: #f1f5f9; color: #334155;
  padding: 10px 8px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.preset-btn.active { background: #dbeafe; color: #0052a3; border-color: #60a5fa; }
.field-hint { margin: 0; font-size: 12px; color: var(--muted); }
.perpetual-box {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  padding: 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
}

.btn-primary, .btn-secondary, .btn-danger, .btn-text {
  border: 0; border-radius: 11px; padding: 12px 16px; font-weight: 700; font-size: 15px; cursor: pointer; width: 100%;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-lg { padding: 14px 16px; font-size: 16px; }
.btn-secondary { background: #e2e8f0; color: #1e293b; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-text { background: transparent; color: var(--muted); margin-top: 6px; }

.search-bar { margin-bottom: 10px; }
.card-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 13px;
}
.item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.item-title { font-weight: 700; font-size: 15px; color: var(--ink); }
.item-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.item-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; color: var(--primary); font-size: 15px; }
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  background: #eff6ff; color: #1d4ed8; white-space: nowrap;
}
.badge.ok { background: #ecfdf5; color: #059669; }
.badge.warn { background: #fef3c7; color: #b45309; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.item-actions { display: flex; gap: 8px; margin-top: 10px; }
.item-actions button {
  flex: 1; padding: 8px 10px; border-radius: 8px; border: 0; font-size: 13px; font-weight: 600; cursor: pointer;
}
.act-primary { background: #e0f2fe; color: #0369a1; }
.act-ghost { background: #f1f5f9; color: #475569; }
.act-danger { background: #fee2e2; color: #b91c1c; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 13.5px; }

.kv-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid #f1f5f9; font-size: 13.5px;
}
.kv-row span { color: var(--muted); }
.metrics-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; text-align: center;
}
.metrics-row div { background: #f8fafc; border-radius: 10px; padding: 10px 6px; }
.metrics-row small { display: block; color: var(--muted); font-size: 11.5px; }
.metrics-row strong { display: block; font-size: 20px; color: var(--primary); margin-top: 4px; }
.card-head-inline { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-head-inline h2 { margin: 0; }

.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tab-item {
  border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 18px; padding: 4px 0; cursor: pointer;
}
.tab-item span { font-size: 11px; font-weight: 600; }
.tab-item.active { color: var(--primary); }

.result-dialog {
  border: 0; border-radius: 18px; padding: 0; max-width: 420px; width: calc(100vw - 28px);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
}
.result-dialog::backdrop { background: rgba(15, 23, 42, .6); }
.dialog-inner { padding: 20px; text-align: center; }
.dialog-eyebrow { margin: 0; color: var(--green); font-size: 12.5px; font-weight: 700; }
.big-code {
  margin: 12px 0 6px; font-size: 28px; font-weight: 900; letter-spacing: .06em;
  color: var(--primary); font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.dialog-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.dialog-inner textarea { font-size: 12.5px; line-height: 1.45; margin-bottom: 12px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
