:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273549;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(68px + var(--safe-bottom));
}

.app-header {
  padding: 14px 16px 8px;
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

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

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-offline {
  font-size: 11px;
  color: var(--good);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.backup-alert {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 10px;
  color: var(--warn);
  font-size: 12px;
}

.app-main {
  flex: 1;
  padding: 12px 14px 24px;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card-header {
  margin-bottom: 12px;
}
.card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hint-text {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.opt {
  font-size: 11px;
  opacity: 0.7;
  margin-left: 4px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input[type="date"],
input[type="time"],
input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* Prevents iOS auto-zoom */
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

select {
  width: auto;
  font-size: 13px;
  padding: 6px 10px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

.preview-box {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  margin-bottom: 16px;
  text-align: center;
}
.p-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}
.p-val {
  display: block;
  font-size: 15px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.label-row label {
  margin-bottom: 0;
}
.impact-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: rgba(129, 140, 248, 0.15);
  padding: 2px 9px;
  border-radius: 999px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 28px;
}

.range-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.btn-row {
  display: flex;
  gap: 10px;
}
.stack-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

button, .file-label {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  transition: opacity 0.15s;
}
button:active, .file-label:active {
  opacity: 0.75;
}

.btn-primary {
  flex: 1;
  background: var(--primary-dark);
  color: #fff;
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger {
  width: 100%;
  background: rgba(248, 113, 113, 0.14);
  color: var(--bad);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.error-msg {
  color: var(--bad);
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}
.stat-value {
  display: block;
  font-size: 19px;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.stat-sub {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.leg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.dot-eff { background: #818cf8; }
.dot-imp { background: #fb923c; }
.line-ref {
  width: 14px;
  height: 0;
  border-top: 2px dashed #34d399;
  display: inline-block;
}
.box {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.box-tib { background: #475569; }
.box-tst { background: #818cf8; }

.chart-wrap {
  width: 100%;
  overflow-x: auto;
}
.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 12px;
  font-size: 13px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hist-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.hist-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.hist-date {
  font-weight: 700;
  font-size: 15px;
}
.eff-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.eff-good { color: var(--good); background: rgba(52, 211, 153, 0.14); }
.eff-warn { color: var(--warn); background: rgba(251, 191, 36, 0.14); }
.eff-bad  { color: var(--bad);  background: rgba(248, 113, 113, 0.14); }

.hist-metrics {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}
.hist-memo {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  padding: 6px 8px;
  border-radius: 8px;
  word-break: break-word;
}
.hist-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.btn-mini {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}
.btn-mini-del {
  color: var(--bad);
}

.meta-info, .desc-text {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.guide-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text);
}
.guide-list li {
  margin-bottom: 8px;
}

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border-radius: 0;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
}
.tab-btn.active {
  color: var(--primary);
}
.tab-icon {
  font-size: 18px;
  line-height: 1.1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #334155;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 30;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}
